Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(update): name the attribution backfill as the reason for a git history re-read (#3804)
Raghav Chamadiya63aa11df2f4e
diff --git a/packages/cli/src/repowise/cli/commands/attribution_cmd.py b/packages/cli/src/repowise/cli/commands/attribution_cmd.pyindex de7999efc..9f051caa8 100644--- a/packages/cli/src/repowise/cli/commands/attribution_cmd.py+++ b/packages/cli/src/repowise/cli/commands/attribution_cmd.py@@ -231,13 +231,19 @@ def _request_history_rewalk(repo_path: Path) -> bool:"""Make the next ``repowise update`` re-read git history once, which labelsthe newly bound commits in the index; False when there is no index.- Drops the git-history stamp in ``.repowise/state.json``, the same signal a- history-rules change raises. No update flag re-walks git history alone.+ Replaces a current git-history stamp in ``.repowise/state.json`` with the+ backfill marker, which the update reads as stale and names as the reason.+ A stamp already stale is left alone: that walk labels these commits too.+ No update flag re-walks git history alone."""import jsonfrom repowise.core.fsutils import atomic_write_text- from repowise.core.ingestion.git_indexer import GIT_HISTORY_VERSION_KEY+ from repowise.core.ingestion.git_indexer import (+ GIT_HISTORY_BACKFILL_REWALK,+ GIT_HISTORY_VERSION,+ GIT_HISTORY_VERSION_KEY,+ )state_path = repo_path / ".repowise" / "state.json"try:@@ -246,7 +252,9 @@ def _request_history_rewalk(repo_path: Path) -> bool:return Falseif not isinstance(state, dict):return False- state.pop(GIT_HISTORY_VERSION_KEY, None)+ if state.get(GIT_HISTORY_VERSION_KEY) != GIT_HISTORY_VERSION:+ return True+ state[GIT_HISTORY_VERSION_KEY] = GIT_HISTORY_BACKFILL_REWALKatomic_write_text(state_path, json.dumps(state, indent=2))return Truediff --git a/packages/cli/src/repowise/cli/commands/update_cmd/command.py b/packages/cli/src/repowise/cli/commands/update_cmd/command.pyindex 78805f94e..5fa6a5c98 100644--- a/packages/cli/src/repowise/cli/commands/update_cmd/command.py+++ b/packages/cli/src/repowise/cli/commands/update_cmd/command.py@@ -43,6 +43,7 @@ from repowise.cli.helpers import ()from repowise.core.docs_mode import docs_mode_state_fields, resolve_docs_modefrom repowise.core.ingestion.git_indexer import (+ GIT_HISTORY_BACKFILL_REWALK,GIT_HISTORY_VERSION,GIT_HISTORY_VERSION_KEY,git_history_stale,@@ -1135,7 +1136,10 @@ def run_update()if history_stale:console.print(- "[yellow]Git history rules changed since this index was built; "+ "[yellow]Re-reading git history once to label commits from the "+ "attribution backfill.[/yellow]"+ if state.get(GIT_HISTORY_VERSION_KEY) == GIT_HISTORY_BACKFILL_REWALK+ else "[yellow]Git history rules changed since this index was built; ""re-reading the full history once.[/yellow]")# Deliberately not in ``git_is_current``: the rescan does its own full parse,diff --git a/packages/core/src/repowise/core/ingestion/git_indexer/__init__.py b/packages/core/src/repowise/core/ingestion/git_indexer/__init__.pyindex 5f6529480..d81333bbc 100644--- a/packages/core/src/repowise/core/ingestion/git_indexer/__init__.py+++ b/packages/core/src/repowise/core/ingestion/git_indexer/__init__.py@@ -27,6 +27,7 @@ from ...lazy_exports import lazy_exportsif TYPE_CHECKING:from ._constants import (+ GIT_HISTORY_BACKFILL_REWALK,GIT_HISTORY_VERSION,GIT_HISTORY_VERSION_KEY,HOTSPOT_HALFLIFE_DAYS,@@ -74,6 +75,7 @@ if TYPE_CHECKING:from .tiers import GitIndexTier_EXPORTS: dict[str, str] = {+ "GIT_HISTORY_BACKFILL_REWALK": "._constants","GIT_HISTORY_VERSION": "._constants","GIT_HISTORY_VERSION_KEY": "._constants","HOTSPOT_HALFLIFE_DAYS": "._constants",@@ -120,6 +122,7 @@ __getattr__, __dir__ = lazy_exports(__name__, _EXPORTS, globals())__all__ = ["BACKFILL_PHASE",+ "GIT_HISTORY_BACKFILL_REWALK","GIT_HISTORY_VERSION","GIT_HISTORY_VERSION_KEY","HOTSPOT_HALFLIFE_DAYS",diff --git a/packages/core/src/repowise/core/ingestion/git_indexer/_constants.py b/packages/core/src/repowise/core/ingestion/git_indexer/_constants.pyindex 00b0be7d9..c6585e0e4 100644--- a/packages/core/src/repowise/core/ingestion/git_indexer/_constants.py+++ b/packages/core/src/repowise/core/ingestion/git_indexer/_constants.py@@ -327,6 +327,10 @@ HOTSPOT_HALFLIFE_DAYS: float = 180.0#: v3: commits carry their category, and changes are rebuilt from history.GIT_HISTORY_VERSION: int = 3GIT_HISTORY_VERSION_KEY = "git_history_version"+#: Stored under :data:`GIT_HISTORY_VERSION_KEY` by ``repowise attribution+#: backfill`` so the next update re-walks history to label the newly bound+#: commits, and can say so instead of reporting a rules change.+GIT_HISTORY_BACKFILL_REWALK = "attribution-backfill"def git_history_stale(state: dict[str, Any]) -> bool:diff --git a/tests/unit/cli/test_attribution_capture_cli.py b/tests/unit/cli/test_attribution_capture_cli.pyindex 4a37ba1d3..4a7bc02b8 100644--- a/tests/unit/cli/test_attribution_capture_cli.py+++ b/tests/unit/cli/test_attribution_capture_cli.py@@ -216,7 +216,10 @@ def test_backfill_reports_and_status_shows_the_run(assert report["covered_after"] == report["covered_before"] + 1# The next update re-reads git history once; nothing else in the state moves.assert report["history_rewalk_on_next_update"] is True- assert json.loads(state.read_text(encoding="utf-8")) == {"last_sync_commit": "abc"}+ assert json.loads(state.read_text(encoding="utf-8")) == {+ "git_history_version": "attribution-backfill",+ "last_sync_commit": "abc",+ }status = CliRunner().invoke(attribution_group, ["status", str(repo), "--format", "json"])assert json.loads(status.output)["backfill"]["bound"] == 1diff --git a/tests/unit/cli/test_update_git_history_stamp.py b/tests/unit/cli/test_update_git_history_stamp.pyindex 2fe00037c..6f0d0e1d3 100644--- a/tests/unit/cli/test_update_git_history_stamp.py+++ b/tests/unit/cli/test_update_git_history_stamp.py@@ -16,6 +16,7 @@ from repowise.cli.commands.init_cmd.persistence import apply_git_history_coveragfrom repowise.cli.helpers import load_state, save_statefrom repowise.core.analysis.health import HEALTH_ANALYZER_VERSIONfrom repowise.core.ingestion.git_indexer import (+ GIT_HISTORY_BACKFILL_REWALK,GIT_HISTORY_VERSION,GIT_HISTORY_VERSION_KEY,GitIndexer,@@ -100,6 +101,30 @@ def test_stale_stamp_walks_once_then_updates_incrementally(assert len(walks) == 1+def test_backfill_marker_walks_once_and_names_the_backfill(tmp_path, walks) -> None:+ repo, _ = _indexed_repo(tmp_path)+ walks.clear()+ _current(repo, **{GIT_HISTORY_VERSION_KEY: GIT_HISTORY_BACKFILL_REWALK})++ out = _invoke_update(repo)++ assert "attribution backfill" in out+ assert "Git history rules changed" not in out+ assert len(walks) == 1+ assert load_state(repo)[GIT_HISTORY_VERSION_KEY] == GIT_HISTORY_VERSION+++def test_backfill_leaves_a_stale_stamp_alone(tmp_path) -> None:+ from repowise.cli.commands.attribution_cmd import _request_history_rewalk++ repo, _ = _indexed_repo(tmp_path)+ _current(repo, **{GIT_HISTORY_VERSION_KEY: GIT_HISTORY_VERSION - 1})++ assert _request_history_rewalk(repo)+ # The rules really did change, so the update still says that.+ assert load_state(repo)[GIT_HISTORY_VERSION_KEY] == GIT_HISTORY_VERSION - 1++def test_current_stamp_forces_no_walk(tmp_path, walks) -> None:repo, _ = _indexed_repo(tmp_path)walks.clear()diff --git a/tests/unit/test_git_indexer_lazy_exports.py b/tests/unit/test_git_indexer_lazy_exports.pyindex 2aca03f7c..4bb1504e1 100644--- a/tests/unit/test_git_indexer_lazy_exports.py+++ b/tests/unit/test_git_indexer_lazy_exports.py@@ -44,7 +44,7 @@ def test_public_exports_are_discoverable_and_resolve_to_their_defining_modules()import importlibimport repowise.core.ingestion.git_indexer as package- assert len(package.__all__) == 40+ assert len(package.__all__) == 41assert set(package.__all__) == set(package._EXPORTS)assert set(package.__all__) <= set(dir(package))for name in package.__all__: