diff: preserve left/right anchor paths#30
Conversation
7dcab6c to
70e9e08
Compare
70e9e08 to
9a321e0
Compare
arighi
left a comment
There was a problem hiding this comment.
I don't really understand this patch, can you show an example of what is improving/fixing?
Moreover, a couple of issues found by codex:
-
High — LEFT anchors for renames and deletions are removed before this code can use them. src/api.rs:4151 now looks up LEFT findings using
old_file, but the earlier DiffIndex still indexes both sides under the +++ path (src/diff_index.rs:59, src/diff_index.rs:98). Deleted
files are not indexed at all. Consequently, drop_unanchored_locations() removes old-path rename/deletion locations (src/main.rs:1041)
before LKML attachments are generated. The commit’s primary feature therefore does not work end-to-end. DiffIndex also needs separate old/
new paths, with LEFT entries indexed under the old path. -
Medium — deleted source text can be mistaken for an old-file header. src/api.rs:4067 treats every --- line as a file header. Inside a
valid hunk, deleting a line beginning with -- produces exactly that prefix. The hunk collector already stops before such a line at src/
api.rs:4095; the outer loop now consumes it as a header and overwrites current_old_file. Subsequent hunks in the same file then cannot
match LEFT findings. Header parsing should be constrained to file-header state, or hunk bodies should be consumed according to their
declared ranges.
Thanks.
|
The patch is trying to fix a pretty specific anchoring problem with renamed or deleted files. The simple example is a rename: diff --git a/app/main.rs b/app/main_renamed.rs
rename from app/main.rs
rename to app/main_renamed.rs
--- a/app/main.rs
+++ b/app/main_renamed.rs
@@ -10,4 +10,4 @@ main flow
trace!("before");
- println!("old behavior");
+ println!("new behavior");
trace!("after");If a finding points at the removed line, that finding is on the old side of the diff. So the correct anchor is something like:
But the hunk also has a new path:
Before this patch, the hunk lookup mostly used the new/right-side path, so a valid LEFT-side finding using the old filename could fail to match the hunk. In practice that means we can lose the exact diff context for the finding, especially when generating the LKML/report payload. The same thing happens for deleted files: diff --git a/app/removed.rs b/app/removed.rs
deleted file mode 100644
--- a/app/removed.rs
+++ /dev/null
@@ -5,2 +0,0 @@
- console!("remove me");
- cleanup();There is no real new/right-side file here, because the file was deleted. But a finding on the deleted line should still be able to anchor to:
So the goal of the patch is to preserve both paths from the diff:
That said, I agree with the issue Codex pointed out. |
e955d3e to
eaff5d8
Compare
|
Thanks for clarifying it. There are some other issues found by codex, let me know what you think.
|
2b6186d to
5cfecb9
Compare
Track old and new diff header paths separately so LEFT anchors keep the pre-image path while RIGHT and context anchors keep the post-image path. This fixes rename and delete hunks where findings must resolve against different repository locations. While parsing hunks, only recognize file headers in the outer scan. Header-like payload lines inside a hunk body must remain part of the hunk or later finding attachment can truncate and misanchor. Add regression coverage for rename edits, deleted-file anchors, header-like payload lines, and end-to-end attachment resolution. Signed-off-by: Minh Vu <vuhoangminh97@gmail.com>
5cfecb9 to
ac9e470
Compare
|
Looks good now. Thanks for all the iterations and improvements on this PR! |
Summary