Search code examples
gitlibgit2objective-git

git_revwalk ignores order of pushed refs?


In using git_revwalk (through Objective-Git's GTEnumerator), I'm trying to get more recently updated branches ordered first. I'm calling gt_revwalk_push with refs sorted by commit date, but it has no effect. Sorted, reverse sorted, and unsorted all come out the same.

Using GIT_SORT_TIME without GIT_SORT_TOPOLOGICAL comes close, but I do need a topological ordering, so I'm setting both flags.

Is there a way to get git_revwalk to use the refs in the order I give them?


Solution

  • libgit2 would often not provide quite the same topological sorting as git, since there are multiple possible topological sortings which are all correct.

    A recent PR ported over more code from git to make the output more consistent for other reasons, so you make use of that. Specifying both a topological and time-based sort (GIT_SORT_TOPOLOGICAL | GIT_SORT_TIME), equivalent to git rev-list's --date-order will sort the tips you requested by time with the current master.