{"thread":{"id":"51334","subject":"[PATCH 0/3] git-status: create config for ahead/behind calculation","startedAt":"2019-06-18T20:21:29Z","lastAt":"2019-06-29T17:30:07Z","messageCount":7,"participants":["Derrick Stolee via GitGitGadget","Jeff Hostetler via GitGitGadget","Junio C Hamano","Jeff Hostetler","SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"377449","messageId":"pull.272.git.gitgitgadget@gmail.com","threadId":"51334","inReplyTo":null,"subject":"[PATCH 0/3] git-status: create config for ahead/behind calculation","fromName":"Derrick Stolee via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-06-18T20:21:25Z","receivedAt":"2019-06-18T20:21:29Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"The git status builtin includes a calculation for how far the local ref is\nahead or behind the remote tracking branch. This check can be expensive, so\nwe already have a --[no-]ahead-behind command-line option.\n\nThis series adds two bits of functionality to the feature:\n\n 1. Add a new status.aheadBehind config setting.\n    \n    \n 2. Add a new advice.statusAheadBehind config setting associated with a\n    warning that suggests status.aheadBehind when the calculation takes a\n    long time.\n    \n    \n\nWe have been running with these commits in microsoft/git for a while now.\nThe only change I made in adapting Jeff's commits was to add the advice\nconfig documentation.\n\nThe status.aheadBehind config setting is a candidate to be added to the\nproposed \"large repo\" meta-config setting previously discussed [1]. I'm\nputting this out for independent review as it is much smaller compared to\nthe potential of that series.\n\nThanks, -Stolee\n\n[1] https://public-inbox.org/git/pull.254.git.gitgitgadget@gmail.com/\n\nJeff Hostetler (3):\n  status: add status.aheadbehind setting\n  status: warn when a/b calculation takes too long\n  status: ignore status.aheadbehind in porcelain formats\n\n Documentation/config/advice.txt |  6 ++++++\n Documentation/config/status.txt |  5 +++++\n advice.c                        |  2 ++\n advice.h                        |  1 +\n builtin/commit.c                | 19 ++++++++++++++++++-\n t/t6040-tracking-info.sh        | 31 +++++++++++++++++++++++++++++++\n t/t7064-wtstatus-pv2.sh         |  8 ++++++++\n wt-status.c                     | 17 +++++++++++++++++\n 8 files changed, 88 insertions(+), 1 deletion(-)\n\n\nbase-commit: b697d92f56511e804b8ba20ccbe7bdc85dc66810\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-272%2Fderrickstolee%2Fstatus-ahead-behind-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-272/derrickstolee/status-ahead-behind-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/272\n-- \ngitgitgadget\n"},{"id":"377450","messageId":"2f0f2a2df9410947b985d83a924d2549d62bb65f.1560889284.git.gitgitgadget@gmail.com","threadId":"51334","inReplyTo":"pull.272.git.gitgitgadget@gmail.com","subject":"[PATCH 1/3] status: add status.aheadbehind setting","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-06-18T20:21:25Z","receivedAt":"2019-06-18T20:21:30Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nThe --[no-]ahead-behind option was introduced in fd9b544a\n(status: add --[no-]ahead-behind to status and commit for V2\nformat, 2018-01-09). This is a necessary change of behavior\nin repos where the remote tracking branches can move very\nquickly ahead of the local branches. However, users need to\nremember to provide the command-line argument every time.\n\nAdd a new \"status.aheadBehind\" config setting to change the\ndefault behavior of all git status formats.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\nSigned-off-by: Derrick Stolee <dstolee@microsoft.com>\n---\n Documentation/config/status.txt |  5 +++++\n builtin/commit.c                | 17 ++++++++++++++++-\n t/t6040-tracking-info.sh        | 31 +++++++++++++++++++++++++++++++\n t/t7064-wtstatus-pv2.sh         |  4 ++++\n 4 files changed, 56 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/config/status.txt b/Documentation/config/status.txt\nindex ed72fa7dae..0fc704ab80 100644\n--- a/Documentation/config/status.txt\n+++ b/Documentation/config/status.txt\n@@ -12,6 +12,11 @@ status.branch::\n \tSet to true to enable --branch by default in linkgit:git-status[1].\n \tThe option --no-branch takes precedence over this variable.\n \n+status.aheadBehind::\n+\tSet to true to enable `--ahead-behind` and false to enable\n+\t`--no-ahead-behind` by default in linkgit:git-status[1] for\n+\tnon-porcelain status formats.  Defaults to true.\n+\n status.displayCommentPrefix::\n \tIf set to true, linkgit:git-status[1] will insert a comment\n \tprefix before each output line (starting with\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 1c9e8e2228..71305073ad 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1078,9 +1078,11 @@ static const char *read_commit_message(const char *name)\n static struct status_deferred_config {\n \tenum wt_status_format status_format;\n \tint show_branch;\n+\tenum ahead_behind_flags ahead_behind;\n } status_deferred_config = {\n \tSTATUS_FORMAT_UNSPECIFIED,\n-\t-1 /* unspecified */\n+\t-1, /* unspecified */\n+\tAHEAD_BEHIND_UNSPECIFIED,\n };\n \n static void finalize_deferred_config(struct wt_status *s)\n@@ -1107,6 +1109,15 @@ static void finalize_deferred_config(struct wt_status *s)\n \tif (s->show_branch < 0)\n \t\ts->show_branch = 0;\n \n+\t/*\n+\t * If the user did not give a \"--[no]-ahead-behind\" command\n+\t * line argument, then we inherit the a/b config setting.\n+\t * If is not set, then we inherit _FULL for backwards\n+\t * compatibility.\n+\t */\n+\tif (s->ahead_behind_flags == AHEAD_BEHIND_UNSPECIFIED)\n+\t\ts->ahead_behind_flags = status_deferred_config.ahead_behind;\n+\n \tif (s->ahead_behind_flags == AHEAD_BEHIND_UNSPECIFIED)\n \t\ts->ahead_behind_flags = AHEAD_BEHIND_FULL;\n }\n@@ -1246,6 +1257,10 @@ static int git_status_config(const char *k, const char *v, void *cb)\n \t\tstatus_deferred_config.show_branch = git_config_bool(k, v);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(k, \"status.aheadbehind\")) {\n+\t\tstatus_deferred_config.ahead_behind = git_config_bool(k, v);\n+\t\treturn 0;\n+\t}\n \tif (!strcmp(k, \"status.showstash\")) {\n \t\ts->show_stash = git_config_bool(k, v);\n \t\treturn 0;\ndiff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh\nindex 716283b274..febf63f28a 100755\n--- a/t/t6040-tracking-info.sh\n+++ b/t/t6040-tracking-info.sh\n@@ -159,6 +159,19 @@ test_expect_success 'status -s -b --no-ahead-behind (diverged from upstream)' '\n \ttest_i18ncmp expect actual\n '\n \n+cat >expect <<\\EOF\n+## b1...origin/master [different]\n+EOF\n+\n+test_expect_success 'status.aheadbehind=false status -s -b (diverged from upstream)' '\n+\t(\n+\t\tcd test &&\n+\t\tgit checkout b1 >/dev/null &&\n+\t\tgit -c status.aheadbehind=false status -s -b | head -1\n+\t) >actual &&\n+\ttest_i18ncmp expect actual\n+'\n+\n cat >expect <<\\EOF\n On branch b1\n Your branch and 'origin/master' have diverged,\n@@ -174,6 +187,15 @@ test_expect_success 'status --long --branch' '\n \ttest_i18ncmp expect actual\n '\n \n+test_expect_success 'status --long --branch' '\n+\t(\n+\t\tcd test &&\n+\t\tgit checkout b1 >/dev/null &&\n+\t\tgit -c status.aheadbehind=true status --long -b | head -3\n+\t) >actual &&\n+\ttest_i18ncmp expect actual\n+'\n+\n cat >expect <<\\EOF\n On branch b1\n Your branch and 'origin/master' refer to different commits.\n@@ -188,6 +210,15 @@ test_expect_success 'status --long --branch --no-ahead-behind' '\n \ttest_i18ncmp expect actual\n '\n \n+test_expect_success 'status.aheadbehind=false status --long --branch' '\n+\t(\n+\t\tcd test &&\n+\t\tgit checkout b1 >/dev/null &&\n+\t\tgit -c status.aheadbehind=false status --long -b | head -2\n+\t) >actual &&\n+\ttest_i18ncmp expect actual\n+'\n+\n cat >expect <<\\EOF\n ## b5...brokenbase [gone]\n EOF\ndiff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh\nindex 11eccc231a..a0baf6e8b0 100755\n--- a/t/t7064-wtstatus-pv2.sh\n+++ b/t/t7064-wtstatus-pv2.sh\n@@ -436,6 +436,10 @@ test_expect_success 'verify --[no-]ahead-behind with V2 format' '\n \t\tgit status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&\n \t\ttest_cmp expect actual &&\n \n+\t\t# Confirmat that \"status.aheadbehind\" works on V2 format.\n+\t\tgit -c status.aheadbehind=false status --porcelain=v2 --branch --untracked-files=all >actual &&\n+\t\ttest_cmp expect actual &&\n+\n \t\t# Confirm --ahead-behind reports traditional branch.ab with 1/0.\n \t\tcat >expect <<-EOF &&\n \t\t# branch.oid $HUF\n-- \ngitgitgadget\n\n"},{"id":"377451","messageId":"feea3f6ef12b22364e3f9790b64484be96c48193.1560889284.git.gitgitgadget@gmail.com","threadId":"51334","inReplyTo":"pull.272.git.gitgitgadget@gmail.com","subject":"[PATCH 3/3] status: ignore status.aheadbehind in porcelain formats","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-06-18T20:21:28Z","receivedAt":"2019-06-18T20:21:32Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nTeach porcelain V[12] formats to ignore the status.aheadbehind\nconfig setting. They only respect the --[no-]ahead-behind\ncommand line argument.  This is for backwards compatibility\nwith existing scripts.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\nSigned-off-by: Derrick Stolee <dstolee@microsoft.com>\n---\n builtin/commit.c        | 10 ++++++----\n t/t7064-wtstatus-pv2.sh | 12 ++++++++----\n 2 files changed, 14 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 71305073ad..79cb238d87 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1111,11 +1111,13 @@ static void finalize_deferred_config(struct wt_status *s)\n \n \t/*\n \t * If the user did not give a \"--[no]-ahead-behind\" command\n-\t * line argument, then we inherit the a/b config setting.\n-\t * If is not set, then we inherit _FULL for backwards\n-\t * compatibility.\n+\t * line argument *AND* we will print in a human-readable format\n+\t * (short, long etc.) then we inherit from the status.aheadbehind\n+\t * config setting.  In all other cases (and porcelain V[12] formats\n+\t * in particular), we inherit _FULL for backwards compatibility.\n \t */\n-\tif (s->ahead_behind_flags == AHEAD_BEHIND_UNSPECIFIED)\n+\tif (use_deferred_config &&\n+\t    s->ahead_behind_flags == AHEAD_BEHIND_UNSPECIFIED)\n \t\ts->ahead_behind_flags = status_deferred_config.ahead_behind;\n \n \tif (s->ahead_behind_flags == AHEAD_BEHIND_UNSPECIFIED)\ndiff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh\nindex a0baf6e8b0..537787e598 100755\n--- a/t/t7064-wtstatus-pv2.sh\n+++ b/t/t7064-wtstatus-pv2.sh\n@@ -436,10 +436,6 @@ test_expect_success 'verify --[no-]ahead-behind with V2 format' '\n \t\tgit status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&\n \t\ttest_cmp expect actual &&\n \n-\t\t# Confirmat that \"status.aheadbehind\" works on V2 format.\n-\t\tgit -c status.aheadbehind=false status --porcelain=v2 --branch --untracked-files=all >actual &&\n-\t\ttest_cmp expect actual &&\n-\n \t\t# Confirm --ahead-behind reports traditional branch.ab with 1/0.\n \t\tcat >expect <<-EOF &&\n \t\t# branch.oid $HUF\n@@ -449,6 +445,14 @@ test_expect_success 'verify --[no-]ahead-behind with V2 format' '\n \t\tEOF\n \n \t\tgit status --ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&\n+\t\ttest_cmp expect actual &&\n+\n+\t\t# Confirm that \"status.aheadbehind\" DOES NOT work on V2 format.\n+\t\tgit -c status.aheadbehind=false status --porcelain=v2 --branch --untracked-files=all >actual &&\n+\t\ttest_cmp expect actual &&\n+\n+\t\t# Confirm that \"status.aheadbehind\" DOES NOT work on V2 format.\n+\t\tgit -c status.aheadbehind=true status --porcelain=v2 --branch --untracked-files=all >actual &&\n \t\ttest_cmp expect actual\n \t)\n '\n-- \ngitgitgadget\n"},{"id":"377452","messageId":"c1056545b617b89e881f5991beb2fe0d860de740.1560889284.git.gitgitgadget@gmail.com","threadId":"51334","inReplyTo":"pull.272.git.gitgitgadget@gmail.com","subject":"[PATCH 2/3] status: warn when a/b calculation takes too long","fromName":"Jeff Hostetler via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-06-18T20:21:27Z","receivedAt":"2019-06-18T20:21:32Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nThe ahead/behind calculation in 'git status' can be slow in some\ncases. Users may not realize that there are ways to avoid this\ncomputation, especially if they are not using the information.\n\nAdd a warning that appears if this calculation takes more than\ntwo seconds. The warning can be disabled through the new config\nsetting advice.statusAheadBehind.\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\nSigned-off-by: Derrick Stolee <dstolee@microsoft.com>\n---\n Documentation/config/advice.txt |  6 ++++++\n advice.c                        |  2 ++\n advice.h                        |  1 +\n wt-status.c                     | 17 +++++++++++++++++\n 4 files changed, 26 insertions(+)\n\ndiff --git a/Documentation/config/advice.txt b/Documentation/config/advice.txt\nindex ec4f6ae658..4bc5b4c742 100644\n--- a/Documentation/config/advice.txt\n+++ b/Documentation/config/advice.txt\n@@ -37,6 +37,12 @@ advice.*::\n \t\twe can still suggest that the user push to either\n \t\trefs/heads/* or refs/tags/* based on the type of the\n \t\tsource object.\n+\tstatusAheadBehind::\n+\t\tShown when linkgit:git-status[1] computes the ahead/behind\n+\t\tcounts for a local ref compared to its remote tracking ref,\n+\t\tand that calculation takes longer than expected. Will not\n+\t\tappear if `status.aheadBehind` is false or the option\n+\t\t`--no-ahead-behind` is given.\n \tstatusHints::\n \t\tShow directions on how to proceed from the current\n \t\tstate in the output of linkgit:git-status[1], in\ndiff --git a/advice.c b/advice.c\nindex ce5f374ecd..54f8dea30c 100644\n--- a/advice.c\n+++ b/advice.c\n@@ -12,6 +12,7 @@ int advice_push_needs_force = 1;\n int advice_push_unqualified_ref_name = 1;\n int advice_status_hints = 1;\n int advice_status_u_option = 1;\n+int advice_status_ahead_behind_warning = 1;\n int advice_commit_before_merge = 1;\n int advice_reset_quiet_warning = 1;\n int advice_resolve_conflict = 1;\n@@ -68,6 +69,7 @@ static struct {\n \t{ \"pushUnqualifiedRefName\", &advice_push_unqualified_ref_name },\n \t{ \"statusHints\", &advice_status_hints },\n \t{ \"statusUoption\", &advice_status_u_option },\n+\t{ \"statusAheadBehindWarning\", &advice_status_ahead_behind_warning },\n \t{ \"commitBeforeMerge\", &advice_commit_before_merge },\n \t{ \"resetQuiet\", &advice_reset_quiet_warning },\n \t{ \"resolveConflict\", &advice_resolve_conflict },\ndiff --git a/advice.h b/advice.h\nindex e50f02cdfe..c86de9b9b8 100644\n--- a/advice.h\n+++ b/advice.h\n@@ -12,6 +12,7 @@ extern int advice_push_needs_force;\n extern int advice_push_unqualified_ref_name;\n extern int advice_status_hints;\n extern int advice_status_u_option;\n+extern int advice_status_ahead_behind_warning;\n extern int advice_commit_before_merge;\n extern int advice_reset_quiet_warning;\n extern int advice_resolve_conflict;\ndiff --git a/wt-status.c b/wt-status.c\nindex d2a1bec226..c94d43879a 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -19,6 +19,8 @@\n #include \"lockfile.h\"\n #include \"sequencer.h\"\n \n+#define AB_DELAY_WARNING_IN_MS (2 * 1000)\n+\n static const char cut_line[] =\n \"------------------------ >8 ------------------------\\n\";\n \n@@ -1085,14 +1087,29 @@ static void wt_longstatus_print_tracking(struct wt_status *s)\n \tstruct branch *branch;\n \tchar comment_line_string[3];\n \tint i;\n+\tuint64_t t_begin = 0;\n \n \tassert(s->branch && !s->is_initial);\n \tif (!skip_prefix(s->branch, \"refs/heads/\", &branch_name))\n \t\treturn;\n \tbranch = branch_get(branch_name);\n+\n+\tt_begin = getnanotime();\n+\n \tif (!format_tracking_info(branch, &sb, s->ahead_behind_flags))\n \t\treturn;\n \n+\tif (advice_status_ahead_behind_warning &&\n+\t    s->ahead_behind_flags == AHEAD_BEHIND_FULL) {\n+\t\tuint64_t t_delta_in_ms = (getnanotime() - t_begin) / 1000000;\n+\t\tif (t_delta_in_ms > AB_DELAY_WARNING_IN_MS) {\n+\t\t\tstrbuf_addf(&sb, _(\"\\n\"\n+\t\t\t\t\t   \"It took %.2f seconds to compute the branch ahead/behind values.\\n\"\n+\t\t\t\t\t   \"You can use '--no-ahead-behind' to avoid this.\\n\"),\n+\t\t\t\t    t_delta_in_ms / 1000.0);\n+\t\t}\n+\t}\n+\n \ti = 0;\n \tif (s->display_comment_prefix) {\n \t\tcomment_line_string[i++] = comment_line_char;\n-- \ngitgitgadget\n\n"},{"id":"377752","messageId":"xmqqzhmakidw.fsf@gitster-ct.c.googlers.com","threadId":"51334","inReplyTo":"2f0f2a2df9410947b985d83a924d2549d62bb65f.1560889284.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 1/3] status: add status.aheadbehind setting","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-06-21T16:33:47Z","receivedAt":"2019-06-21T16:33:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Jeff Hostetler via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Jeff Hostetler <jeffhost@microsoft.com>\n>\n> The --[no-]ahead-behind option was introduced in fd9b544a\n> (status: add --[no-]ahead-behind to status and commit for V2\n> format, 2018-01-09). This is a necessary change of behavior\n> in repos where the remote tracking branches can move very\n> quickly ahead of the local branches. However, users need to\n> remember to provide the command-line argument every time.\n>\n> Add a new \"status.aheadBehind\" config setting to change the\n> default behavior of all git status formats.\n>\n> Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>\n> ---\n>  Documentation/config/status.txt |  5 +++++\n>  builtin/commit.c                | 17 ++++++++++++++++-\n>  t/t6040-tracking-info.sh        | 31 +++++++++++++++++++++++++++++++\n>  t/t7064-wtstatus-pv2.sh         |  4 ++++\n>  4 files changed, 56 insertions(+), 1 deletion(-)\n>\n> diff --git a/Documentation/config/status.txt b/Documentation/config/status.txt\n> index ed72fa7dae..0fc704ab80 100644\n> --- a/Documentation/config/status.txt\n> +++ b/Documentation/config/status.txt\n> @@ -12,6 +12,11 @@ status.branch::\n>  \tSet to true to enable --branch by default in linkgit:git-status[1].\n>  \tThe option --no-branch takes precedence over this variable.\n>  \n> +status.aheadBehind::\n> +\tSet to true to enable `--ahead-behind` and false to enable\n> +\t`--no-ahead-behind` by default in linkgit:git-status[1] for\n> +\tnon-porcelain status formats.  Defaults to true.\n\nSensible.\n\n> @@ -1078,9 +1078,11 @@ static const char *read_commit_message(const char *name)\n>  static struct status_deferred_config {\n>  \tenum wt_status_format status_format;\n>  \tint show_branch;\n> +\tenum ahead_behind_flags ahead_behind;\n>  } status_deferred_config = {\n>  \tSTATUS_FORMAT_UNSPECIFIED,\n> -\t-1 /* unspecified */\n> +\t-1, /* unspecified */\n> +\tAHEAD_BEHIND_UNSPECIFIED,\n\nThis obviously is not a problem introduced by this patch, but is\nthere a plan to extend this beyond a boolean?\n\nOtherwise, a separate enum is way overkill.  Naming the field so\nthat it is clear it is either true or false (e.g.  perhaps call it\n\"ahead_behind_detailed\" as the current \"QUICK\" is merely \"are they\nequal?\" which corresponds to \"false\", and \"FULL\" is to show the\ndetailed info), and then use the usual \"-1 is unspecified, 0 and 1\nare usual bools\" convention would be more appropriate.\n\n"},{"id":"378079","messageId":"c2b26b9d-827f-58b7-1938-023c246b7d9b@jeffhostetler.com","threadId":"51334","inReplyTo":"xmqqzhmakidw.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH 1/3] status: add status.aheadbehind setting","fromName":"Jeff Hostetler","fromEmail":"git@jeffhostetler.com","sentAt":"2019-06-26T20:02:17Z","receivedAt":"2019-06-26T20:02:21Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"\n\nOn 6/21/2019 12:33 PM, Junio C Hamano wrote:\n> \"Jeff Hostetler via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n> \n>> From: Jeff Hostetler <jeffhost@microsoft.com>\n>>\n>> The --[no-]ahead-behind option was introduced in fd9b544a\n>> (status: add --[no-]ahead-behind to status and commit for V2\n>> format, 2018-01-09). This is a necessary change of behavior\n>> in repos where the remote tracking branches can move very\n>> quickly ahead of the local branches. However, users need to\n>> remember to provide the command-line argument every time.\n>>\n>> Add a new \"status.aheadBehind\" config setting to change the\n>> default behavior of all git status formats.\n>>\n>> Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n>> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>\n>> ---\n>>   Documentation/config/status.txt |  5 +++++\n>>   builtin/commit.c                | 17 ++++++++++++++++-\n>>   t/t6040-tracking-info.sh        | 31 +++++++++++++++++++++++++++++++\n>>   t/t7064-wtstatus-pv2.sh         |  4 ++++\n>>   4 files changed, 56 insertions(+), 1 deletion(-)\n>>\n>> diff --git a/Documentation/config/status.txt b/Documentation/config/status.txt\n>> index ed72fa7dae..0fc704ab80 100644\n>> --- a/Documentation/config/status.txt\n>> +++ b/Documentation/config/status.txt\n>> @@ -12,6 +12,11 @@ status.branch::\n>>   \tSet to true to enable --branch by default in linkgit:git-status[1].\n>>   \tThe option --no-branch takes precedence over this variable.\n>>   \n>> +status.aheadBehind::\n>> +\tSet to true to enable `--ahead-behind` and false to enable\n>> +\t`--no-ahead-behind` by default in linkgit:git-status[1] for\n>> +\tnon-porcelain status formats.  Defaults to true.\n> \n> Sensible.\n> \n>> @@ -1078,9 +1078,11 @@ static const char *read_commit_message(const char *name)\n>>   static struct status_deferred_config {\n>>   \tenum wt_status_format status_format;\n>>   \tint show_branch;\n>> +\tenum ahead_behind_flags ahead_behind;\n>>   } status_deferred_config = {\n>>   \tSTATUS_FORMAT_UNSPECIFIED,\n>> -\t-1 /* unspecified */\n>> +\t-1, /* unspecified */\n>> +\tAHEAD_BEHIND_UNSPECIFIED,\n> \n> This obviously is not a problem introduced by this patch, but is\n> there a plan to extend this beyond a boolean?\n> \n> Otherwise, a separate enum is way overkill.  Naming the field so\n> that it is clear it is either true or false (e.g.  perhaps call it\n> \"ahead_behind_detailed\" as the current \"QUICK\" is merely \"are they\n> equal?\" which corresponds to \"false\", and \"FULL\" is to show the\n> detailed info), and then use the usual \"-1 is unspecified, 0 and 1\n> are usual bools\" convention would be more appropriate.\n> \n\nAt one point[1] we talked about having an intermediate option\nto try N or less commits before giving up.  The enum would let\nus add that case if we wanted it.\n\nSo far, I've not heard any complaints with just having QUICK or FULL\nfrom our Windows developers, so adding a 3rd mode hasn't been a\npriority.  But the enum is here if we do decide to do so.\n\nJeff\n\n[1] \nhttps://public-inbox.org/git/20180111093943.GC9190@sigill.intra.peff.net/\n"},{"id":"378331","messageId":"20190629173001.GI21574@szeder.dev","threadId":"51334","inReplyTo":"2f0f2a2df9410947b985d83a924d2549d62bb65f.1560889284.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 1/3] status: add status.aheadbehind setting","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-06-29T17:30:01Z","receivedAt":"2019-06-29T17:30:07Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Tue, Jun 18, 2019 at 01:21:25PM -0700, Jeff Hostetler via GitGitGadget wrote:\n> diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh\n> index 716283b274..febf63f28a 100755\n> --- a/t/t6040-tracking-info.sh\n> +++ b/t/t6040-tracking-info.sh\n> @@ -159,6 +159,19 @@ test_expect_success 'status -s -b --no-ahead-behind (diverged from upstream)' '\n>  \ttest_i18ncmp expect actual\n>  '\n>  \n> +cat >expect <<\\EOF\n> +## b1...origin/master [different]\n> +EOF\n> +\n> +test_expect_success 'status.aheadbehind=false status -s -b (diverged from upstream)' '\n> +\t(\n> +\t\tcd test &&\n> +\t\tgit checkout b1 >/dev/null &&\n> +\t\tgit -c status.aheadbehind=false status -s -b | head -1\n\nThese tests specifically check 'git status', but the pipe hides its\nexit code.  Please use an intermediate file instead.\n\n> +\t) >actual &&\n\nI found it odd to save the output of a whole subshell and redirect\n'git checkout's stdout to /dev/null to prevent it from itnerfering\nwith the stdout of the subshell, instead of saving only the stdout of\nthe command the test focuses on.\n\n> +\ttest_i18ncmp expect actual\n> +'\n> +\n>  cat >expect <<\\EOF\n>  On branch b1\n>  Your branch and 'origin/master' have diverged,\n> @@ -174,6 +187,15 @@ test_expect_success 'status --long --branch' '\n>  \ttest_i18ncmp expect actual\n>  '\n>  \n> +test_expect_success 'status --long --branch' '\n> +\t(\n> +\t\tcd test &&\n> +\t\tgit checkout b1 >/dev/null &&\n> +\t\tgit -c status.aheadbehind=true status --long -b | head -3\n> +\t) >actual &&\n> +\ttest_i18ncmp expect actual\n> +'\n> +\n>  cat >expect <<\\EOF\n>  On branch b1\n>  Your branch and 'origin/master' refer to different commits.\n> @@ -188,6 +210,15 @@ test_expect_success 'status --long --branch --no-ahead-behind' '\n>  \ttest_i18ncmp expect actual\n>  '\n>  \n> +test_expect_success 'status.aheadbehind=false status --long --branch' '\n> +\t(\n> +\t\tcd test &&\n> +\t\tgit checkout b1 >/dev/null &&\n> +\t\tgit -c status.aheadbehind=false status --long -b | head -2\n> +\t) >actual &&\n> +\ttest_i18ncmp expect actual\n> +'\n> +\n>  cat >expect <<\\EOF\n>  ## b5...brokenbase [gone]\n>  EOF\n"}]}