=?UTF-8?Q?Re:_[RFC_PATCH]_gitweb:_use_HEAD_as_primary_sort_key_in_git=5F?= =?UTF-8?Q?get=5Fheads=5Flist()?=
Jeff King
Greg Hurrell
See Also
Prev Ref 1 Ref 2
2021-06-08 09:02:15 UTC
On Tue, Jun 8, 2021, at 10:34 AM, Jeff King wrote:
> In your earlier example, it sounded like you were primarily concerned
> with breaking ties. But here it sounds like you're proposing putting the
> HEAD first _regardless_ of the committer timestamp.

I arrived there organically. My initial goal was merely to find out why
"master" was sorting ahead of "main" even after I switched HEAD, as it
seemed arbitrary and possibly hard-coded.

Adding `--sort=-HEAD` wallpapers over the problem by forcing HEAD to the
top, but it doesn't address the underlying arbitrariness/non-determinism
of how refs with equal committerdate get treated.

So I like your idea of splitting this into two separate changes much

>   1. break ties by name, like:
>        git for-each-ref --sort=refname --sort=-committerdate
>   2. emphasize the HEAD branch, even if it isn't the newest:
>        git for-each-ref --sort=refname --sort=-committerdate --sort=-HEAD

I think adding "1" is a clear improvement. "2" is more debatable (I
think it would be of practical use, but as you said, HEAD is very often
going to be the most recently committed thing anyway). In my specific
use case (where "main" is the HEAD but "master" is kept in sync with it
automatically so as not to break existing clones), sorting by refname
_happens_ to mean that "main" will come before "master"; but that is of
course a quirk of my branch naming choices and not something that should
be relied upon.

In any case, splitting this into two pieces sounds good: we have the
option of taking one or both (or none).