]> Lady’s Gitweb - Gitweb/commit
gitweb: use HEAD as secondary sort key in git_get_heads_list()
authorGreg Hurrell <redacted>
Wed, 9 Jun 2021 19:28:06 +0000 (21:28 +0200)
committerLady <redacted>
Mon, 6 Apr 2026 04:51:33 +0000 (00:51 -0400)
commitd5ca249cbe6db5b1ebe794cb3007f2989e36bd62bfad51bf7c2a6482a48ca159
treec8dd0270f0b1579dbf78b1a354483286e0c8a0e182f6861fbd372d4224d0dfcb
parent55f06e7063188f3f6034f019e77a73880c5753c0dd1d95875fd36e7e1c87af7d
gitweb: use HEAD as secondary sort key in git_get_heads_list()

The "heads" section on the gitweb summary page shows heads in
`-committerdate` order (ie. the most recently-modified ones at the
top), tie-breaking equal-dated refs using the implicit `refname` sort
fallback. This recency-based ordering appears in multiple places in the
UI, such as the project listing, the tags list, and even the
shortlog and log views.

Given two equal-dated refs, however, sorting the `HEAD` ref before
the non-`HEAD` ref provides more useful signal than merely sorting by
refname. For example, say we had "master" and "trunk" both pointing at
the same commit but "trunk" was `HEAD`, sorting "trunk" first helps
communicate its special status as the default branch that you'll check
out if you clone the repo.

Add `-HEAD` as a secondary sort key to the `git for-each-ref` call
in `git_get_heads_list()` to provide the desired behavior. The most
recently committed refs will appear first, but `HEAD`-ness will be used
as a tie-breaker. Note that `refname` is the implicit fallback sort key,
which means that two same-dated non-`HEAD` refs will continue to be
sorted in lexicographical order, as they are today.

Signed-off-by: Greg Hurrell <redacted>
Signed-off-by: Junio C Hamano <redacted>
gitweb.perl
This page took 0.161769 seconds and 4 git commands to generate.