Skip to content

Commit 4227b26

Browse files
committed
fix DiffFile struct
1 parent 493e32b commit 4227b26

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

services/gitdiff/gitdiff.go

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -357,18 +357,20 @@ func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine, loc
357357

358358
// DiffFile represents a file diff.
359359
type DiffFile struct {
360-
Name string
361-
NameHash string
362-
OldName string
363-
Index int
364-
Addition, Deletion int
365-
Type DiffFileType
366-
IsCreated bool
367-
IsDeleted bool
368-
IsBin bool
369-
IsLFSFile bool
370-
IsRenamed bool
371-
IsAmbiguous bool
360+
Name string
361+
NameHash string
362+
OldName string
363+
Addition, Deletion int
364+
Type DiffFileType
365+
IsCreated bool
366+
IsDeleted bool
367+
IsBin bool
368+
IsLFSFile bool
369+
IsRenamed bool
370+
371+
// only used internally to parse Ambiguous filenames
372+
isAmbiguous bool
373+
372374
Sections []*DiffSection
373375
IsIncomplete bool
374376
IsIncompleteLineTooLong bool
@@ -645,28 +647,28 @@ parsingLoop:
645647
case strings.HasPrefix(line, "rename from "):
646648
curFile.IsRenamed = true
647649
curFile.Type = DiffFileRename
648-
if curFile.IsAmbiguous {
650+
if curFile.isAmbiguous {
649651
curFile.OldName = prepareValue(line, "rename from ")
650652
}
651653
case strings.HasPrefix(line, "rename to "):
652654
curFile.IsRenamed = true
653655
curFile.Type = DiffFileRename
654-
if curFile.IsAmbiguous {
656+
if curFile.isAmbiguous {
655657
curFile.Name = prepareValue(line, "rename to ")
656-
curFile.IsAmbiguous = false
658+
curFile.isAmbiguous = false
657659
}
658660
case strings.HasPrefix(line, "copy from "):
659661
curFile.IsRenamed = true
660662
curFile.Type = DiffFileCopy
661-
if curFile.IsAmbiguous {
663+
if curFile.isAmbiguous {
662664
curFile.OldName = prepareValue(line, "copy from ")
663665
}
664666
case strings.HasPrefix(line, "copy to "):
665667
curFile.IsRenamed = true
666668
curFile.Type = DiffFileCopy
667-
if curFile.IsAmbiguous {
669+
if curFile.isAmbiguous {
668670
curFile.Name = prepareValue(line, "copy to ")
669-
curFile.IsAmbiguous = false
671+
curFile.isAmbiguous = false
670672
}
671673
case strings.HasPrefix(line, "new file"):
672674
curFile.Type = DiffFileAdd
@@ -693,7 +695,7 @@ parsingLoop:
693695
curFile.IsBin = true
694696
case strings.HasPrefix(line, "--- "):
695697
// Handle ambiguous filenames
696-
if curFile.IsAmbiguous {
698+
if curFile.isAmbiguous {
697699
// The shortest string that can end up here is:
698700
// "--- a\t\n" without the quotes.
699701
// This line has a len() of 7 but doesn't contain a oldName.
@@ -711,7 +713,7 @@ parsingLoop:
711713
// Otherwise do nothing with this line
712714
case strings.HasPrefix(line, "+++ "):
713715
// Handle ambiguous filenames
714-
if curFile.IsAmbiguous {
716+
if curFile.isAmbiguous {
715717
if len(line) > 6 && line[4] == 'b' {
716718
curFile.Name = line[6 : len(line)-1]
717719
if line[len(line)-2] == '\t' {
@@ -723,7 +725,7 @@ parsingLoop:
723725
} else {
724726
curFile.Name = curFile.OldName
725727
}
726-
curFile.IsAmbiguous = false
728+
curFile.isAmbiguous = false
727729
}
728730
// Otherwise do nothing with this line, but now switch to parsing hunks
729731
lineBytes, isFragment, err := parseHunks(ctx, curFile, maxLines, maxLineCharacters, input)
@@ -1047,12 +1049,11 @@ func createDiffFile(diff *Diff, line string) *DiffFile {
10471049
//
10481050
// Path names are quoted if necessary.
10491051
//
1050-
// This means that you should always be able to determine the file name even when there
1052+
// This means that you should always be able to determine the file name even when
10511053
// there is potential ambiguity...
10521054
//
10531055
// but we can be simpler with our heuristics by just forcing git to prefix things nicely
10541056
curFile := &DiffFile{
1055-
Index: len(diff.Files) + 1,
10561057
Type: DiffFileChange,
10571058
Sections: make([]*DiffSection, 0, 10),
10581059
}
@@ -1064,7 +1065,7 @@ func createDiffFile(diff *Diff, line string) *DiffFile {
10641065
curFile.OldName, oldNameAmbiguity = readFileName(rd)
10651066
curFile.Name, newNameAmbiguity = readFileName(rd)
10661067
if oldNameAmbiguity && newNameAmbiguity {
1067-
curFile.IsAmbiguous = true
1068+
curFile.isAmbiguous = true
10681069
// OK we should bet that the oldName and the newName are the same if they can be made to be same
10691070
// So we need to start again ...
10701071
if (len(line)-len(cmdDiffHead)-1)%2 == 0 {

templates/repo/diff/image_diff.tmpl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
>
1010
<overflow-menu class="ui secondary pointing tabular menu custom">
1111
<div class="overflow-menu-items tw-justify-center">
12-
<a class="item active" data-tab="diff-side-by-side-{{.file.Index}}">{{ctx.Locale.Tr "repo.diff.image.side_by_side"}}</a>
12+
<a class="item active" data-tab="diff-side-by-side-{{.file.NameHash}}">{{ctx.Locale.Tr "repo.diff.image.side_by_side"}}</a>
1313
{{if and .blobBase .blobHead}}
14-
<a class="item" data-tab="diff-swipe-{{.file.Index}}">{{ctx.Locale.Tr "repo.diff.image.swipe"}}</a>
15-
<a class="item" data-tab="diff-overlay-{{.file.Index}}">{{ctx.Locale.Tr "repo.diff.image.overlay"}}</a>
14+
<a class="item" data-tab="diff-swipe-{{.file.NameHash}}">{{ctx.Locale.Tr "repo.diff.image.swipe"}}</a>
15+
<a class="item" data-tab="diff-overlay-{{.file.NameHash}}">{{ctx.Locale.Tr "repo.diff.image.overlay"}}</a>
1616
{{end}}
1717
</div>
1818
</overflow-menu>
1919
<div class="image-diff-tabs is-loading">
20-
<div class="ui bottom attached tab image-diff-container active" data-tab="diff-side-by-side-{{.file.Index}}">
20+
<div class="ui bottom attached tab image-diff-container active" data-tab="diff-side-by-side-{{.file.NameHash}}">
2121
<div class="diff-side-by-side">
2222
{{if .blobBase}}
2323
<span class="side">
@@ -52,7 +52,7 @@
5252
</div>
5353
</div>
5454
{{if and .blobBase .blobHead}}
55-
<div class="ui bottom attached tab image-diff-container" data-tab="diff-swipe-{{.file.Index}}">
55+
<div class="ui bottom attached tab image-diff-container" data-tab="diff-swipe-{{.file.NameHash}}">
5656
<div class="diff-swipe">
5757
<div class="swipe-frame">
5858
<span class="before-container"><img class="image-before"></span>
@@ -66,7 +66,7 @@
6666
</div>
6767
</div>
6868
</div>
69-
<div class="ui bottom attached tab image-diff-container" data-tab="diff-overlay-{{.file.Index}}">
69+
<div class="ui bottom attached tab image-diff-container" data-tab="diff-overlay-{{.file.NameHash}}">
7070
<div class="diff-overlay">
7171
<input type="range" min="0" max="100" value="50">
7272
<div class="overlay-frame">

0 commit comments

Comments
 (0)