chore: sync local changes, add Chinese docs and opencode config

This commit is contained in:
AuraK Developer
2026-08-31 11:37:03 +08:00
parent 307d2fd471
commit ecc55158c1
81 changed files with 7645 additions and 144 deletions
+15 -2
View File
@@ -11,7 +11,7 @@ import os
import re
import subprocess
from pathlib import Path
from typing import Any
from typing import Any, Callable, Optional
from .constants import SECURITY_KEYWORDS as _SECURITY_KEYWORDS
from .flows import get_affected_flows
@@ -204,12 +204,20 @@ def _parse_numstat(log_text: str) -> dict[str, int]:
def compute_file_churn(
repo_root: str,
window_days: int | None = None,
progress_cb: Callable[[float, Optional[str]], None] | None = None,
) -> dict[str, int]:
"""Count commits touching each file over a trailing window.
Returns an empty mapping when the window is invalid or Git cannot be
queried. Renames are deliberately not followed: churn belongs to the path
that existed in each commit.
Args:
repo_root: Repository root.
window_days: Trailing window; defaults to ``CRG_CHURN_WINDOW_DAYS``.
progress_cb: Optional ``(fraction, message)`` progress callback; the
single blocking step (``git log --numstat``) reports stage 0 before
and 1 after it runs.
"""
if window_days is None:
raw_window = os.environ.get("CRG_CHURN_WINDOW_DAYS", "90")
@@ -224,6 +232,8 @@ def compute_file_churn(
if window_days <= 0:
return {}
if progress_cb is not None:
progress_cb(0.0, "computing git churn")
try:
result = subprocess.run(
[
@@ -257,7 +267,10 @@ def compute_file_churn(
logger.warning("git log error: %s", exc)
return {}
return _parse_numstat(result.stdout)
parsed = _parse_numstat(result.stdout)
if progress_cb is not None:
progress_cb(1.0, "git churn done")
return parsed
# ---------------------------------------------------------------------------