Re: [PATCH v3 2/5] status: add --[no-]ahead-behind to status and commit for V2 format.
On 1/4/2018 5:05 PM, Junio C Hamano wrote: Jeff Hostetler writes: + sti = stat_tracking_info(branch, &nr_ahead, &nr_behind, +&base, s->ahead_behind_flags); if (base) { base = shorten_unambiguous_ref(base, 0); fprintf(s->fp, "# branch.upstream %s%c", base, eol); free((char *)base); - if (ab_info) - fprintf(s->fp, "# branch.ab +%d -%d%c", nr_ahead, nr_behind, eol); + if (sti >= 0) { + if (s->ahead_behind_flags == AHEAD_BEHIND_FULL) + fprintf(s->fp, "# branch.ab +%d -%d%c", + nr_ahead, nr_behind, eol); + else if (s->ahead_behind_flags == AHEAD_BEHIND_QUICK) + fprintf(s->fp, "# branch.equal %s%c", + sti ? "neq" : "eq", eol); This is related to what I said in the review of [1/5], but this arrangement to require the caller to know that _QUICK request results in incomplete information smells like a bit of maintenance hassle. We'd rather allow the caller to tell if it was given incomplete information from the values returned by stat_tracking_info() function (notice the plural "values" here; what is returned in nr_{ahead,behind} also counts). For example, we can keep the (-1 => "no relation", 0 => "identical", 1 => "different") as return values of the function, but have it clear nr_{ahead,behind} when it only knows the two are different but not by how many commits. That way, this step can instead do: ab_info = stat_tracking_info(...); if (base) { ... do the base thing ... if (ab_info > 0) { /* different */ if (nr_ahead || nr_behind) fprintf(... +%d -%d ... nr_ahead, nr_behind, ...); else fprintf(... "neq" ...); } else if (!ab_info) { /* same */ fprintf(... +%d -%d ... nr_ahead, nr_behind, ...); } ... That would allow us to later add different kinds of _QUICK that do not give full information without having to update this consumer with something like - else if (s->ahead_behind_flags == AHEAD_BEHIND_QUICK) + else if (s->ahead_behind_flags == AHEAD_BEHIND_QUICK || +s->ahead_behind_flags == AHEAD_BEHIND_QUICK_DIFFERENTLY) when it happens. Two related tangents. - I do not see why "eq" need to exist at all. Even in _QUICK mode, when you determine that two are identical, you know your branch is ahead and behind by 0 commit each. - A short-format that is easy to parse by machines does not have to be cryptic to humans. s/neq/not-equal/ or something may be an improvement. Thanks. Thanks for the review. Let me update it along the lines suggested here. It felt odd to define the nr_{ahead,behind} as undefined, but short of making them negative or something I wasn't sure what was best. Thanks, Jeff
Re: [PATCH v3 2/5] status: add --[no-]ahead-behind to status and commit for V2 format.
Jeff Hostetler writes: > + sti = stat_tracking_info(branch, &nr_ahead, &nr_behind, > + &base, s->ahead_behind_flags); > if (base) { > base = shorten_unambiguous_ref(base, 0); > fprintf(s->fp, "# branch.upstream %s%c", base, eol); > free((char *)base); > > - if (ab_info) > - fprintf(s->fp, "# branch.ab +%d -%d%c", > nr_ahead, nr_behind, eol); > + if (sti >= 0) { > + if (s->ahead_behind_flags == AHEAD_BEHIND_FULL) > + fprintf(s->fp, "# branch.ab +%d -%d%c", > + nr_ahead, nr_behind, eol); > + else if (s->ahead_behind_flags == > AHEAD_BEHIND_QUICK) > + fprintf(s->fp, "# branch.equal %s%c", > + sti ? "neq" : "eq", eol); This is related to what I said in the review of [1/5], but this arrangement to require the caller to know that _QUICK request results in incomplete information smells like a bit of maintenance hassle. We'd rather allow the caller to tell if it was given incomplete information from the values returned by stat_tracking_info() function (notice the plural "values" here; what is returned in nr_{ahead,behind} also counts). For example, we can keep the (-1 => "no relation", 0 => "identical", 1 => "different") as return values of the function, but have it clear nr_{ahead,behind} when it only knows the two are different but not by how many commits. That way, this step can instead do: ab_info = stat_tracking_info(...); if (base) { ... do the base thing ... if (ab_info > 0) { /* different */ if (nr_ahead || nr_behind) fprintf(... +%d -%d ... nr_ahead, nr_behind, ...); else fprintf(... "neq" ...); } else if (!ab_info) { /* same */ fprintf(... +%d -%d ... nr_ahead, nr_behind, ...); } ... That would allow us to later add different kinds of _QUICK that do not give full information without having to update this consumer with something like - else if (s->ahead_behind_flags == AHEAD_BEHIND_QUICK) + else if (s->ahead_behind_flags == AHEAD_BEHIND_QUICK || +s->ahead_behind_flags == AHEAD_BEHIND_QUICK_DIFFERENTLY) when it happens. Two related tangents. - I do not see why "eq" need to exist at all. Even in _QUICK mode, when you determine that two are identical, you know your branch is ahead and behind by 0 commit each. - A short-format that is easy to parse by machines does not have to be cryptic to humans. s/neq/not-equal/ or something may be an improvement. Thanks.
[PATCH v3 2/5] status: add --[no-]ahead-behind to status and commit for V2 format.
From: Jeff Hostetler Teach "git status" and "git commit" to accept "--no-ahead-behind" and "--ahead-behind" arguments to request quick or full ahead/behind reporting. When "--no-ahead-behind" is given, the existing porcelain V2 line "branch.ab x y" is replaced with a new "branch equal eq|neq" line. This indicates that the branch and its upstream are or are not equal without the expense of computing the full ahead/behind values. Added "status.aheadBehind" config setting. This is only used by non-porcelain format for backward-compatibility. Signed-off-by: Jeff Hostetler --- Documentation/config.txt | 6 Documentation/git-status.txt | 5 builtin/commit.c | 18 +++- remote.c | 2 ++ remote.h | 5 ++-- t/t7064-wtstatus-pv2.sh | 69 wt-status.c | 27 + wt-status.h | 2 ++ 8 files changed, 125 insertions(+), 9 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 9593bfa..affb0d6 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -3035,6 +3035,12 @@ status.branch:: Set to true to enable --branch by default in linkgit:git-status[1]. The option --no-branch takes precedence over this variable. +status.aheadBehind:: + Set to true to enable --ahead-behind and to false to enable + --no-ahead-behind by default in linkgit:git-status[1] for + non-porcelain formats. This setting is ignored by porcelain + formats for backwards compatibility. + status.displayCommentPrefix:: If set to true, linkgit:git-status[1] will insert a comment prefix before each output line (starting with diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt index 9f3a78a..603bf40 100644 --- a/Documentation/git-status.txt +++ b/Documentation/git-status.txt @@ -111,6 +111,11 @@ configuration variable documented in linkgit:git-config[1]. without options are equivalent to 'always' and 'never' respectively. +--ahead-behind:: +--no-ahead-behind:: + Display or do not display detailed ahead/behind counts for the + branch relative to its upstream branch. Defaults to true. + ...:: See the 'pathspec' entry in linkgit:gitglossary[7]. diff --git a/builtin/commit.c b/builtin/commit.c index be370f6..416fe2c 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1109,9 +1109,11 @@ static const char *read_commit_message(const char *name) static struct status_deferred_config { enum wt_status_format status_format; int show_branch; + enum ahead_behind_flags ahead_behind; } status_deferred_config = { STATUS_FORMAT_UNSPECIFIED, - -1 /* unspecified */ + -1, /* unspecified */ + AHEAD_BEHIND_UNSPECIFIED, }; static void finalize_deferred_config(struct wt_status *s) @@ -1137,6 +1139,12 @@ static void finalize_deferred_config(struct wt_status *s) s->show_branch = status_deferred_config.show_branch; if (s->show_branch < 0) s->show_branch = 0; + + if (use_deferred_config && + s->ahead_behind_flags == AHEAD_BEHIND_UNSPECIFIED) + s->ahead_behind_flags = status_deferred_config.ahead_behind; + if (s->ahead_behind_flags == AHEAD_BEHIND_UNSPECIFIED) + s->ahead_behind_flags = AHEAD_BEHIND_FULL; } static int parse_and_validate_options(int argc, const char *argv[], @@ -1297,6 +1305,10 @@ static int git_status_config(const char *k, const char *v, void *cb) status_deferred_config.show_branch = git_config_bool(k, v); return 0; } + if (!strcmp(k, "status.aheadbehind")) { + status_deferred_config.ahead_behind = git_config_bool(k, v); + return 0; + } if (!strcmp(k, "status.showstash")) { s->show_stash = git_config_bool(k, v); return 0; @@ -1351,6 +1363,8 @@ int cmd_status(int argc, const char **argv, const char *prefix) N_("show branch information")), OPT_BOOL(0, "show-stash", &s.show_stash, N_("show stash information")), + OPT_BOOL(0, "ahead-behind", &s.ahead_behind_flags, +N_("compute full ahead/behind values")), { OPTION_CALLBACK, 0, "porcelain", &status_format, N_("version"), N_("machine-readable output"), PARSE_OPT_OPTARG, opt_parse_porcelain }, @@ -1628,6 +1642,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) OPT_SET_INT(0, "short", &status_format, N_("show status concisely"), STATUS_FORMAT_SHORT), OPT_BOOL(0, "branch", &s.show_branch, N_("show branch information")), + OPT_BOOL(0, "ahead-behind", &s.ahead_behind_flags, +