From: Matthieu Moy <Matthieu.Moy@grenoble-inp•fr>
To: Karthik Nayak <karthik.188@gmail•com>
Cc: git@vger•kernel.org, christian.couder@gmail•com, gitster@pobox•com
Subject: Re: [PATCH v5 7/8] branch.c: use 'ref-filter' APIs
Date: Sun, 20 Sep 2015 21:24:24 +0200 [thread overview]
Message-ID: <vpqmvwgevx3.fsf@anie.imag.fr> (raw)
In-Reply-To: <1442772627-25421-8-git-send-email-Karthik.188@gmail.com> (Karthik Nayak's message of "Sun, 20 Sep 2015 23:40:26 +0530")
Karthik Nayak <karthik.188@gmail•com> writes:
> --- a/Documentation/git-branch.txt
> +++ b/Documentation/git-branch.txt
> @@ -231,6 +231,13 @@ start-point is either a local or remote-tracking branch.
> The new name for an existing branch. The same restrictions as for
> <branchname> apply.
>
> +--sort=<key>::
> + Sort based on the key given. Prefix `-` to sort in descending
> + order of the value. You may use the --sort=<key> option
> + multiple times, in which case the last key becomes the primary
> + key. The keys supported are the same as those in `git
> + for-each-ref`. Sort order defaults to sorting based on branch
> + type.
The last sentence is no longer true. Perhaps something like:
Sort order defaults to sorting based on the full refname (including
`refs/...` prefix). This lists detached HEAD (if present) first, then
local branches and finally remote-tracking branches.
> -static void print_ref_list(struct ref_filter *filter)
> +static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sorting)
> {
> int i;
> struct ref_array array;
> - struct ref_filter_cbdata data;
> int maxwidth = 0;
> const char *remote_prefix = "";
> - struct rev_info revs;
> + struct ref_sorting def_sorting;
> + const char *sort_type = "refname";
You are using refname without special-casing HEAD at all. So, this is
relying on the fact that HEAD comes alphabetically before refs/..., and
that we are only listing refs/... and HEAD.
As I mentionned earlyer, if we ever allow branch to list e.g.
FETCH_HEAD, then the detached HEAD will come in the middle. I first
thought that this was too fragile, but after thinking about it, I think
this is actually sensible. After all, if we ever allow FETCH_HEAD, then
keeping the alphabetical order still makes sense.
So, your code is OK, but a bit too subtle to my taste: you should add a
comment explaining why sorting according to refname is sufficient (I
would use a comment, but a better commit message may be OK too).
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
next prev parent reply other threads:[~2015-09-20 19:24 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-20 18:10 [PATCH v5 0/8] port the filtering part of branch.c to use ref-filter APIs Karthik Nayak
2015-09-20 18:10 ` [PATCH v5 1/8] branch: refactor width computation Karthik Nayak
2015-09-20 18:10 ` [PATCH v5 2/8] branch: bump get_head_description() to the top Karthik Nayak
2015-09-20 18:10 ` [PATCH v5 3/8] branch: roll show_detached HEAD into regular ref_list Karthik Nayak
2015-09-20 19:11 ` Matthieu Moy
2015-09-20 18:10 ` [PATCH v5 4/8] branch: move 'current' check down to the presentation layer Karthik Nayak
2015-09-20 18:10 ` [PATCH v5 5/8] branch: drop non-commit error reporting Karthik Nayak
2015-09-20 19:16 ` Matthieu Moy
2015-09-21 10:20 ` Karthik Nayak
2015-09-21 11:35 ` Karthik Nayak
2015-09-20 18:10 ` [PATCH v5 6/8] branch.c: use 'ref-filter' data structures Karthik Nayak
2015-09-20 18:10 ` [PATCH v5 7/8] branch.c: use 'ref-filter' APIs Karthik Nayak
2015-09-20 19:24 ` Matthieu Moy [this message]
2015-09-21 10:21 ` Karthik Nayak
2015-09-20 18:10 ` [PATCH v5 8/8] branch: add '--points-at' option Karthik Nayak
2015-09-20 19:00 ` [PATCH v5 0/8] port the filtering part of branch.c to use ref-filter APIs Matthieu Moy
2015-09-21 6:11 ` Karthik Nayak
2015-09-21 6:23 ` Matthieu Moy
2015-09-21 10:15 ` 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=vpqmvwgevx3.fsf@anie.imag.fr \
--to=matthieu.moy@grenoble-inp$(echo .)fr \
--cc=christian.couder@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
--cc=karthik.188@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox