@@ -371,6 +371,8 @@ type DiffFile struct {
371
371
IsViewed bool // User specific
372
372
HasChangedSinceLastReview bool // User specific
373
373
Language string
374
+ Mode string
375
+ OldMode string
374
376
}
375
377
376
378
// GetType returns type of diff file.
@@ -501,6 +503,11 @@ func ParsePatch(maxLines, maxLineCharacters, maxFiles int, reader io.Reader, ski
501
503
}
502
504
return diff , err
503
505
}
506
+
507
+ prepareValue := func (s , p string ) string {
508
+ return strings .TrimSpace (strings .TrimPrefix (s , p ))
509
+ }
510
+
504
511
parsingLoop:
505
512
for {
506
513
// 1. A patch file always begins with `diff --git ` + `a/path b/path` (possibly quoted)
@@ -585,43 +592,55 @@ parsingLoop:
585
592
}
586
593
break parsingLoop
587
594
}
595
+
588
596
switch {
589
597
case strings .HasPrefix (line , cmdDiffHead ):
590
598
break curFileLoop
591
599
case strings .HasPrefix (line , "old mode " ) ||
592
600
strings .HasPrefix (line , "new mode " ):
601
+
602
+ if strings .HasPrefix (line , "old mode " ) {
603
+ curFile .OldMode = prepareValue (line , "old mode " )
604
+ }
605
+ if strings .HasPrefix (line , "new mode " ) {
606
+ curFile .Mode = prepareValue (line , "new mode " )
607
+ }
608
+
593
609
if strings .HasSuffix (line , " 160000\n " ) {
594
610
curFile .IsSubmodule = true
595
611
}
596
612
case strings .HasPrefix (line , "rename from " ):
597
613
curFile .IsRenamed = true
598
614
curFile .Type = DiffFileRename
599
615
if curFile .IsAmbiguous {
600
- curFile .OldName = line [ len ( "rename from " ) : len ( line ) - 1 ]
616
+ curFile .OldName = prepareValue ( line , "rename from " )
601
617
}
602
618
case strings .HasPrefix (line , "rename to " ):
603
619
curFile .IsRenamed = true
604
620
curFile .Type = DiffFileRename
605
621
if curFile .IsAmbiguous {
606
- curFile .Name = line [ len ( "rename to " ) : len ( line ) - 1 ]
622
+ curFile .Name = prepareValue ( line , "rename to " )
607
623
curFile .IsAmbiguous = false
608
624
}
609
625
case strings .HasPrefix (line , "copy from " ):
610
626
curFile .IsRenamed = true
611
627
curFile .Type = DiffFileCopy
612
628
if curFile .IsAmbiguous {
613
- curFile .OldName = line [ len ( "copy from " ) : len ( line ) - 1 ]
629
+ curFile .OldName = prepareValue ( line , "copy from " )
614
630
}
615
631
case strings .HasPrefix (line , "copy to " ):
616
632
curFile .IsRenamed = true
617
633
curFile .Type = DiffFileCopy
618
634
if curFile .IsAmbiguous {
619
- curFile .Name = line [ len ( "copy to " ) : len ( line ) - 1 ]
635
+ curFile .Name = prepareValue ( line , "copy to " )
620
636
curFile .IsAmbiguous = false
621
637
}
622
638
case strings .HasPrefix (line , "new file" ):
623
639
curFile .Type = DiffFileAdd
624
640
curFile .IsCreated = true
641
+ if strings .HasPrefix (line , "new file mode " ) {
642
+ curFile .Mode = prepareValue (line , "new file mode " )
643
+ }
625
644
if strings .HasSuffix (line , " 160000\n " ) {
626
645
curFile .IsSubmodule = true
627
646
}
0 commit comments