Skip to content

Commit 327f18c

Browse files
zeripath6543
andauthored
Fix initial commit page & binary munching problem (#13249)
* Fix initial commit page Unfortunately as a result of properly fixing ParsePatch the hack that used git show <initial_commit_id> to get the diff for this failed. This PR fixes this using the "super-secret" empty tree ref to make the diff against. Signed-off-by: Andrew Thornton <[email protected]> * Also fix #13248 Signed-off-by: Andrew Thornton <[email protected]> * Update services/gitdiff/gitdiff.go Co-authored-by: 6543 <[email protected]>
1 parent f6ee7ce commit 327f18c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

services/gitdiff/gitdiff.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ parsingLoop:
530530
break parsingLoop
531531
}
532532
switch {
533+
case strings.HasPrefix(line, cmdDiffHead):
534+
break curFileLoop
533535
case strings.HasPrefix(line, "old mode ") ||
534536
strings.HasPrefix(line, "new mode "):
535537
if strings.HasSuffix(line, " 160000\n") {
@@ -850,7 +852,14 @@ func GetDiffRangeWithWhitespaceBehavior(repoPath, beforeCommitID, afterCommitID
850852
defer cancel()
851853
var cmd *exec.Cmd
852854
if (len(beforeCommitID) == 0 || beforeCommitID == git.EmptySHA) && commit.ParentCount() == 0 {
853-
cmd = exec.CommandContext(ctx, git.GitExecutable, "show", afterCommitID)
855+
diffArgs := []string{"diff", "--src-prefix=\\a/", "--dst-prefix=\\b/", "-M"}
856+
if len(whitespaceBehavior) != 0 {
857+
diffArgs = append(diffArgs, whitespaceBehavior)
858+
}
859+
// append empty tree ref
860+
diffArgs = append(diffArgs, "4b825dc642cb6eb9a060e54bf8d69288fbee4904")
861+
diffArgs = append(diffArgs, afterCommitID)
862+
cmd = exec.CommandContext(ctx, git.GitExecutable, diffArgs...)
854863
} else {
855864
actualBeforeCommitID := beforeCommitID
856865
if len(actualBeforeCommitID) == 0 {

0 commit comments

Comments
 (0)