{"thread":{"id":"49131","subject":"[PATCH] branch: support configuring --sort via .gitconfig","startedAt":"2018-08-15T11:16:10Z","lastAt":"2018-08-16T18:16:58Z","messageCount":6,"participants":["samuel.maftoul@gmail.com","Eric Sunshine","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"355684","messageId":"20180815111544.30711-1-samuel.maftoul@gmail.com","threadId":"49131","inReplyTo":null,"subject":"[PATCH] branch: support configuring --sort via .gitconfig","fromName":"","fromEmail":"samuel.maftoul@gmail.com","sentAt":"2018-08-15T11:15:44Z","receivedAt":"2018-08-15T11:16:10Z","isPatch":true,"sender":{"key":"samuel.maftoul@gmail.com","avatar":"https://avatars.githubusercontent.com/u/239203?v=4"},"body":"From: Samuel Maftoul <samuel.maftoul@gmail.com>\n\nAdd support for configuring default sort ordering for git branches. Command\nline option will override this configured value, using the exact same\nsyntax.\n---\n Documentation/config.txt     |  5 +++++\n Documentation/git-branch.txt |  4 ++++\n builtin/branch.c             | 10 +++++++++-\n t/t3200-branch.sh            | 46 ++++++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 64 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 63365dcf3..82e306d20 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1034,6 +1034,11 @@ branch.autoSetupRebase::\n \tbranch to track another branch.\n \tThis option defaults to never.\n \n+branch.sort::\n+\tThis variable controls the sort ordering of branches when displayed by\n+\tlinkgit:git-branch[1]. Without the \"--sort=<value>\" option provided, the\n+\tvalue of this variable will be used as the default.\n+\n branch.<name>.remote::\n \tWhen on branch <name>, it tells 'git fetch' and 'git push'\n \twhich remote to fetch from/push to.  The remote to push to\ndiff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\nindex 1072ca0eb..9212a8d5d 100644\n--- a/Documentation/git-branch.txt\n+++ b/Documentation/git-branch.txt\n@@ -272,6 +272,10 @@ start-point is either a local or remote-tracking branch.\n \tfull refname (including `refs/...` prefix). This lists\n \tdetached HEAD (if present) first, then local branches and\n \tfinally remote-tracking branches.\n+\tThe keys supported are the same as those in `git for-each-ref`.\n+\tSort order defaults to the value configured for the `tag.sort`\n+\tvariable if it exists, or lexicographic order otherwise. See\n+\tlinkgit:git-config[1].\n \n \n --points-at <object>::\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 4fc55c350..bbd006aab 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -74,6 +74,14 @@ define_list_config_array(color_branch_slots);\n static int git_branch_config(const char *var, const char *value, void *cb)\n {\n \tconst char *slot_name;\n+\tstruct ref_sorting **sorting_tail = (struct ref_sorting **)cb;\n+\n+\tif (!strcmp(var, \"branch.sort\")) {\n+\t\tif (!value)\n+\t\t\treturn config_error_nonbool(var);\n+\t\tparse_ref_sorting(sorting_tail, value);\n+\t\treturn 0;\n+\t}\n \n \tif (starts_with(var, \"column.\"))\n \t\treturn git_column_config(var, value, \"branch\", &colopts);\n@@ -653,7 +661,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \tif (argc == 2 && !strcmp(argv[1], \"-h\"))\n \t\tusage_with_options(builtin_branch_usage, options);\n \n-\tgit_config(git_branch_config, NULL);\n+\tgit_config(git_branch_config, sorting_tail);\n \n \ttrack = git_branch_track;\n \ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex dbca665da..8bd42e9c6 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -1305,4 +1305,50 @@ test_expect_success 'tracking with unexpected .fetch refspec' '\n \t)\n '\n \n+test_expect_success 'configured committerdate sort' '\n+\tgit init sort &&\n+\t(\n+\t\tcd sort &&\n+\t\tgit config branch.sort committerdate &&\n+\t\ttest_commit initial &&\n+\t\tgit checkout -b a &&\n+\t\ttest_commit a &&\n+\t\tgit checkout -b c &&\n+\t\ttest_commit c &&\n+\t\tgit checkout -b b &&\n+\t\ttest_commit b &&\n+\t\tgit branch >actual &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\t  master\n+\t\t  a\n+\t\t  c\n+\t\t* b\n+\t\tEOF\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'option override configured sort' '\n+\t(\n+\t\tcd sort &&\n+\t\tgit branch --sort=refname >actual &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\t  a\n+\t\t* b\n+\t\t  c\n+\t\t  master\n+\t\tEOF\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'invalid sort parameter in configuration' '\n+       (\n+\t\tcd sort &&\n+\t\tgit config branch.sort \"v:notvalid\" &&\n+\t\ttest_must_fail git branch\n+\n+\t)\n+'\n+\n test_done\n-- \n2.14.3 (Apple Git-98)\n\n"},{"id":"355709","messageId":"CAPig+cSUy7rFwhmJ1SFHsAjPkoWparfY6wAjV=6kJyUL3SLQUw@mail.gmail.com","threadId":"49131","inReplyTo":"20180815111544.30711-1-samuel.maftoul@gmail.com","subject":"Re: [PATCH] branch: support configuring --sort via .gitconfig","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-08-15T16:59:26Z","receivedAt":"2018-08-15T16:59:40Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Wed, Aug 15, 2018 at 7:16 AM <samuel.maftoul@gmail.com> wrote:\n> Add support for configuring default sort ordering for git branches. Command\n> line option will override this configured value, using the exact same\n> syntax.\n\nYour Signed-off-by: is missing. See Documentation/SubmittingPatches.\n\n> diff --git a/Documentation/config.txt b/Documentation/config.txt\n> @@ -1034,6 +1034,11 @@ branch.autoSetupRebase::\n> +branch.sort::\n> +       This variable controls the sort ordering of branches when displayed by\n> +       linkgit:git-branch[1]. Without the \"--sort=<value>\" option provided, the\n> +       value of this variable will be used as the default.\n\nI realize that you copied this description from 'tag.sort', thus\ninherited its existing weakness, but as a reader of this, the first\nquestion which popped into my head was \"what are the possible\n<value>s? This description gives no clues and leaves the reader\nhanging. Better would be either to list the values or point the reader\n(possibly with a linkgit:) at documentation which does list them.\n\n> diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\n> @@ -272,6 +272,10 @@ start-point is either a local or remote-tracking branch.\n>         full refname (including `refs/...` prefix). This lists\n>         detached HEAD (if present) first, then local branches and\n>         finally remote-tracking branches.\n> +       The keys supported are the same as those in `git for-each-ref`.\n> +       Sort order defaults to the value configured for the `tag.sort`\n\nDid you mean s/tag/branch/?\n\n> +       variable if it exists, or lexicographic order otherwise. See\n> +       linkgit:git-config[1].\n\nExcept for the \"See linkgit:git-config[1]\", isn't this new text mostly\nduplicating what this item already says? When I look at\nDocumentation/git-branch.txt, I see:\n\n    Sort based on the key given. Prefix `-` to sort in descending\n    order of the value. You may use the --sort=<key> option\n    multiple times, in which case the last key becomes the primary\n    key. **The keys supported are the same as those in `git\n    for-each-ref`. Sort order defaults to** sorting based on the\n    full refname (including `refs/...` prefix). This lists\n    detached HEAD (if present) first, then local branches and\n    finally remote-tracking branches.\n\nI added ** to highlight the existing text which this duplicates.\n\n> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\n> @@ -1305,4 +1305,50 @@ test_expect_success 'tracking with unexpected .fetch refspec' '\n> +test_expect_success 'configured committerdate sort' '\n> +       git init sort &&\n> +       (\n> +               cd sort &&\n> +               git config branch.sort committerdate &&\n> +               [...]\n> +       )\n> +'\n> +\n> +test_expect_success 'option override configured sort' '\n> +       (\n> +               cd sort &&\n> +               git branch --sort=refname >actual &&\n\nI would trust this test more if it explicitly configured \"branch.sort\"\nrather than inheriting the value from test(s) above it. That way you\nwouldn't have to worry about someone later inserting a test above this\none which changes or removes the value.\n\n> +               cat >expect <<-\\EOF &&\n> +                 a\n> +               * b\n> +                 c\n> +                 master\n> +               EOF\n> +               test_cmp expect actual\n> +       )\n> +'\n> +\n> +test_expect_success 'invalid sort parameter in configuration' '\n> +       (\n> +               cd sort &&\n> +               git config branch.sort \"v:notvalid\" &&\n> +               test_must_fail git branch\n> +\n> +       )\n> +'\n\nStyle: Lose the unnecessary blank line.\n\nThanks.\n"},{"id":"355818","messageId":"20180816080549.33544-1-samuel.maftoul@gmail.com","threadId":"49131","inReplyTo":"CAPig+cSUy7rFwhmJ1SFHsAjPkoWparfY6wAjV=6kJyUL3SLQUw@mail.gmail.com","subject":"[PATCH] branch: support configuring --sort via .gitconfig","fromName":"","fromEmail":"samuel.maftoul@gmail.com","sentAt":"2018-08-16T08:05:49Z","receivedAt":"2018-08-16T08:06:18Z","isPatch":true,"sender":{"key":"samuel.maftoul@gmail.com","avatar":"https://avatars.githubusercontent.com/u/239203?v=4"},"body":"From: Samuel Maftoul <samuel.maftoul@gmail.com>\n\nAdd support for configuring default sort ordering for git branches. Command\nline option will override this configured value, using the exact same\nsyntax.\n\nSigned-off-by: Samuel Maftoul <samuel.maftoul@gmail.com>\n---\n Documentation/config.txt     |  6 +++++\n Documentation/git-branch.txt |  3 +++\n builtin/branch.c             | 10 +++++++-\n t/t3200-branch.sh            | 47 ++++++++++++++++++++++++++++++++++++\n 4 files changed, 65 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 63365dcf3..1236d1ec9 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1034,6 +1034,12 @@ branch.autoSetupRebase::\n \tbranch to track another branch.\n \tThis option defaults to never.\n \n+branch.sort::\n+\tThis variable controls the sort ordering of branches when displayed by\n+\tlinkgit:git-branch[1]. Without the \"--sort=<value>\" option provided, the\n+\tvalue of this variable will be used as the default.\n+\tSee linkgit:git-for-each-ref[1] field names for valid values.\n+\n branch.<name>.remote::\n \tWhen on branch <name>, it tells 'git fetch' and 'git push'\n \twhich remote to fetch from/push to.  The remote to push to\ndiff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\nindex 1072ca0eb..1be009a35 100644\n--- a/Documentation/git-branch.txt\n+++ b/Documentation/git-branch.txt\n@@ -272,6 +272,9 @@ start-point is either a local or remote-tracking branch.\n \tfull refname (including `refs/...` prefix). This lists\n \tdetached HEAD (if present) first, then local branches and\n \tfinally remote-tracking branches.\n+\tSort order defaults to the value configured for the `branch.sort`\n+\tvariable if it exists, or lexicographic order otherwise. See\n+\tlinkgit:git-config[1].\n \n \n --points-at <object>::\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 4fc55c350..bbd006aab 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -74,6 +74,14 @@ define_list_config_array(color_branch_slots);\n static int git_branch_config(const char *var, const char *value, void *cb)\n {\n \tconst char *slot_name;\n+\tstruct ref_sorting **sorting_tail = (struct ref_sorting **)cb;\n+\n+\tif (!strcmp(var, \"branch.sort\")) {\n+\t\tif (!value)\n+\t\t\treturn config_error_nonbool(var);\n+\t\tparse_ref_sorting(sorting_tail, value);\n+\t\treturn 0;\n+\t}\n \n \tif (starts_with(var, \"column.\"))\n \t\treturn git_column_config(var, value, \"branch\", &colopts);\n@@ -653,7 +661,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \tif (argc == 2 && !strcmp(argv[1], \"-h\"))\n \t\tusage_with_options(builtin_branch_usage, options);\n \n-\tgit_config(git_branch_config, NULL);\n+\tgit_config(git_branch_config, sorting_tail);\n \n \ttrack = git_branch_track;\n \ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex dbca665da..448c93527 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -1305,4 +1305,51 @@ test_expect_success 'tracking with unexpected .fetch refspec' '\n \t)\n '\n \n+test_expect_success 'configured committerdate sort' '\n+\tgit init sort &&\n+\t(\n+\t\tcd sort &&\n+\t\tgit config branch.sort committerdate &&\n+\t\ttest_commit initial &&\n+\t\tgit checkout -b a &&\n+\t\ttest_commit a &&\n+\t\tgit checkout -b c &&\n+\t\ttest_commit c &&\n+\t\tgit checkout -b b &&\n+\t\ttest_commit b &&\n+\t\tgit branch >actual &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\t  master\n+\t\t  a\n+\t\t  c\n+\t\t* b\n+\t\tEOF\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'option override configured sort' '\n+\t(\n+\t\tcd sort &&\n+\t\tgit config branch.sort committerdate &&\n+\t\tgit branch --sort=refname >actual &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\t  a\n+\t\t* b\n+\t\t  c\n+\t\t  master\n+\t\tEOF\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'invalid sort parameter in configuration' '\n+\t(\n+\t\tcd sort &&\n+\t\tgit config branch.sort \"v:notvalid\" &&\n+\t\ttest_must_fail git branch\n+\n+\t)\n+'\n+\n test_done\n-- \n2.18.0\n\n"},{"id":"355825","messageId":"CAPig+cR5cu3cxtpdHsbSSK7xWRpMQh_sv5nvunZrojAOkFeedg@mail.gmail.com","threadId":"49131","inReplyTo":"20180816080549.33544-1-samuel.maftoul@gmail.com","subject":"Re: [PATCH] branch: support configuring --sort via .gitconfig","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-08-16T08:56:07Z","receivedAt":"2018-08-16T08:56:21Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, Aug 16, 2018 at 4:06 AM <samuel.maftoul@gmail.com> wrote:\n> Add support for configuring default sort ordering for git branches. Command\n> line option will override this configured value, using the exact same\n> syntax.\n>\n> Signed-off-by: Samuel Maftoul <samuel.maftoul@gmail.com>\n> ---\n> diff --git a/Documentation/config.txt b/Documentation/config.txt\n> @@ -1034,6 +1034,12 @@ branch.autoSetupRebase::\n> +branch.sort::\n> +       This variable controls the sort ordering of branches when displayed by\n> +       linkgit:git-branch[1]. Without the \"--sort=<value>\" option provided, the\n> +       value of this variable will be used as the default.\n> +       See linkgit:git-for-each-ref[1] field names for valid values.\n\nThanks for adding some information about what values are valid for\nthis config variable.\n\n> diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\n> @@ -272,6 +272,9 @@ start-point is either a local or remote-tracking branch.\n>         full refname (including `refs/...` prefix). This lists\n>         detached HEAD (if present) first, then local branches and\n>         finally remote-tracking branches.\n> +       Sort order defaults to the value configured for the `branch.sort`\n> +       variable if it exists, or lexicographic order otherwise. See\n> +       linkgit:git-config[1].\n\nThis change still has problems pointed out by my earlier review[1].\nThe existing text in git-branch.txt says:\n\n    Sort order defaults to sorting based on the\n    full refname...\n\nWhich is both redundant with the new text you add and seems to say\nsomething rather different.\n\n> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\n> @@ -1305,4 +1305,51 @@ test_expect_success 'tracking with unexpected .fetch refspec' '\n> +test_expect_success 'invalid sort parameter in configuration' '\n> +       (\n> +               cd sort &&\n> +               git config branch.sort \"v:notvalid\" &&\n> +               test_must_fail git branch\n> +\n> +       )\n> +'\n\nSee my earlier review[1] regarding the unnecessary blank line in this new test.\n\n[1]: https://public-inbox.org/git/CAPig+cSUy7rFwhmJ1SFHsAjPkoWparfY6wAjV=6kJyUL3SLQUw@mail.gmail.com/\n"},{"id":"355826","messageId":"20180816093508.37193-1-samuel.maftoul@gmail.com","threadId":"49131","inReplyTo":"CAPig+cR5cu3cxtpdHsbSSK7xWRpMQh_sv5nvunZrojAOkFeedg@mail.gmail.com","subject":"[PATCH] branch: support configuring --sort via .gitconfig","fromName":"","fromEmail":"samuel.maftoul@gmail.com","sentAt":"2018-08-16T09:35:08Z","receivedAt":"2018-08-16T09:35:43Z","isPatch":true,"sender":{"key":"samuel.maftoul@gmail.com","avatar":"https://avatars.githubusercontent.com/u/239203?v=4"},"body":"From: Samuel Maftoul <samuel.maftoul@gmail.com>\n\nAdd support for configuring default sort ordering for git branches. Command\nline option will override this configured value, using the exact same\nsyntax.\n\nSigned-off-by: Samuel Maftoul <samuel.maftoul@gmail.com>\n---\n Documentation/config.txt     |  6 +++++\n Documentation/git-branch.txt |  5 ++--\n builtin/branch.c             | 10 +++++++-\n t/t3200-branch.sh            | 46 ++++++++++++++++++++++++++++++++++++\n 4 files changed, 64 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex fd8d27e76..7f7a50123 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1039,6 +1039,12 @@ branch.autoSetupRebase::\n \tbranch to track another branch.\n \tThis option defaults to never.\n \n+branch.sort::\n+\tThis variable controls the sort ordering of branches when displayed by\n+\tlinkgit:git-branch[1]. Without the \"--sort=<value>\" option provided, the\n+\tvalue of this variable will be used as the default.\n+\tSee linkgit:git-for-each-ref[1] field names for valid values.\n+\n branch.<name>.remote::\n \tWhen on branch <name>, it tells 'git fetch' and 'git push'\n \twhich remote to fetch from/push to.  The remote to push to\ndiff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\nindex 1072ca0eb..9767b2b48 100644\n--- a/Documentation/git-branch.txt\n+++ b/Documentation/git-branch.txt\n@@ -268,10 +268,11 @@ start-point is either a local or remote-tracking branch.\n \torder of the value. You may use the --sort=<key> option\n \tmultiple times, in which case the last key becomes the primary\n \tkey. The keys supported are the same as those in `git\n-\tfor-each-ref`. Sort order defaults to sorting based on the\n+\tfor-each-ref`. Sort order defaults to the value configured for the\n+\t`branch.sort` variable if exists, or to sorting based on the\n \tfull refname (including `refs/...` prefix). This lists\n \tdetached HEAD (if present) first, then local branches and\n-\tfinally remote-tracking branches.\n+\tfinally remote-tracking branches. See linkgit:git-config[1].\n \n \n --points-at <object>::\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 4fc55c350..bbd006aab 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -74,6 +74,14 @@ define_list_config_array(color_branch_slots);\n static int git_branch_config(const char *var, const char *value, void *cb)\n {\n \tconst char *slot_name;\n+\tstruct ref_sorting **sorting_tail = (struct ref_sorting **)cb;\n+\n+\tif (!strcmp(var, \"branch.sort\")) {\n+\t\tif (!value)\n+\t\t\treturn config_error_nonbool(var);\n+\t\tparse_ref_sorting(sorting_tail, value);\n+\t\treturn 0;\n+\t}\n \n \tif (starts_with(var, \"column.\"))\n \t\treturn git_column_config(var, value, \"branch\", &colopts);\n@@ -653,7 +661,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \tif (argc == 2 && !strcmp(argv[1], \"-h\"))\n \t\tusage_with_options(builtin_branch_usage, options);\n \n-\tgit_config(git_branch_config, NULL);\n+\tgit_config(git_branch_config, sorting_tail);\n \n \ttrack = git_branch_track;\n \ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex dbca665da..93f21ab07 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -1305,4 +1305,50 @@ test_expect_success 'tracking with unexpected .fetch refspec' '\n \t)\n '\n \n+test_expect_success 'configured committerdate sort' '\n+\tgit init sort &&\n+\t(\n+\t\tcd sort &&\n+\t\tgit config branch.sort committerdate &&\n+\t\ttest_commit initial &&\n+\t\tgit checkout -b a &&\n+\t\ttest_commit a &&\n+\t\tgit checkout -b c &&\n+\t\ttest_commit c &&\n+\t\tgit checkout -b b &&\n+\t\ttest_commit b &&\n+\t\tgit branch >actual &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\t  master\n+\t\t  a\n+\t\t  c\n+\t\t* b\n+\t\tEOF\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'option override configured sort' '\n+\t(\n+\t\tcd sort &&\n+\t\tgit config branch.sort committerdate &&\n+\t\tgit branch --sort=refname >actual &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\t  a\n+\t\t* b\n+\t\t  c\n+\t\t  master\n+\t\tEOF\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'invalid sort parameter in configuration' '\n+\t(\n+\t\tcd sort &&\n+\t\tgit config branch.sort \"v:notvalid\" &&\n+\t\ttest_must_fail git branch\n+\t)\n+'\n+\n test_done\n-- \n2.18.0\n\n"},{"id":"355863","messageId":"xmqqva8advn2.fsf@gitster-ct.c.googlers.com","threadId":"49131","inReplyTo":"20180816093508.37193-1-samuel.maftoul@gmail.com","subject":"Re: [PATCH] branch: support configuring --sort via .gitconfig","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-08-16T18:16:49Z","receivedAt":"2018-08-16T18:16:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"samuel.maftoul@gmail.com writes:\n\n> From: Samuel Maftoul <samuel.maftoul@gmail.com>\n>\n> Add support for configuring default sort ordering for git branches. Command\n> line option will override this configured value, using the exact same\n> syntax.\n\nUsing the exact same syntax as ...?\n\n> Signed-off-by: Samuel Maftoul <samuel.maftoul@gmail.com>\n> ---\n>  Documentation/config.txt     |  6 +++++\n>  Documentation/git-branch.txt |  5 ++--\n>  builtin/branch.c             | 10 +++++++-\n>  t/t3200-branch.sh            | 46 ++++++++++++++++++++++++++++++++++++\n>  4 files changed, 64 insertions(+), 3 deletions(-)\n>\n> diff --git a/Documentation/config.txt b/Documentation/config.txt\n> index fd8d27e76..7f7a50123 100644\n> --- a/Documentation/config.txt\n> +++ b/Documentation/config.txt\n> @@ -1039,6 +1039,12 @@ branch.autoSetupRebase::\n>  \tbranch to track another branch.\n>  \tThis option defaults to never.\n>  \n> +branch.sort::\n> +\tThis variable controls the sort ordering of branches when displayed by\n> +\tlinkgit:git-branch[1]. Without the \"--sort=<value>\" option provided, the\n> +\tvalue of this variable will be used as the default.\n> +\tSee linkgit:git-for-each-ref[1] field names for valid values.\n\nOK, the answer to the above question is \"same syntax as used for the\nvalue of the `branch.sort` configuration variable\".\n\n> diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\n> index 1072ca0eb..9767b2b48 100644\n> --- a/Documentation/git-branch.txt\n> +++ b/Documentation/git-branch.txt\n> @@ -268,10 +268,11 @@ start-point is either a local or remote-tracking branch.\n>  \torder of the value. You may use the --sort=<key> option\n>  \tmultiple times, in which case the last key becomes the primary\n>  \tkey. The keys supported are the same as those in `git\n> -\tfor-each-ref`. Sort order defaults to sorting based on the\n> +\tfor-each-ref`. Sort order defaults to the value configured for the\n> +\t`branch.sort` variable if exists, or to sorting based on the\n>  \tfull refname (including `refs/...` prefix). This lists\n>  \tdetached HEAD (if present) first, then local branches and\n> -\tfinally remote-tracking branches.\n> +\tfinally remote-tracking branches. See linkgit:git-config[1].\n\nOK.\n\n> diff --git a/builtin/branch.c b/builtin/branch.c\n> index 4fc55c350..bbd006aab 100644\n> --- a/builtin/branch.c\n> +++ b/builtin/branch.c\n> @@ -74,6 +74,14 @@ define_list_config_array(color_branch_slots);\n>  static int git_branch_config(const char *var, const char *value, void *cb)\n>  {\n>  \tconst char *slot_name;\n> +\tstruct ref_sorting **sorting_tail = (struct ref_sorting **)cb;\n> +\n> +\tif (!strcmp(var, \"branch.sort\")) {\n> +\t\tif (!value)\n> +\t\t\treturn config_error_nonbool(var);\n> +\t\tparse_ref_sorting(sorting_tail, value);\n> +\t\treturn 0;\n> +\t}\n\nHmph.  It is unfortunate that \"don't feed me NULL\" check is not in\nparse_ref_sorting() but is in parse_opt_ref_sorting().  But that is\na separate low-hanging fruit.  The code we see here is correct.\n\nWill queue.  Thanks.\n"}]}