@@ -357,34 +357,44 @@ func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine, loc
357357
358358// DiffFile represents a file diff.
359359type 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
372- Sections []* DiffSection
373- IsIncomplete bool
374- IsIncompleteLineTooLong bool
375- IsProtected bool
376- IsGenerated bool
377- IsVendored bool
360+ // only used internally to parse Ambiguous filenames
361+ isAmbiguous bool
362+
363+ // basic fields (parsed from diff result)
364+ Name string
365+ NameHash string
366+ OldName string
367+ Addition int
368+ Deletion int
369+ Type DiffFileType
370+ Mode string
371+ OldMode string
372+ IsCreated bool
373+ IsDeleted bool
374+ IsBin bool
375+ IsLFSFile bool
376+ IsRenamed bool
377+ IsSubmodule bool
378+ // basic fields but for render purpose only
379+ Sections []* DiffSection
380+ IsIncomplete bool
381+ IsIncompleteLineTooLong bool
382+
383+ // will be filled by the extra loop in GitDiff
384+ Language string
385+ IsGenerated bool
386+ IsVendored bool
387+ SubmoduleDiffInfo * SubmoduleDiffInfo // IsSubmodule==true, then there must be a SubmoduleDiffInfo
388+
389+ // will be filled by route handler
390+ IsProtected bool
391+
392+ // will be filled by SyncUserSpecificDiff
378393 IsViewed bool // User specific
379394 HasChangedSinceLastReview bool // User specific
380- Language string
381- Mode string
382- OldMode string
383395
384- IsSubmodule bool // if IsSubmodule==true, then there must be a SubmoduleDiffInfo
385- SubmoduleDiffInfo * SubmoduleDiffInfo
386-
387- highlightedOldLines map [int ]template.HTML // TODO: in the future, we only need to store the related diff lines to save memory
396+ // for render purpose only, TODO: in the future, we only need to store the related diff lines to save memory
397+ highlightedOldLines map [int ]template.HTML
388398 highlightedNewLines map [int ]template.HTML
389399}
390400
@@ -645,28 +655,28 @@ parsingLoop:
645655 case strings .HasPrefix (line , "rename from " ):
646656 curFile .IsRenamed = true
647657 curFile .Type = DiffFileRename
648- if curFile .IsAmbiguous {
658+ if curFile .isAmbiguous {
649659 curFile .OldName = prepareValue (line , "rename from " )
650660 }
651661 case strings .HasPrefix (line , "rename to " ):
652662 curFile .IsRenamed = true
653663 curFile .Type = DiffFileRename
654- if curFile .IsAmbiguous {
664+ if curFile .isAmbiguous {
655665 curFile .Name = prepareValue (line , "rename to " )
656- curFile .IsAmbiguous = false
666+ curFile .isAmbiguous = false
657667 }
658668 case strings .HasPrefix (line , "copy from " ):
659669 curFile .IsRenamed = true
660670 curFile .Type = DiffFileCopy
661- if curFile .IsAmbiguous {
671+ if curFile .isAmbiguous {
662672 curFile .OldName = prepareValue (line , "copy from " )
663673 }
664674 case strings .HasPrefix (line , "copy to " ):
665675 curFile .IsRenamed = true
666676 curFile .Type = DiffFileCopy
667- if curFile .IsAmbiguous {
677+ if curFile .isAmbiguous {
668678 curFile .Name = prepareValue (line , "copy to " )
669- curFile .IsAmbiguous = false
679+ curFile .isAmbiguous = false
670680 }
671681 case strings .HasPrefix (line , "new file" ):
672682 curFile .Type = DiffFileAdd
@@ -693,7 +703,7 @@ parsingLoop:
693703 curFile .IsBin = true
694704 case strings .HasPrefix (line , "--- " ):
695705 // Handle ambiguous filenames
696- if curFile .IsAmbiguous {
706+ if curFile .isAmbiguous {
697707 // The shortest string that can end up here is:
698708 // "--- a\t\n" without the quotes.
699709 // This line has a len() of 7 but doesn't contain a oldName.
@@ -711,7 +721,7 @@ parsingLoop:
711721 // Otherwise do nothing with this line
712722 case strings .HasPrefix (line , "+++ " ):
713723 // Handle ambiguous filenames
714- if curFile .IsAmbiguous {
724+ if curFile .isAmbiguous {
715725 if len (line ) > 6 && line [4 ] == 'b' {
716726 curFile .Name = line [6 : len (line )- 1 ]
717727 if line [len (line )- 2 ] == '\t' {
@@ -723,7 +733,7 @@ parsingLoop:
723733 } else {
724734 curFile .Name = curFile .OldName
725735 }
726- curFile .IsAmbiguous = false
736+ curFile .isAmbiguous = false
727737 }
728738 // Otherwise do nothing with this line, but now switch to parsing hunks
729739 lineBytes , isFragment , err := parseHunks (ctx , curFile , maxLines , maxLineCharacters , input )
@@ -1047,12 +1057,11 @@ func createDiffFile(diff *Diff, line string) *DiffFile {
10471057 //
10481058 // Path names are quoted if necessary.
10491059 //
1050- // This means that you should always be able to determine the file name even when there
1060+ // This means that you should always be able to determine the file name even when
10511061 // there is potential ambiguity...
10521062 //
10531063 // but we can be simpler with our heuristics by just forcing git to prefix things nicely
10541064 curFile := & DiffFile {
1055- Index : len (diff .Files ) + 1 ,
10561065 Type : DiffFileChange ,
10571066 Sections : make ([]* DiffSection , 0 , 10 ),
10581067 }
@@ -1064,7 +1073,7 @@ func createDiffFile(diff *Diff, line string) *DiffFile {
10641073 curFile .OldName , oldNameAmbiguity = readFileName (rd )
10651074 curFile .Name , newNameAmbiguity = readFileName (rd )
10661075 if oldNameAmbiguity && newNameAmbiguity {
1067- curFile .IsAmbiguous = true
1076+ curFile .isAmbiguous = true
10681077 // OK we should bet that the oldName and the newName are the same if they can be made to be same
10691078 // So we need to start again ...
10701079 if (len (line )- len (cmdDiffHead )- 1 )% 2 == 0 {
0 commit comments