Skip to content

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

Conversation

zeripath
Copy link
Contributor

@zeripath zeripath commented May 29, 2020

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]

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]>
@zeripath zeripath added type/bug skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. labels May 29, 2020
@zeripath zeripath added this to the 1.13.0 milestone May 29, 2020
@zeripath
Copy link
Contributor Author

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.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 29, 2020
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels May 29, 2020
@a1012112796
Copy link
Member

please review #11674 again, Thanks

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels May 29, 2020
@zeripath
Copy link
Contributor Author

make lg-tm work

@zeripath zeripath merged commit 6e44808 into go-gitea:master May 29, 2020
@zeripath zeripath deleted the fix-11650-ensure-that-diffshortstat-works-for-initial-commit branch May 29, 2020 21:14
@a1012112796
Copy link
Member

Ok, I see. I thought in the wrong direction. Some nits for this change.
First, as we know, the reason is that the ParsePatch does not count the real number of files but counts the number of files to be shown, so if the file number is more than max file number, it will only return it. but if the file number is less than max file number, it won't be necessary to count again. For example,

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 100+, if users want to know more, they can increase git.MAX_GIT_DIFF_FILES when they have a good internet connection.

ydelafollye pushed a commit to ydelafollye/gitea that referenced this pull request Jul 31, 2020
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]>
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] When view first commit it return "Diff Content Not Available"
5 participants