All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Cc: Karthik Nayak <karthik.188@gmail.com>, Git <git@vger.kernel.org>,
	Christian Couder <christian.couder@gmail.com>
Subject: Re: [PATCH v4 3/8] branch: roll show_detached HEAD into regular ref_list
Date: Thu, 17 Sep 2015 08:15:27 -0700	[thread overview]
Message-ID: <xmqqh9mtkrg0.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <vpqpp1hqgcd.fsf@anie.imag.fr> (Matthieu Moy's message of "Thu, 17 Sep 2015 16:18:42 +0200")

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> Karthik Nayak <karthik.188@gmail.com> writes:
>
>> So either we could introduce a new atom for sorting something like
>> `branch_sort` which uses the FILTER_REFS_(DETACHED_HEAD | BRANCHES |
>> REMOTES)
>
> I don't think you need a new atom. You can just change the sorting
> function to consider that detached HEAD is always first, and when
> comparing two non-detached-HEAD branches, use the atom supplied by the
> user.
>
> That would mean the detached HEAD would be displayed first regardless of
> --sort (which is the case right now).

I am a bit fuzzy about this.  I do not understand why Karthik thinks
a new atom is necessary in the first place, and I do agree that the
best way to go would be to teach the sort function to do "the right
thing", but I am not sure why it has to be "regardless of --sort".

In the original for-each-ref (before it was butchered^W updated with
ref-filter), we grab refs and sort with default_sort() when "--sort"
is not given.  When --sort is given, we just use atoms to compare.

I do not think ref-filter broke that pattern, and as long as it kept
that pattern, I do not think the solution has to be more than just
"teach that default_sort() function, which sorts by refname, to
always show HEAD first".  When you throw HEAD into the mix, instead
of grabbing only from refs/*, you can still give that set to a
sorting function, which by default puts "HEAD" before others (just
like the sorting function for "branch -a" by default puts local
before remote-tracking), and you are done, no?

When the user does give a custom --sort criteria, the logic in
default_sort() would not kick in, so there is no need for special
casing for "HEAD" like the code I questioned in this thread.

What am I missing?

> Introducing a new atom would mean that "git branch --sort authorname"
> would not use this new atom, hence the HEAD would be sorted like the
> others.

I think that is exactly what people would expect.

Perhaps a slightly tricky would be "git branch -a --sort refname".
If you have HEAD, refs/heads/master, and refs/remotes/origin/master,
I'd expect that it would sort these in that order purely because
that is the textual/ascii sort order of the FULL refname.

And then at the presentation level you would strip refs/heads and
refs/remotes from local and remote-tracking branches, just like "git
branch -a" output has always done, from the sorted result when
showing.

"git branch -a --sort refname:short" would sort using HEAD vs master
vs origin/master in the above example and would end up mixing loal
and remote-tracking together, but that is what the user is asking
for, and the user deserves to get what s/he asked for.

Somewhat confused....

  reply	other threads:[~2015-09-17 15:15 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-13  7:23 [PATCH v4 0/8] port the filtering part of branch.c to use ref-filter APIs Karthik Nayak
2015-09-13  7:23 ` [PATCH v4 1/8] branch: refactor width computation Karthik Nayak
2015-09-13 11:51   ` Matthieu Moy
2015-09-13 12:23     ` Karthik Nayak
2015-09-13 12:33       ` Matthieu Moy
2015-09-13  7:23 ` [PATCH v4 2/8] branch: bump get_head_description() to the top Karthik Nayak
2015-09-13  7:23 ` [PATCH v4 3/8] branch: roll show_detached HEAD into regular ref_list Karthik Nayak
2015-09-13 12:12   ` Matthieu Moy
2015-09-13 13:24     ` Karthik Nayak
2015-09-13 16:46     ` Eric Sunshine
2015-09-13 18:31       ` Eric Sunshine
2015-09-14 14:48         ` Karthik Nayak
2015-09-14 14:54           ` Matthieu Moy
2015-09-14 19:35   ` Junio C Hamano
2015-09-16  6:23     ` Karthik Nayak
2015-09-17  9:47       ` Karthik Nayak
2015-09-17 14:18         ` Matthieu Moy
2015-09-17 15:15           ` Junio C Hamano [this message]
2015-09-17 15:43             ` Matthieu Moy
2015-09-17 16:49               ` Junio C Hamano
2015-09-17 17:08                 ` Matthieu Moy
2015-09-17 17:21                   ` Junio C Hamano
2015-09-17 18:25                   ` Karthik Nayak
2015-09-13  7:23 ` [PATCH v4 4/8] branch: move 'current' check down to the presentation layer Karthik Nayak
2015-09-13 12:15   ` Matthieu Moy
2015-09-13 13:22     ` Karthik Nayak
2015-09-13 15:35   ` Karthik Nayak
2015-09-13  7:23 ` [PATCH v4 5/8] branch: drop non-commit error reporting Karthik Nayak
2015-09-14 19:49   ` Junio C Hamano
2015-09-16  6:04     ` Karthik Nayak
2015-09-13  7:23 ` [PATCH v4 6/8] branch.c: use 'ref-filter' data structures Karthik Nayak
2015-09-13 12:26   ` Matthieu Moy
2015-09-13 13:19     ` Karthik Nayak
2015-09-13 17:49       ` Matthieu Moy
2015-09-13  7:23 ` Karthik Nayak
2015-09-13  7:32   ` Karthik Nayak
2015-09-13  7:23 ` [PATCH v4 8/8] branch: add '--points-at' option Karthik Nayak
2015-09-13  7:29 ` [PATCH v4 7/8] branch.c: use 'ref-filter' APIs Karthik Nayak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqh9mtkrg0.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=karthik.188@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.