-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Make gogit Repository.GetBranchNames consistent #28348
Conversation
nogogit GetBranchNames() lists branches sorted in reverse commit date order. On the other hand the gogit implementation doesn't apply any ordering resulting in unpredictable behaviour. In my case, the unit tests requiring particular order fail repo_branch_test.go:24: Error Trace: ./gitea/modules/git/repo_branch_test.go:24 Error: elements differ extra elements in list A: ([]interface {}) (len=1) { (string) (len=6) "master" } extra elements in list B: ([]interface {}) (len=1) { (string) (len=7) "branch1" } listA: ([]string) (len=2) { (string) (len=6) "master", (string) (len=7) "branch2" } listB: ([]string) (len=2) { (string) (len=7) "branch1", (string) (len=7) "branch2" } Test: TestRepository_GetBranches To fix this, we sort branches based on their commit date in gogit implementation. Fixes: go-gitea#28318
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried using the Log
function in go-git? After I checked the branches
function in go-git, the code logic seemed cumbersome to me because the code iterates first to filter out the type branch
and then sort.
I think using the Log
function with an embedded heap sort to get the hash ref iterator and using the hash ref to see if it's a branch ref during the iteration would be a more effective way. Correct me if my understanding needs to be corrected because I'm not so familiar with the go-git package.
I had no idea about the said https://github.com/go-git/go-git/blob/master/_examples/log/main.go and the implementation, https://github.com/go-git/go-git/blob/master/repository.go#L1236 It looks like https://github.com/go-git/go-git/blob/master/repository.go#L1379 since it goes through all the "References" (see refs/ directory in git repository). There generally are not a lot of these. But if that's not exactly true, it should be fixed in go-git instead of here. |
You are right. I think
You are right. It seems that the API provided by go-git is not that flexible. |
Backport #28348 by @AdamMajer nogogit GetBranchNames() lists branches sorted in reverse commit date order. On the other hand the gogit implementation doesn't apply any ordering resulting in unpredictable behaviour. In my case, the unit tests requiring particular order fail repo_branch_test.go:24: Error Trace: ./gitea/modules/git/repo_branch_test.go:24 Error: elements differ extra elements in list A: ([]interface {}) (len=1) { (string) (len=6) "master" } extra elements in list B: ([]interface {}) (len=1) { (string) (len=7) "branch1" } listA: ([]string) (len=2) { (string) (len=6) "master", (string) (len=7) "branch2" } listB: ([]string) (len=2) { (string) (len=7) "branch1", (string) (len=7) "branch2" } Test: TestRepository_GetBranches To fix this, we sort branches based on their commit date in gogit implementation. Fixes: #28318 Co-authored-by: Adam Majer <amajer@suse.de>
* giteaofficial/main: Improve text in Security settings (go-gitea#28393) Fix Docker meta action for releases (go-gitea#28232) Make gogit Repository.GetBranchNames consistent (go-gitea#28348) Remove GetByBean method because sometimes it's danger when query condition parameter is zero and also introduce new generic methods (go-gitea#28220) Include public repos in doer's dashboard for issue search (go-gitea#28304) Issue fixes for RSS feed improvements (go-gitea#28380) Fix margin in server signed signature verification view (go-gitea#28379) [skip ci] Updated translations via Crowdin Fix incorrect run order of action jobs (go-gitea#28367) Improve RSS feed icons (go-gitea#28368) Use `filepath` instead of `path` to create SQLite3 database file (go-gitea#28374) Fix incorrect default value of `[attachment].MAX_SIZE` (go-gitea#28373) Fix object does not exist error when checking citation file (go-gitea#28314)
nogogit GetBranchNames() lists branches sorted in reverse commit date order. On the other hand the gogit implementation doesn't apply any ordering resulting in unpredictable behaviour. In my case, the unit tests requiring particular order fail
To fix this, we sort branches based on their commit date in gogit implementation.
Fixes: #28318