0

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?

Uncommon
  • 3,323
  • 2
  • 18
  • 36
  • I know nothing of Objective-Git but asking for a topo sort *and* a time-based sort is like asking for 1 PM to come before noon because 1 is less than 12. You must give up on one of these two criteria: you can't get both. – torek Sep 29 '16 at 19:11
  • With both flags, I would expect commits from parallel branches to be sorted relative to each other. That would be possible to a limited extent without violating topological order. But anyway, that's tangential to my real problem. I would expect, for example, that the newest commit should come out first since that's the ref that I pushed first, and that's not happening. – Uncommon Sep 29 '16 at 19:24
  • ...of course, that's assuming that the first ref points to a commit with no children, which it does in my test case. – Uncommon Sep 29 '16 at 21:25
  • True, you can use one as a secondary sort criterion when the first criterion produces a tie. Topo has to go first to have any meaning at all, so this merely picks which edge to traverse depth-first based on sorting the outgoing edges by node time-stamps. With Git, that means sorting the parents by author or committer date. (Note that outgoing edges are *parent* links, not *child* links.) – torek Sep 29 '16 at 22:20

1 Answers1

1

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.

Carlos Martín Nieto
  • 5,207
  • 1
  • 15
  • 16