From 828c73bad4f2f49b7659dfee3ca7470b5d508e7a Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 9 Aug 2026 15:20:29 +0200 Subject: [PATCH] Rename parsedDiffLine.RelPath to Path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A diff line's identity is about to become recoverable from a second source, a diff renderer's own records, and a renderer states the path however it likes — absolute paths included. The field can't promise repo-relative any more. Co-authored-by: Claude Opus 5 (1M context) --- .../controllers/helpers/diff_line_helper.go | 2 +- .../controllers/helpers/diff_line_parser.go | 8 ++--- .../helpers/diff_line_parser_test.go | 34 +++++++++---------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/pkg/gui/controllers/helpers/diff_line_helper.go b/pkg/gui/controllers/helpers/diff_line_helper.go index 4402d124d..77f70611e 100644 --- a/pkg/gui/controllers/helpers/diff_line_helper.go +++ b/pkg/gui/controllers/helpers/diff_line_helper.go @@ -45,7 +45,7 @@ func (self *DiffLineHelper) GetDiffLineInfo(view *gocui.View, viewLineIdx int) ( // absolute-path identity consumers work with. func (self *DiffLineHelper) diffLineInfoFromParsed(parsed parsedDiffLine) types.DiffLineInfo { return types.DiffLineInfo{ - Path: filepath.Join(self.c.Git().RepoPaths.WorktreePath(), parsed.RelPath), + Path: filepath.Join(self.c.Git().RepoPaths.WorktreePath(), parsed.Path), Type: parsed.Type, NewLine: parsed.NewLine, OldLine: parsed.OldLine, diff --git a/pkg/gui/controllers/helpers/diff_line_parser.go b/pkg/gui/controllers/helpers/diff_line_parser.go index 109fd758e..c9033960d 100644 --- a/pkg/gui/controllers/helpers/diff_line_parser.go +++ b/pkg/gui/controllers/helpers/diff_line_parser.go @@ -32,10 +32,10 @@ var submoduleSectionPattern = regexp.MustCompile( `^Submodule (.+) (?:contains (?:untracked|modified) content|[0-9a-f]+\.{2,3}[0-9a-f]+(?: \(.*\))?:?)$`) // parsedDiffLine is what the parser recovers about a row of a rendered diff. -// RelPath is the path as the diff header spells it, i.e. relative to the repo -// root; the caller turns it into the absolute path of types.DiffLineInfo. +// Path is the path as the diff header spells it, i.e. relative to the repo root; +// the caller turns it into the absolute path of types.DiffLineInfo. type parsedDiffLine struct { - RelPath string + Path string Type types.DiffLineType NewLine int OldLine int @@ -215,7 +215,7 @@ func parseFileSection(fileLines []string, endsTheBuffer bool) []bufferLineParse break } parsed := parsedDiffLine{ - RelPath: relPath, + Path: relPath, Type: diffLineTypeForKind(patchLines[i].Kind), NewLine: p.LineNumberOfLine(i), } diff --git a/pkg/gui/controllers/helpers/diff_line_parser_test.go b/pkg/gui/controllers/helpers/diff_line_parser_test.go index ae620d23c..11f078abd 100644 --- a/pkg/gui/controllers/helpers/diff_line_parser_test.go +++ b/pkg/gui/controllers/helpers/diff_line_parser_test.go @@ -40,16 +40,16 @@ func TestParseDiffLineFromBuffer(t *testing.T) { expected parsedDiffLine expectOk bool }{ - {"file header", 0, parsedDiffLine{RelPath: "file1.go", Type: types.DiffLineFileHeader, NewLine: 1}, true}, - {"hunk header", 4, parsedDiffLine{RelPath: "file1.go", Type: types.DiffLineHunkHeader, NewLine: 1}, true}, - {"context line", 5, parsedDiffLine{RelPath: "file1.go", Type: types.DiffLineContext, NewLine: 1}, true}, + {"file header", 0, parsedDiffLine{Path: "file1.go", Type: types.DiffLineFileHeader, NewLine: 1}, true}, + {"hunk header", 4, parsedDiffLine{Path: "file1.go", Type: types.DiffLineHunkHeader, NewLine: 1}, true}, + {"context line", 5, parsedDiffLine{Path: "file1.go", Type: types.DiffLineContext, NewLine: 1}, true}, // The two deletions share new-file line 2 but have distinct old-file lines. - {"first deletion", 6, parsedDiffLine{RelPath: "file1.go", Type: types.DiffLineDeleted, NewLine: 2, OldLine: 2}, true}, - {"second deletion", 7, parsedDiffLine{RelPath: "file1.go", Type: types.DiffLineDeleted, NewLine: 2, OldLine: 3}, true}, + {"first deletion", 6, parsedDiffLine{Path: "file1.go", Type: types.DiffLineDeleted, NewLine: 2, OldLine: 2}, true}, + {"second deletion", 7, parsedDiffLine{Path: "file1.go", Type: types.DiffLineDeleted, NewLine: 2, OldLine: 3}, true}, // The second file: its path comes from the second "diff --git" section, // and its additions get distinct new-file line numbers. - {"first addition", 15, parsedDiffLine{RelPath: "dir/file2.go", Type: types.DiffLineAdded, NewLine: 10}, true}, - {"second addition", 16, parsedDiffLine{RelPath: "dir/file2.go", Type: types.DiffLineAdded, NewLine: 11}, true}, + {"first addition", 15, parsedDiffLine{Path: "dir/file2.go", Type: types.DiffLineAdded, NewLine: 10}, true}, + {"second addition", 16, parsedDiffLine{Path: "dir/file2.go", Type: types.DiffLineAdded, NewLine: 11}, true}, {"out of range", 999, parsedDiffLine{}, false}, } @@ -75,7 +75,7 @@ rename to new.go`, "\n") result, ok := parseDiffLineFromBuffer(pureRename, 2) assert.True(t, ok) - assert.Equal(t, parsedDiffLine{RelPath: "new.go", Type: types.DiffLineFileHeader, NewLine: 1}, result) + assert.Equal(t, parsedDiffLine{Path: "new.go", Type: types.DiffLineFileHeader, NewLine: 1}, result) renameWithModification := strings.Split(`diff --git a/old.go b/new.go similarity index 62% @@ -91,7 +91,7 @@ index 1111111..2222222 100644 result, ok = parseDiffLineFromBuffer(renameWithModification, 10) assert.True(t, ok) - assert.Equal(t, parsedDiffLine{RelPath: "new.go", Type: types.DiffLineAdded, NewLine: 2}, result) + assert.Equal(t, parsedDiffLine{Path: "new.go", Type: types.DiffLineAdded, NewLine: 2}, result) } func TestParseDiffLineFromBufferDeletedFile(t *testing.T) { @@ -107,7 +107,7 @@ index 1111111..0000000 result, ok := parseDiffLineFromBuffer(deletedFile, 7) assert.True(t, ok) - assert.Equal(t, parsedDiffLine{RelPath: "gone.go", Type: types.DiffLineDeleted, NewLine: 0, OldLine: 2}, result) + assert.Equal(t, parsedDiffLine{Path: "gone.go", Type: types.DiffLineDeleted, NewLine: 0, OldLine: 2}, result) } func TestParseDiffLineFromBufferSubmodule(t *testing.T) { @@ -129,13 +129,13 @@ Submodule modules/xyz a32f27c..2d9f921: result, ok := parseDiffLineFromBuffer(withSubmodule, targetIdx) assert.True(t, ok) assert.Equal(t, - parsedDiffLine{RelPath: "modules/xyz", Type: types.DiffLineFileHeader, NewLine: 1}, + parsedDiffLine{Path: "modules/xyz", Type: types.DiffLineFileHeader, NewLine: 1}, result, "line %d", targetIdx) } result, ok := parseDiffLineFromBuffer(withSubmodule, 7) assert.True(t, ok) - assert.Equal(t, parsedDiffLine{RelPath: "file.txt", Type: types.DiffLineAdded, NewLine: 3}, result) + assert.Equal(t, parsedDiffLine{Path: "file.txt", Type: types.DiffLineAdded, NewLine: 3}, result) } func TestParseDiffLineFromBufferSubmoduleInARendering(t *testing.T) { @@ -153,8 +153,8 @@ products/a.txt two`, "\n") all := parseAllDiffLinesFromBuffer(rendered) - assert.Equal(t, "modules/xyz", all[0].parsed.RelPath) - assert.Equal(t, "modules/xyz", all[1].parsed.RelPath) + assert.Equal(t, "modules/xyz", all[0].parsed.Path) + assert.Equal(t, "modules/xyz", all[1].parsed.Path) for i := 2; i < len(rendered); i++ { assert.False(t, all[i].ok, "line %d: %q", i, rendered[i]) } @@ -230,7 +230,7 @@ func TestParseDiffLineFromBufferReadInPart(t *testing.T) { cutShort := lines[:len(lines)-1] result, ok := parseDiffLineFromBuffer(cutShort, 15) assert.True(t, ok) - assert.Equal(t, parsedDiffLine{RelPath: "dir/file2.go", Type: types.DiffLineAdded, NewLine: 10}, result) + assert.Equal(t, parsedDiffLine{Path: "dir/file2.go", Type: types.DiffLineAdded, NewLine: 10}, result) // Only the section the buffer breaks off in is read that way. One that another // section follows is all there, so a hunk short of what its header declares means @@ -287,13 +287,13 @@ func TestParseDiffLineFromBufferQuotedPath(t *testing.T) { result, ok := parseDiffLineFromBuffer(renamed, 10) assert.True(t, ok) - assert.Equal(t, parsedDiffLine{RelPath: "café new.go", Type: types.DiffLineAdded, NewLine: 2}, result) + assert.Equal(t, parsedDiffLine{Path: "café new.go", Type: types.DiffLineAdded, NewLine: 2}, result) // The same rename without a content change has no +++/--- lines, so the path // comes from the "diff --git" line, where both paths are quoted. result, ok = parseDiffLineFromBuffer(renamed[:4], 2) assert.True(t, ok) - assert.Equal(t, parsedDiffLine{RelPath: "café new.go", Type: types.DiffLineFileHeader, NewLine: 1}, result) + assert.Equal(t, parsedDiffLine{Path: "café new.go", Type: types.DiffLineFileHeader, NewLine: 1}, result) } func TestParseAllDiffLinesFromBuffer(t *testing.T) {