Re: [PATCH v2 1/1] ref-filter: sort detached HEAD lines firstly
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 11, 2019, 20:10 UTC
- Message-ID
- <xmqq7e9rlw72.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <cf0246a5cce6cbd9b4a1fd1eefa0f5cbc2cfcaf0.1560277373.git.matvore@google.com>
Matthew DeVore <matvore@google.com> writes:
Show 6 quoted lines
> - if (s->version)
> + if (s->version) {
> cmp = versioncmp(va->s, vb->s);
> - else if (cmp_type == FIELD_STR)
> - cmp = cmp_fn(va->s, vb->s);
> - else {Ah, this must be the patch noise Jonathan was (half) complaining about. It does make it a bit distracting to read the patch but the resulting code is of course easier to follow ;-).
Show 12 quoted lines
> + } else if (cmp_type == FIELD_STR) {
> + const int a_detached = a->kind & FILTER_REFS_DETACHED_HEAD;
> +
> + /*
> + * When sorting by name, we should put "detached" head lines,
> + * which are all the lines in parenthesis, before all others.
> + * This usually is automatic, since "(" is before "refs/" and
> + * "remotes/", but this does not hold for zh_CN, which uses
> + * full-width parenthesis, so make the ordering explicit.
> + */
> + if (a_detached != (b->kind & FILTER_REFS_DETACHED_HEAD))
> + cmp = a_detached ? -1 : 1;So, comparing a detached and an undetached ones, the detached side always sorts lower. Good. And ...
> + else > + cmp = cmp_fn(va->s, vb->s);
... otherwise we compare the string using the given function.
Sounds sensible. Will queue.