From 2db010b940e64ccf3f5281b0b38b5e673360508b Mon Sep 17 00:00:00 2001 From: zeripath Date: Thu, 22 Oct 2020 00:08:44 +0100 Subject: [PATCH] Fix initial commit page & binary munching problem (#13249) Backport #13249 * Fix initial commit page Unfortunately as a result of properly fixing ParsePatch the hack that used git show 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 * Also fix #13248 Signed-off-by: Andrew Thornton * Update services/gitdiff/gitdiff.go Co-authored-by: 6543 <6543@obermui.de> --- services/gitdiff/gitdiff.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index 164e1c0ca5866..7acf8324c3a5e 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -530,6 +530,8 @@ parsingLoop: break parsingLoop } switch { + case strings.HasPrefix(line, cmdDiffHead): + break curFileLoop case strings.HasPrefix(line, "old mode ") || strings.HasPrefix(line, "new mode "): if strings.HasSuffix(line, " 160000\n") { @@ -850,7 +852,14 @@ func GetDiffRangeWithWhitespaceBehavior(repoPath, beforeCommitID, afterCommitID defer cancel() var cmd *exec.Cmd if (len(beforeCommitID) == 0 || beforeCommitID == git.EmptySHA) && commit.ParentCount() == 0 { - cmd = exec.CommandContext(ctx, git.GitExecutable, "show", afterCommitID) + diffArgs := []string{"diff", "--src-prefix=\\a/", "--dst-prefix=\\b/", "-M"} + if len(whitespaceBehavior) != 0 { + diffArgs = append(diffArgs, whitespaceBehavior) + } + // append empty tree ref + diffArgs = append(diffArgs, "4b825dc642cb6eb9a060e54bf8d69288fbee4904") + diffArgs = append(diffArgs, afterCommitID) + cmd = exec.CommandContext(ctx, git.GitExecutable, diffArgs...) } else { actualBeforeCommitID := beforeCommitID if len(actualBeforeCommitID) == 0 {