Skip to content

Commit f1fd8a7

Browse files
zeripath6543
andauthored
Fix initial commit page & binary munching problem (go-gitea#13249) (go-gitea#13259)
Backport go-gitea#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 go-gitea#13248 Signed-off-by: Andrew Thornton <[email protected]> * Update services/gitdiff/gitdiff.go Co-authored-by: 6543 <[email protected]> Co-authored-by: 6543 <[email protected]>
1 parent 9f9a53e commit f1fd8a7

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

services/gitdiff/gitdiff.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ parsingLoop:
498498
break parsingLoop
499499
}
500500
switch {
501+
case strings.HasPrefix(line, cmdDiffHead):
502+
break curFileLoop
501503
case strings.HasPrefix(line, "old mode ") ||
502504
strings.HasPrefix(line, "new mode "):
503505
if strings.HasSuffix(line, " 160000\n") {
@@ -815,8 +817,15 @@ func GetDiffRangeWithWhitespaceBehavior(repoPath, beforeCommitID, afterCommitID
815817
ctx, cancel := context.WithCancel(git.DefaultContext)
816818
defer cancel()
817819
var cmd *exec.Cmd
818-
if len(beforeCommitID) == 0 && commit.ParentCount() == 0 {
819-
cmd = exec.CommandContext(ctx, git.GitExecutable, "show", afterCommitID)
820+
if (len(beforeCommitID) == 0 || beforeCommitID == git.EmptySHA) && commit.ParentCount() == 0 {
821+
diffArgs := []string{"diff", "--src-prefix=\\a/", "--dst-prefix=\\b/", "-M"}
822+
if len(whitespaceBehavior) != 0 {
823+
diffArgs = append(diffArgs, whitespaceBehavior)
824+
}
825+
// append empty tree ref
826+
diffArgs = append(diffArgs, "4b825dc642cb6eb9a060e54bf8d69288fbee4904")
827+
diffArgs = append(diffArgs, afterCommitID)
828+
cmd = exec.CommandContext(ctx, git.GitExecutable, diffArgs...)
820829
} else {
821830
actualBeforeCommitID := beforeCommitID
822831
if len(actualBeforeCommitID) == 0 {

0 commit comments

Comments
 (0)