Description
In tools/diff/diff.go, the DiffHunk struct has OldCount int and NewCount int fields but they are never assigned during hunk construction. Only OldStart and NewStart are set.
Impact
XML consumers that rely on old_count/new_count to reconstruct or display diffs receive incorrect zero values. The unified diff format requires these (@@ -10,5 +10,7 @@).
Steps to Reproduce
aict diff file1.go file2.go --xml
Observe: <hunk old_start="10" old_count="0" new_start="10" new_count="0">
Expected Behavior
old_count = number of removed + context lines in the hunk
new_count = number of added + context lines in the hunk
Fix
After building each hunk's Lines slice, compute counts before appending to hunks:
hunk.OldCount = countLines(hunk.Lines, "removed") + countLines(hunk.Lines, "context")
hunk.NewCount = countLines(hunk.Lines, "added") + countLines(hunk.Lines, "context")
Related
tools/diff/diff.go computeDiff function
Description
In
tools/diff/diff.go, theDiffHunkstruct hasOldCount intandNewCount intfields but they are never assigned during hunk construction. OnlyOldStartandNewStartare set.Impact
XML consumers that rely on
old_count/new_countto reconstruct or display diffs receive incorrect zero values. The unified diff format requires these (@@ -10,5 +10,7 @@).Steps to Reproduce
Observe:
<hunk old_start="10" old_count="0" new_start="10" new_count="0">Expected Behavior
old_count= number ofremoved+contextlines in the hunknew_count= number ofadded+contextlines in the hunkFix
After building each hunk's
Linesslice, compute counts before appending tohunks:Related
tools/diff/diff.gocomputeDifffunction