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