diff options
author | zeripath | 2020-10-22 15:30:19 +0100 |
---|---|---|
committer | GitHub | 2020-10-22 15:30:19 +0100 |
commit | f1fd8a772f5c7b9953c901ac43dc341d2575e9ed (patch) | |
tree | 9a3854ef59fcdcce726aba7f13f1a19991fe09be | |
parent | 9f9a53e361f3199e83e62fa8c4b7327204d42eaf (diff) |
Fix initial commit page & binary munching problem (#13249) (#13259)
Backport #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 <art27@cantab.net>
* Also fix #13248
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Update services/gitdiff/gitdiff.go
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: 6543 <6543@obermui.de>
-rw-r--r-- | services/gitdiff/gitdiff.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index 4da47fc87..4efe9e93a 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -498,6 +498,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") { @@ -815,8 +817,15 @@ func GetDiffRangeWithWhitespaceBehavior(repoPath, beforeCommitID, afterCommitID ctx, cancel := context.WithCancel(git.DefaultContext) defer cancel() var cmd *exec.Cmd - if len(beforeCommitID) == 0 && commit.ParentCount() == 0 { - cmd = exec.CommandContext(ctx, git.GitExecutable, "show", afterCommitID) + if (len(beforeCommitID) == 0 || beforeCommitID == git.EmptySHA) && commit.ParentCount() == 0 { + 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 { |