-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Fix issue with DiffIndex on initial commit #11677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue with DiffIndex on initial commit #11677
Conversation
Unfortunately go-gitea#11614 introduced a bug whereby the initial commit of a repository could not be seen due to there being no parent commit to create a clear diff from. Here we ensure that the index is empty by referring to a non-existent file and the create a diffstat from the difference between it and the parentless SHA. Fix go-gitea#11650 Signed-off-by: Andrew Thornton <[email protected]>
As ever with this part of the codebase no good deed goes unpunished. I've said it before and no doubt I'll say it again the compare page endpoint is fragile, convoluted and highly inefficient. It needs a complete refactor. |
…an empty Tree See go-gitea#11674 (comment) Co-Authored-By: L0veSunshine <[email protected]> Signed-off-by: Andrew Thornton <[email protected]>
…for-initial-commit
please review #11674 again, Thanks |
…for-initial-commit
make lg-tm work |
Ok, I see. I thought in the wrong direction. Some nits for this change. diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index 02aef7088..7d5e31084 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -711,6 +711,10 @@ func GetDiffRangeWithWhitespaceBehavior(repoPath, beforeCommitID, afterCommitID
return nil, fmt.Errorf("Wait: %v", err)
}
+ if !diff.IsIncomplete {
+ return diff, err
+ }
+
shortstatArgs := []string{beforeCommitID + "..." + afterCommitID}
if len(beforeCommitID) == 0 || beforeCommitID == git.EmptySHA {
shortstatArgs = []string{git.EmptyTreeSHA, afterCommitID} Then, I still wonder whether it's necessary to show the real number of files if the file number is more than max file number. Maybe showing a plus sign is enough, for example |
Unfortunately go-gitea#11614 introduced a bug whereby the initial commit of a repository could not be seen due to there being no parent commit to create a clear diff from. Here we create a diffstat from the difference between the parentless SHA and the SHA of the empty tree - a constant known to git. (With thanks to @L0veSunshine for informing me of this SHA) Thanks to @a1012112796 for initial attempt to fix. Fix go-gitea#11650 Closes go-gitea#11674 Signed-off-by: Andrew Thornton <[email protected]> Co-Authored-By: L0veSunshine <[email protected]>
Unfortunately #11614 introduced a bug whereby the initial commit of a
repository could not be seen due to there being no parent commit to
create a clear diff from.
Here we create a diffstat from the difference between the parentless SHA and the SHA of the empty tree - a constant known to git. (With thanks to @L0veSunshine for informing me of this SHA)
Thanks to @a1012112796 for initial attempt to fix.
Fix #11650
Closes #11674
Signed-off-by: Andrew Thornton [email protected]