From f905db770dfdf79ba3813a63738b3b04dd959a20 Mon Sep 17 00:00:00 2001 From: Deepjyoti-Sarmah Date: Sun, 11 Oct 2026 15:37:00 +0530 Subject: [PATCH] fix(dedup): rank a relative source_file against the scan root, not the CWD (#4281) Nodes are root-relative by dedup time, but _rank_path resolved them, which prepends the CWD. From root/firmware, a node keyed as firmware/firmware/lib/portal.html and its edge as firmware/lib/portal.html, so the edge never followed the renamed node. Resolve only absolute paths. _source_key is unchanged: at extraction time relative paths are CWD-relative. Co-authored-by: Gijs Mos <1526544+gmos@users.noreply.github.com> (cherry picked from commit 22f87c266aefb2b30cc20775f6c47c5b8057ce2f) --- graphify/dedup.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/graphify/dedup.py b/graphify/dedup.py index e23c46216..061551fe9 100644 --- a/graphify/dedup.py +++ b/graphify/dedup.py @@ -428,13 +428,16 @@ def _lifecycle_penalty(rank_path: str) -> int: def _rank_path(source_file: str, root: Path | None) -> str: """The root-relative form of ``source_file`` used for collision ranking. - Mirrors ``_source_key`` in extractors/resolution.py: with a scan root, an - absolute stored path and its repo-relative twin rank identically, and the - checkout location's own segments never participate (#2532). Without a root - (or when relativizing fails) the normalized stored path is used as-is. + With a scan root, an absolute stored path and its repo-relative twin rank + identically, and the checkout location's own segments never participate + (#2532). A relative stored path is already root-relative and is used as-is; + unlike ``_source_key`` in extractors/resolution.py, it is not resolved + against the CWD, so a run from a subdirectory of the root keys it the same + (#4281). Without a root (or when relativizing fails) the normalized stored + path is used as-is. """ normalized = source_file.replace("\\", "/") - if root is not None and normalized: + if root is not None and normalized and Path(normalized).is_absolute(): try: return Path(normalized).resolve().relative_to(root).as_posix() except Exception: