Skip to content

diff hunk old_count and new_count attributes are always 0 in XML output #23

@github-actions

Description

@github-actions

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions