All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] gitweb: use HEAD as primary sort key in git_get_heads_list()
@ 2021-06-06  8:51 Greg Hurrell
  2021-06-06  8:57 ` Greg Hurrell
  0 siblings, 1 reply; 10+ messages in thread
From: Greg Hurrell @ 2021-06-06  8:51 UTC (permalink / raw)
  To: git; +Cc: Greg Hurrell

Prior to this commit, the "heads" section on a gitweb summary page would
list the heads in `-committerdate` order (ie. the most recently-modified
ones at the top).

In my own repos I have started to move from "master" towards "main", but
I keep "master" around and in sync with "main" so as not to break
existing clones. As such, they always point at the same commit.

This means that in the "heads" listing of a gitweb instance, the display
order ends up being determined by how `git for-each-ref` decides to
tie-break "master" and "main"

For example, right now on a sample repo, gitweb shows the heads in this
order, even though "master" and "main" reference the same commit. The
tie-breaking evidently isn't happening lexicographically:

- master
- main
- pu
- next

So, this commit adds another `--sort` parameter to the `git
for-each-ref` invocation in `git_get_heads_list()`, ensuring that the
`HEAD` ref always ends up getting sorted to the top:

- main
- master
- pu
- next

This seems to be a useful change, because I can't see anywhere else in
the gitweb UI where we actually indicate to the user what the "default"
branch is (ie. what they'll checkout if they run `git clone`).
---
 gitweb/gitweb.perl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index e09e024a09..e5270b0291 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3796,7 +3796,8 @@ sub git_get_heads_list {
 	my @headslist;
 
 	open my $fd, '-|', git_cmd(), 'for-each-ref',
-		($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
+		($limit ? '--count='.($limit+1) : ()),
+		'--sort=-committerdate', '--sort=-HEAD',
 		'--format=%(objectname) %(refname) %(subject)%00%(committer)',
 		@patterns
 		or return;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-06-09 19:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-06  8:51 [RFC PATCH] gitweb: use HEAD as primary sort key in git_get_heads_list() Greg Hurrell
2021-06-06  8:57 ` Greg Hurrell
2021-06-08  8:34   ` Jeff King
2021-06-08  9:02     ` Greg Hurrell
2021-06-08 21:14       ` Greg Hurrell
2021-06-08 22:07         ` Jeff King
2021-06-09  0:15         ` Junio C Hamano
2021-06-09  7:38           ` Greg Hurrell
2021-06-09  7:47             ` Junio C Hamano
2021-06-09 19:28               ` [PATCH v2] gitweb: use HEAD as secondary " Greg Hurrell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.