git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: samuel.maftoul@gmail.com
Cc: git@vger.kernel.org, peff@peff.net, sunshine@sunshineco.com
Subject: Re: [PATCH] branch: support configuring --sort via .gitconfig
Date: Thu, 16 Aug 2018 11:16:49 -0700	[thread overview]
Message-ID: <xmqqva8advn2.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20180816093508.37193-1-samuel.maftoul@gmail.com> (samuel maftoul's message of "Thu, 16 Aug 2018 11:35:08 +0200")

samuel.maftoul@gmail.com writes:

> From: Samuel Maftoul <samuel.maftoul@gmail.com>
>
> Add support for configuring default sort ordering for git branches. Command
> line option will override this configured value, using the exact same
> syntax.

Using the exact same syntax as ...?

> Signed-off-by: Samuel Maftoul <samuel.maftoul@gmail.com>
> ---
>  Documentation/config.txt     |  6 +++++
>  Documentation/git-branch.txt |  5 ++--
>  builtin/branch.c             | 10 +++++++-
>  t/t3200-branch.sh            | 46 ++++++++++++++++++++++++++++++++++++
>  4 files changed, 64 insertions(+), 3 deletions(-)
>
> diff --git a/Documentation/config.txt b/Documentation/config.txt
> index fd8d27e76..7f7a50123 100644
> --- a/Documentation/config.txt
> +++ b/Documentation/config.txt
> @@ -1039,6 +1039,12 @@ branch.autoSetupRebase::
>  	branch to track another branch.
>  	This option defaults to never.
>  
> +branch.sort::
> +	This variable controls the sort ordering of branches when displayed by
> +	linkgit:git-branch[1]. Without the "--sort=<value>" option provided, the
> +	value of this variable will be used as the default.
> +	See linkgit:git-for-each-ref[1] field names for valid values.

OK, the answer to the above question is "same syntax as used for the
value of the `branch.sort` configuration variable".

> diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
> index 1072ca0eb..9767b2b48 100644
> --- a/Documentation/git-branch.txt
> +++ b/Documentation/git-branch.txt
> @@ -268,10 +268,11 @@ start-point is either a local or remote-tracking branch.
>  	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 the
> +	for-each-ref`. Sort order defaults to the value configured for the
> +	`branch.sort` variable if exists, or 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.
> +	finally remote-tracking branches. See linkgit:git-config[1].

OK.

> diff --git a/builtin/branch.c b/builtin/branch.c
> index 4fc55c350..bbd006aab 100644
> --- a/builtin/branch.c
> +++ b/builtin/branch.c
> @@ -74,6 +74,14 @@ define_list_config_array(color_branch_slots);
>  static int git_branch_config(const char *var, const char *value, void *cb)
>  {
>  	const char *slot_name;
> +	struct ref_sorting **sorting_tail = (struct ref_sorting **)cb;
> +
> +	if (!strcmp(var, "branch.sort")) {
> +		if (!value)
> +			return config_error_nonbool(var);
> +		parse_ref_sorting(sorting_tail, value);
> +		return 0;
> +	}

Hmph.  It is unfortunate that "don't feed me NULL" check is not in
parse_ref_sorting() but is in parse_opt_ref_sorting().  But that is
a separate low-hanging fruit.  The code we see here is correct.

Will queue.  Thanks.

      reply	other threads:[~2018-08-16 18:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-15 11:15 [PATCH] branch: support configuring --sort via .gitconfig samuel.maftoul
2018-08-15 16:59 ` Eric Sunshine
2018-08-16  8:05   ` samuel.maftoul
2018-08-16  8:56     ` Eric Sunshine
2018-08-16  9:35       ` samuel.maftoul
2018-08-16 18:16         ` Junio C Hamano [this message]

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=xmqqva8advn2.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=samuel.maftoul@gmail.com \
    --cc=sunshine@sunshineco.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).