Skip to contentSkip to conversation

Add --no-ahead-behind to status

PATCH Superseded Jeff Hostetler 6 participants 16 messages Jan 8, 2018 – Jan 11, 2018 Documentation

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add --no-ahead-behind to status

From: Jeff Hostetler <[email protected]>

This is version 4 of my patch series to avoid expensive ahead/behind calculations in status. This version removes the last commit containing the experimental config setting. And removes the undefined return values for the nr_ahead/nr_behind arguments as discussed on the mailing list.

This version does not address "git branch -vv", but that requires passing data across the for-each-ref barrier and that seemed beyond the scope of this task.

Jeff Hostetler (4):
stat_tracking_info: return +1 when branches not equal
status: add --[no-]ahead-behind to status and commit for V2 format.
status: update short status to respect --no-ahead-behind
status: support --no-ahead-behind in long format

 Documentation/config.txt     |  6 ++++
 Documentation/git-status.txt |  5 +++
 builtin/checkout.c           |  2 +-
 builtin/commit.c             | 18 ++++++++++-
 ref-filter.c                 |  8 ++---
 remote.c                     | 50 ++++++++++++++++++++----------
 remote.h                     | 12 ++++++--
 t/t6040-tracking-info.sh     | 73 ++++++++++++++++++++++++++++++++++++++++++++
 t/t7064-wtstatus-pv2.sh      | 69 +++++++++++++++++++++++++++++++++++++++++
 wt-status.c                  | 41 +++++++++++++++++--------
 wt-status.h                  |  2 ++
 11 files changed, 250 insertions(+), 36 deletions(-)
Signature · 1 line
2.9.3
#1 lore raw

PATCH v4 1/4 stat_tracking_info: return +1 when branches not equal

From: Jeff Hostetler <[email protected]>

Extend stat_tracking_info() to return +1 when branches are not equal and to take a new "enum ahead_behind_flags" argument to allow skipping the (possibly expensive) ahead/behind computation.

This will be used in the next commit to allow "git status" to avoid full ahead/behind calculations for performance reasons.

---
 ref-filter.c |  8 ++++----
 remote.c     | 34 +++++++++++++++++++++-------------
 remote.h     |  8 +++++++-
 wt-status.c  |  6 ++++--
 4 files changed, 36 insertions(+), 20 deletions(-)
ref-filter.c +4 -4
index e728b15..23bcdc4 100644
@@ -1238,8 +1238,8 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname,
 	if (atom->u.remote_ref.option == RR_REF)
 		*s = show_ref(&atom->u.remote_ref.refname, refname);
 	else if (atom->u.remote_ref.option == RR_TRACK) {
-		if (stat_tracking_info(branch, &num_ours,
-				       &num_theirs, NULL)) {
+		if (stat_tracking_info(branch, &num_ours, &num_theirs,
+				       NULL, AHEAD_BEHIND_FULL) < 0) {
 			*s = xstrdup(msgs.gone);
 		} else if (!num_ours && !num_theirs)
 			*s = "";
@@ -1256,8 +1256,8 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname,
 			free((void *)to_free);
 		}
 	} else if (atom->u.remote_ref.option == RR_TRACKSHORT) {
-		if (stat_tracking_info(branch, &num_ours,
-				       &num_theirs, NULL))
+		if (stat_tracking_info(branch, &num_ours, &num_theirs,
+				       NULL, AHEAD_BEHIND_FULL) < 0)
 			return;
 
 		if (!num_ours && !num_theirs)
remote.c +21 -13
index b220f0d..23177f5 100644
@@ -1977,16 +1977,23 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
 }
 
 /*
- * Compare a branch with its upstream, and save their differences (number
- * of commits) in *num_ours and *num_theirs. The name of the upstream branch
- * (or NULL if no upstream is defined) is returned via *upstream_name, if it
- * is not itself NULL.
+ * Lookup the upstream branch for the given branch and if present, optionally
+ * compute the commit ahead/behind values for the pair.
+ *
+ * If abf is AHEAD_BEHIND_FULL, compute the full ahead/behind and return the
+ * counts in *num_ours and *num_theirs.  If abf is AHEAD_BEHIND_QUICK, skip
+ * the (potentially expensive) a/b computation (*num_ours and *num_theirs are
+ * set to zero).
+ *
+ * The name of the upstream branch (or NULL if no upstream is defined) is
+ * returned via *upstream_name, if it is not itself NULL.
  *
  * Returns -1 if num_ours and num_theirs could not be filled in (e.g., no
- * upstream defined, or ref does not exist), 0 otherwise.
+ * upstream defined, or ref does not exist).  Returns 0 if the commits are
+ * identical.  Returns 1 if commits are different.
  */
 int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
-		       const char **upstream_name)
+		       const char **upstream_name, enum ahead_behind_flags abf)
 {
 	struct object_id oid;
 	struct commit *ours, *theirs;
@@ -2014,11 +2021,13 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
 	if (!ours)
 		return -1;
 
+	*num_theirs = *num_ours = 0;
+
 	/* are we the same? */
-	if (theirs == ours) {
-		*num_theirs = *num_ours = 0;
+	if (theirs == ours)
 		return 0;
-	}
+	if (abf == AHEAD_BEHIND_QUICK)
+		return 1;
 
 	/* Run "rev-list --left-right ours...theirs" internally... */
 	argv_array_push(&argv, ""); /* ignored */
@@ -2034,8 +2043,6 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
 		die("revision walk setup failed");
 
 	/* ... and count the commits on each side. */
-	*num_ours = 0;
-	*num_theirs = 0;
 	while (1) {
 		struct commit *c = get_revision(&revs);
 		if (!c)
@@ -2051,7 +2058,7 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
 	clear_commit_marks(theirs, ALL_REV_FLAGS);
 
 	argv_array_clear(&argv);
-	return 0;
+	return 1;
 }
 
 /*
@@ -2064,7 +2071,8 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
 	char *base;
 	int upstream_is_gone = 0;
 
-	if (stat_tracking_info(branch, &ours, &theirs, &full_base) < 0) {
+	if (stat_tracking_info(branch, &ours, &theirs, &full_base,
+			       AHEAD_BEHIND_FULL) < 0) {
 		if (!full_base)
 			return 0;
 		upstream_is_gone = 1;
remote.h +7 -1
index 2ecf4c8..00932f5 100644
@@ -255,9 +255,15 @@ enum match_refs_flags {
 	MATCH_REFS_FOLLOW_TAGS	= (1 << 3)
 };
 
+/* Flags for --ahead-behind option. */
+enum ahead_behind_flags {
+	AHEAD_BEHIND_QUICK = 0,  /* just eq/neq reporting */
+	AHEAD_BEHIND_FULL  = 1,  /* traditional a/b reporting */
+};
+
 /* Reporting of tracking info */
 int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
-		       const char **upstream_name);
+		       const char **upstream_name, enum ahead_behind_flags abf);
 int format_tracking_info(struct branch *branch, struct strbuf *sb);
 
 struct ref *get_local_heads(void);
wt-status.c +4 -2
index 94e5eba..8f7fdc6 100644
@@ -1791,7 +1791,8 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
 
 	color_fprintf(s->fp, branch_color_local, "%s", branch_name);
 
-	if (stat_tracking_info(branch, &num_ours, &num_theirs, &base) < 0) {
+	if (stat_tracking_info(branch, &num_ours, &num_theirs, &base,
+			       AHEAD_BEHIND_FULL) < 0) {
 		if (!base)
 			goto conclude;
 
@@ -1928,7 +1929,8 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
 		/* Lookup stats on the upstream tracking branch, if set. */
 		branch = branch_get(branch_name);
 		base = NULL;
-		ab_info = (stat_tracking_info(branch, &nr_ahead, &nr_behind, &base) == 0);
+		ab_info = (stat_tracking_info(branch, &nr_ahead, &nr_behind,
+					      &base, AHEAD_BEHIND_FULL) >= 0);
 		if (base) {
 			base = shorten_unambiguous_ref(base, 0);
 			fprintf(s->fp, "# branch.upstream %s%c", base, eol);
Signature · 1 line
2.9.3
#2 lore raw

PATCH v4 2/4 status: add --[no-]ahead-behind to status and commit for V2 format.

In reply to Jeff Hostetler

From: Jeff Hostetler <[email protected]>

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.

---
 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                  | 30 +++++++++++++------
 wt-status.h                  |  2 ++
 8 files changed, 125 insertions(+), 12 deletions(-)
Documentation/config.txt +6 -0
index 9593bfa..affb0d6 100644
@@ -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
Documentation/git-status.txt +5 -0
index 9f3a78a..603bf40 100644
@@ -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.
+
 <pathspec>...::
 	See the 'pathspec' entry in linkgit:gitglossary[7].
 
builtin/commit.c +17 -1
index be370f6..416fe2c 100644
@@ -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,
+			 N_("compute full ahead/behind values")),
 		OPT_SET_INT(0, "porcelain", &status_format,
 			    N_("machine-readable output"), STATUS_FORMAT_PORCELAIN),
 		OPT_SET_INT(0, "long", &status_format,
remote.c +2 -0
index 23177f5..2486afb 100644
@@ -2028,6 +2028,8 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
 		return 0;
 	if (abf == AHEAD_BEHIND_QUICK)
 		return 1;
+	if (abf != AHEAD_BEHIND_FULL)
+		BUG("stat_tracking_info: invalid abf '%d'", abf);
 
 	/* Run "rev-list --left-right ours...theirs" internally... */
 	argv_array_push(&argv, ""); /* ignored */
remote.h +3 -2
index 00932f5..27feb63 100644
@@ -257,8 +257,9 @@ enum match_refs_flags {
 
 /* Flags for --ahead-behind option. */
 enum ahead_behind_flags {
-	AHEAD_BEHIND_QUICK = 0,  /* just eq/neq reporting */
-	AHEAD_BEHIND_FULL  = 1,  /* traditional a/b reporting */
+	AHEAD_BEHIND_UNSPECIFIED = -1,
+	AHEAD_BEHIND_QUICK       =  0,  /* just eq/neq reporting */
+	AHEAD_BEHIND_FULL        =  1,  /* traditional a/b reporting */
 };
 
 /* Reporting of tracking info */
t/t7064-wtstatus-pv2.sh +69 -0

75 lines not on this page · raw message

wt-status.c +21 -9
index 8f7fdc6..3fcab57 100644
@@ -136,6 +136,7 @@ void wt_status_prepare(struct wt_status *s)
 	s->ignored.strdup_strings = 1;
 	s->show_branch = -1;  /* unspecified */
 	s->show_stash = 0;
+	s->ahead_behind_flags = AHEAD_BEHIND_UNSPECIFIED;
 	s->display_comment_prefix = 0;
 }
 
@@ -1878,18 +1879,19 @@ static void wt_porcelain_print(struct wt_status *s)
  *
  *    <upstream> ::= the upstream branch name, when set.
  *
- *       <ahead> ::= integer ahead value, when upstream set
- *                   and the commit is present (not gone).
- *
- *      <behind> ::= integer behind value, when upstream set
- *                   and commit is present.
+ *       <ahead> ::= integer ahead value or '?'.
  *
+ *      <behind> ::= integer behind value or '?'.
  *
  * The end-of-line is defined by the -z flag.
  *
  *                 <eol> ::= NUL when -z,
  *                           LF when NOT -z.
  *
+ * When an upstream is set and present, the 'branch.ab' line will
+ * be printed with the ahead/behind counts for the branch and the
+ * upstream.  When AHEAD_BEHIND_QUICK is requested and the branches
+ * are different, '?' will be substituted for the actual count.
  */
 static void wt_porcelain_v2_print_tracking(struct wt_status *s)
 {
@@ -1929,15 +1931,25 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
 		/* Lookup stats on the upstream tracking branch, if set. */
 		branch = branch_get(branch_name);
 		base = NULL;
-		ab_info = (stat_tracking_info(branch, &nr_ahead, &nr_behind,
-					      &base, AHEAD_BEHIND_FULL) >= 0);
+		ab_info = 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 (ab_info > 0) {
+				/* different */
+				if (nr_ahead || nr_behind)
+					fprintf(s->fp, "# branch.ab +%d -%d%c",
+						nr_ahead, nr_behind, eol);
+				else
+					fprintf(s->fp, "# branch.ab +? -?%c",
+						eol);
+			} else if (!ab_info) {
+				/* same */
+				fprintf(s->fp, "# branch.ab +0 -0%c", eol);
+			}
 		}
 	}
 
wt-status.h +2 -0
index 64f4d33..b450b53 100644
@@ -5,6 +5,7 @@
 #include "string-list.h"
 #include "color.h"
 #include "pathspec.h"
+#include "remote.h"
 
 struct worktree;
 
@@ -80,6 +81,7 @@ struct wt_status {
 	int show_branch;
 	int show_stash;
 	int hints;
+	enum ahead_behind_flags ahead_behind_flags;
 
 	enum wt_status_format status_format;
 	unsigned char sha1_commit[GIT_MAX_RAWSZ]; /* when not Initial */
Signature · 1 line
2.9.3
#3 lore raw

PATCH v4 3/4 status: update short status to respect --no-ahead-behind

In reply to Jeff Hostetler

From: Jeff Hostetler <[email protected]>

Teach "git status --short --branch" to respect "--no-ahead-behind" parameter to skip computing ahead/behind counts for the branch and its upstream and just report '[different]'.

Short status also respect the "status.aheadBehind" config setting.

---
 t/t6040-tracking-info.sh | 26 ++++++++++++++++++++++++++
 wt-status.c              | 11 +++++++----
 2 files changed, 33 insertions(+), 4 deletions(-)
t/t6040-tracking-info.sh +26 -0
index 8f17fd9..053dff3 100755
@@ -147,6 +147,32 @@ test_expect_success 'status -s -b (diverged from upstream)' '
 '
 
 cat >expect <<\EOF
+## b1...origin/master [different]
+EOF
+
+test_expect_success 'status -s -b --no-ahead-behind (diverged from upstream)' '
+	(
+		cd test &&
+		git checkout b1 >/dev/null &&
+		git status -s -b --no-ahead-behind | head -1
+	) >actual &&
+	test_i18ncmp expect actual
+'
+
+cat >expect <<\EOF
+## b1...origin/master [different]
+EOF
+
+test_expect_success 'status.aheadbehind=false status -s -b (diverged from upstream)' '
+	(
+		cd test &&
+		git checkout b1 >/dev/null &&
+		git -c status.aheadbehind=false status -s -b | head -1
+	) >actual &&
+	test_i18ncmp expect actual
+'
+
+cat >expect <<\EOF
 ## b5...brokenbase [gone]
 EOF
 
wt-status.c +7 -4
index 3fcab57..a4d3470 100644
@@ -1766,7 +1766,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
 	const char *base;
 	char *short_base;
 	const char *branch_name;
-	int num_ours, num_theirs;
+	int num_ours, num_theirs, sti;
 	int upstream_is_gone = 0;
 
 	color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "## ");
@@ -1792,8 +1792,9 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
 
 	color_fprintf(s->fp, branch_color_local, "%s", branch_name);
 
-	if (stat_tracking_info(branch, &num_ours, &num_theirs, &base,
-			       AHEAD_BEHIND_FULL) < 0) {
+	sti = stat_tracking_info(branch, &num_ours, &num_theirs, &base,
+				 s->ahead_behind_flags);
+	if (sti < 0) {
 		if (!base)
 			goto conclude;
 
@@ -1805,12 +1806,14 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
 	color_fprintf(s->fp, branch_color_remote, "%s", short_base);
 	free(short_base);
 
-	if (!upstream_is_gone && !num_ours && !num_theirs)
+	if (!upstream_is_gone && !sti)
 		goto conclude;
 
 	color_fprintf(s->fp, header_color, " [");
 	if (upstream_is_gone) {
 		color_fprintf(s->fp, header_color, LABEL(N_("gone")));
+	} else if (s->ahead_behind_flags == AHEAD_BEHIND_QUICK) {
+		color_fprintf(s->fp, header_color, LABEL(N_("different")));
 	} else if (!num_ours) {
 		color_fprintf(s->fp, header_color, LABEL(N_("behind ")));
 		color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
Signature · 1 line
2.9.3
#4 lore raw

PATCH v4 4/4 status: support --no-ahead-behind in long format

In reply to Jeff Hostetler

From: Jeff Hostetler <[email protected]>

Teach long (normal) status format to respect the --no-ahead-behind parameter and skip the possibly expensive ahead/behind computation between the branch and the upstream.

Long status also respects "status.aheadBehind" config setting.

---
 builtin/checkout.c       |  2 +-
 remote.c                 | 18 +++++++++++++-----
 remote.h                 |  3 ++-
 t/t6040-tracking-info.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 wt-status.c              |  2 +-
 5 files changed, 64 insertions(+), 8 deletions(-)
builtin/checkout.c +1 -1
index fc4f8fd..655dac2 100644
@@ -605,7 +605,7 @@ static void report_tracking(struct branch_info *new)
 	struct strbuf sb = STRBUF_INIT;
 	struct branch *branch = branch_get(new->name);
 
-	if (!format_tracking_info(branch, &sb))
+	if (!format_tracking_info(branch, &sb, AHEAD_BEHIND_FULL))
 		return;
 	fputs(sb.buf, stdout);
 	strbuf_release(&sb);
remote.c +13 -5
index 2486afb..e668091 100644
@@ -2066,15 +2066,16 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
 /*
  * Return true when there is anything to report, otherwise false.
  */
-int format_tracking_info(struct branch *branch, struct strbuf *sb)
+int format_tracking_info(struct branch *branch, struct strbuf *sb,
+			 enum ahead_behind_flags abf)
 {
-	int ours, theirs;
+	int ours, theirs, sti;
 	const char *full_base;
 	char *base;
 	int upstream_is_gone = 0;
 
-	if (stat_tracking_info(branch, &ours, &theirs, &full_base,
-			       AHEAD_BEHIND_FULL) < 0) {
+	sti = stat_tracking_info(branch, &ours, &theirs, &full_base, abf);
+	if (sti < 0) {
 		if (!full_base)
 			return 0;
 		upstream_is_gone = 1;
@@ -2088,10 +2089,17 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
 		if (advice_status_hints)
 			strbuf_addstr(sb,
 				_("  (use \"git branch --unset-upstream\" to fixup)\n"));
-	} else if (!ours && !theirs) {
+	} else if (!sti) {
 		strbuf_addf(sb,
 			_("Your branch is up to date with '%s'.\n"),
 			base);
+	} else if (abf == AHEAD_BEHIND_QUICK) {
+		strbuf_addf(sb,
+			    _("Your branch and '%s' refer to different commits.\n"),
+			    base);
+		if (advice_status_hints)
+			strbuf_addf(sb, _("  (use \"%s\" for details)\n"),
+				    "git status --ahead-behind");
 	} else if (!theirs) {
 		strbuf_addf(sb,
 			Q_("Your branch is ahead of '%s' by %d commit.\n",
remote.h +2 -1
index 27feb63..b2fa5cc 100644
@@ -265,7 +265,8 @@ enum ahead_behind_flags {
 /* Reporting of tracking info */
 int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
 		       const char **upstream_name, enum ahead_behind_flags abf);
-int format_tracking_info(struct branch *branch, struct strbuf *sb);
+int format_tracking_info(struct branch *branch, struct strbuf *sb,
+			 enum ahead_behind_flags abf);
 
 struct ref *get_local_heads(void);
 /*
t/t6040-tracking-info.sh +47 -0

53 lines not on this page · raw message

wt-status.c +1 -1
index a4d3470..98d0501 100644
@@ -1006,7 +1006,7 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
 	if (!skip_prefix(s->branch, "refs/heads/", &branch_name))
 		return;
 	branch = branch_get(branch_name);
-	if (!format_tracking_info(branch, &sb))
+	if (!format_tracking_info(branch, &sb, s->ahead_behind_flags))
 		return;
 
 	i = 0;
Signature · 1 line
2.9.3
#5 lore raw
In reply to Jeff Hostetler
Quoted 6 lines · Jeff Hostetler

From: Jeff Hostetler <[email protected]>

This is version 4 of my patch series to avoid expensive ahead/behind calculations in status. This version removes the last commit containing the experimental config setting. And removes the undefined return values for the nr_ahead/nr_behind arguments as discussed on the mailing list.

While I like the simplicity of just turning this off completely, I do wonder if we could come up with a better user experience. For example, could we somehow limit the time spent computing the before/after and if it exceeds that limit, drop back to saying they are "different" rather than computing the exact number of commits before/after.

I was thinking about something similar to the logic we use today about whether to start reporting progress on other long commands. That would mean you could still get the ahead/behind values if you aren't that far behind but would only get "different" if that calculation gets too expensive (which implies the actual value isn't going to be all that helpful anyway).

Quoted 24 lines

This version does not address "git branch -vv", but that requires passing data across the for-each-ref barrier and that seemed beyond the scope of this task.

Jeff Hostetler (4):
stat_tracking_info: return +1 when branches not equal
status: add --[no-]ahead-behind to status and commit for V2 format.
status: update short status to respect --no-ahead-behind
status: support --no-ahead-behind in long format

  Documentation/config.txt     |  6 ++++
  Documentation/git-status.txt |  5 +++
  builtin/checkout.c           |  2 +-
  builtin/commit.c             | 18 ++++++++++-
  ref-filter.c                 |  8 ++---
  remote.c                     | 50 ++++++++++++++++++++----------
  remote.h                     | 12 ++++++--
  t/t6040-tracking-info.sh     | 73 ++++++++++++++++++++++++++++++++++++++++++++
  t/t7064-wtstatus-pv2.sh      | 69 +++++++++++++++++++++++++++++++++++++++++
  wt-status.c                  | 41 +++++++++++++++++--------
  wt-status.h                  |  2 ++
  11 files changed, 250 insertions(+), 36 deletions(-)
#6 lore raw
Quoted 5 lines · Ben Peart
Quoted 2 lines · Jeff Hostetler

From: Jeff Hostetler <[email protected]>

Quoted 8 lines
Quoted 4 lines

This is version 4 of my patch series to avoid expensive ahead/behind calculations in status.  This version removes the last commit containing the experimental config setting.  And removes the undefined return values for the nr_ahead/nr_behind arguments as discussed on the mailing list.

While I like the simplicity of just turning this off completely, I do wonder if we could come up with a better user experience.  For example, could we somehow limit the time spent computing the before/after and if it exceeds that limit, drop back to saying they are "different" rather than computing the exact number of commits before/after.

I was thinking about something similar to the logic we use today about whether to start reporting progress on other long commands. That would mean you could still get the ahead/behind values if you aren't that far behind but would only get "different" if that calculation gets too expensive (which implies the actual value isn't going to be all that helpful anyway).

After a off-line conversation with the others I'm going to look into a version that is limited to n commits rather than be completely on or off. I think if you are for example less than 100 a/b then those numbers have value; if you are past n, then they have much less value.

I'd rather do it by a fixed limit than by time to ensure that output is predictable on graph shape and not on system load.

Jeff

#7 lore raw
Quoted 7 lines · Jeff Hostetler
Quoted 6 lines

I was thinking about something similar to the logic we use today about whether to start reporting progress on other long commands. That would mean you could still get the ahead/behind values if you aren't that far behind but would only get "different" if that calculation gets too expensive (which implies the actual value isn't going to be all that helpful anyway).

Quoted 7 lines

After a off-line conversation with the others I'm going to look into a version that is limited to n commits rather than be completely on or off. I think if you are for example less than 100 a/b then those numbers have value; if you are past n, then they have much less value.

I'd rather do it by a fixed limit than by time to ensure that output is predictable on graph shape and not on system load.

I like this direction a lot. I had hoped we could say "100+ commits ahead", but I don't think we can do so accurately without generation numbers. E.g., the case I mentioned at the bottom of this mail:

https://public-inbox.org/git/[email protected]/

I haven't thought too hard on it, but I suspect with generation numbers you could bound it and at least say "100+ ahead" or "100+ behind". But I don't think you can approximate both ahead and behind together without finding the actual merge base.

But even still, finding small answers quickly and accurately and punting to "really far, I didn't bother to compute it" on the big ones would be an improvement over always punting.

-Peff

#8 lore raw

Hi Peff,

Quoted 14 lines · Jeff King
Quoted 12 lines · Jeff Hostetler
Quoted 6 lines

I was thinking about something similar to the logic we use today about whether to start reporting progress on other long commands. That would mean you could still get the ahead/behind values if you aren't that far behind but would only get "different" if that calculation gets too expensive (which implies the actual value isn't going to be all that helpful anyway).

After a off-line conversation with the others I'm going to look into a version that is limited to n commits rather than be completely on or off. I think if you are for example less than 100 a/b then those numbers have value; if you are past n, then they have much less value.

Quoted 5 lines
Quoted 2 lines

I'd rather do it by a fixed limit than by time to ensure that output is predictable on graph shape and not on system load.

I like this direction a lot. I had hoped we could say "100+ commits ahead",

How about "100+ commits apart" instead?

Quoted 1 line

but I don't think we can do so accurately without generation numbers.

Even with generation numbers, it is not possible to say whether two given commits reflect diverging branches or have an ancestor-descendant relationship (or in graph speak: whether they are comparable).

It could potentially make it possible to cut off the commit traversal, but I do not even see how that would be possible.

The only thing you could say for sure is that two different commits with the same generation number are for sure "uncomparable", i.e. reflect diverging branches.

Quoted 6 lines

E.g., the case I mentioned at the bottom of this mail:

https://public-inbox.org/git/[email protected]/

I haven't thought too hard on it, but I suspect with generation numbers you could bound it and at least say "100+ ahead" or "100+ behind".

If you have walked 100 commits and still have not found a merge base, there is no telling whether one start point is the ancestor of the other. All you can say is that there are more than 100 commits in the "difference".

You would not even be able to say that the *shortest* path between those two start points is longer than 100 commits, you can construct pathological DAGs pretty easily.

Even if you had generation numbers, and one commit's generation number was, say, 17, and the other one's was 17,171, you could not necessarily assume that the 17 one is the ancestor of the 17,171 one, all you can say that it is not possible the other way round.

Quoted 6 lines

But I don't think you can approximate both ahead and behind together without finding the actual merge base.

But even still, finding small answers quickly and accurately and punting to "really far, I didn't bother to compute it" on the big ones would be an improvement over always punting.

Indeed. The longer I think about it, the more I like the "100+ commits apart" idea.

Ciao,
Dscho

#9 lore raw
Quoted 17 lines · Johannes Schindelin

Hi Peff,

Quoted 13 lines · Jeff King
Quoted 11 lines · Jeff Hostetler
Quoted 6 lines

I was thinking about something similar to the logic we use today about whether to start reporting progress on other long commands. That would mean you could still get the ahead/behind values if you aren't that far behind but would only get "different" if that calculation gets too expensive (which implies the actual value isn't going to be all that helpful anyway).

After a off-line conversation with the others I'm going to look into a version that is limited to n commits rather than be completely on or off. I think if you are for example less than 100 a/b then those numbers have value; if you are past n, then they have much less value.

Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

I'd rather do it by a fixed limit than by time to ensure that output is predictable on graph shape and not on system load.

I like this direction a lot. I had hoped we could say "100+ commits ahead",

How about "100+ commits apart" instead?

Unfortunately, we can _never_ guarantee more than 1 commit ahead/behind unless we walk to the merge base (or have generation numbers). For example, suppose the 101st commit in each history has a parent that in the recent history of the other commit. (There must be merge commits to make this work without creating cycles, but the ahead/behind counts could be much lower than the number of walked commits.)

Quoted 5 lines
Quoted 2 lines

but I don't think we can do so accurately without generation numbers.

Even with generation numbers, it is not possible to say whether two given commits reflect diverging branches or have an ancestor-descendant relationship (or in graph speak: whether they are comparable).

If you walk commits using a priority queue where the priority is the generation number, then you can know that you have walked all reachable commits with generation greater than X, so you know among those commits which are comparable or not.

For this to work accurately, you must walk from both tips to a generation lower than each. It does not help the case where one branch is 100,000+ commits ahead, where most of those commits have higher generation number than the behind commit.

Quoted 18 lines

It could potentially make it possible to cut off the commit traversal, but I do not even see how that would be possible.

The only thing you could say for sure is that two different commits with the same generation number are for sure "uncomparable", i.e. reflect diverging branches.

Quoted 6 lines

E.g., the case I mentioned at the bottom of this mail:

   https://public-inbox.org/git/[email protected]/

I haven't thought too hard on it, but I suspect with generation numbers you could bound it and at least say "100+ ahead" or "100+ behind".

If you have walked 100 commits and still have not found a merge base, there is no telling whether one start point is the ancestor of the other. All you can say is that there are more than 100 commits in the "difference".

Quoted 8 lines

You would not even be able to say that the *shortest* path between those two start points is longer than 100 commits, you can construct pathological DAGs pretty easily.

Even if you had generation numbers, and one commit's generation number was, say, 17, and the other one's was 17,171, you could not necessarily assume that the 17 one is the ancestor of the 17,171 one, all you can say that it is not possible the other way round.

This is why we cannot _always_ use generation numbers, but they do help in some cases.

Quoted 9 lines
Quoted 6 lines

But I don't think you can approximate both ahead and behind together without finding the actual merge base.

But even still, finding small answers quickly and accurately and punting to "really far, I didn't bother to compute it" on the big ones would be an improvement over always punting.

Indeed. The longer I think about it, the more I like the "100+ commits apart" idea.

Again, I strongly suggest we drop this approach because it will be more pain than it is worth.

Thanks,
-Stolee

#10 lore raw
Quoted 68 lines · Derrick Stolee
Quoted 17 lines · Johannes Schindelin

Hi Peff,

Quoted 13 lines · Jeff King
Quoted 11 lines · Jeff Hostetler
Quoted 6 lines

I was thinking about something similar to the logic we use today about whether to start reporting progress on other long commands. That would mean you could still get the ahead/behind values if you aren't that far behind but would only get "different" if that calculation gets too expensive (which implies the actual value isn't going to be all that helpful anyway).

After a off-line conversation with the others I'm going to look into a version that is limited to n commits rather than be completely on or off.  I think if you are for example less than 100 a/b then those numbers have value; if you are past n, then they have much less value.

Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

I'd rather do it by a fixed limit than by time to ensure that output is predictable on graph shape and not on system load.

I like this direction a lot. I had hoped we could say "100+ commits ahead",

How about "100+ commits apart" instead?

Unfortunately, we can _never_ guarantee more than 1 commit ahead/behind unless we walk to the merge base (or have generation numbers). For example, suppose the 101st commit in each history has a parent that in the recent history of the other commit. (There must be merge commits to make this work without creating cycles, but the ahead/behind counts could be much lower than the number of walked commits.)

Quoted 5 lines
Quoted 2 lines

but I don't think we can do so accurately without generation numbers.

Even with generation numbers, it is not possible to say whether two given commits reflect diverging branches or have an ancestor-descendant relationship (or in graph speak: whether they are comparable).

If you walk commits using a priority queue where the priority is the generation number, then you can know that you have walked all reachable commits with generation greater than X, so you know among those commits which are comparable or not.

For this to work accurately, you must walk from both tips to a generation lower than each. It does not help the case where one branch is 100,000+ commits ahead, where most of those commits have higher generation number than the behind commit.

Quoted 18 lines

It could potentially make it possible to cut off the commit traversal, but I do not even see how that would be possible.

The only thing you could say for sure is that two different commits with the same generation number are for sure "uncomparable", i.e. reflect diverging branches.

Quoted 6 lines

E.g., the case I mentioned at the bottom of this mail:

   https://public-inbox.org/git/[email protected]/

I haven't thought too hard on it, but I suspect with generation numbers you could bound it and at least say "100+ ahead" or "100+ behind".

If you have walked 100 commits and still have not found a merge base, there is no telling whether one start point is the ancestor of the other. All you can say is that there are more than 100 commits in the "difference".

Quoted 8 lines

You would not even be able to say that the *shortest* path between those two start points is longer than 100 commits, you can construct pathological DAGs pretty easily.

Even if you had generation numbers, and one commit's generation number was, say, 17, and the other one's was 17,171, you could not necessarily assume that the 17 one is the ancestor of the 17,171 one, all you can say that it is not possible the other way round.

This is why we cannot _always_ use generation numbers, but they do help in some cases.

Quoted 3 lines
Quoted 3 lines

But I don't think you can approximate both ahead and behind together without finding the actual merge base.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

But even still, finding small answers quickly and accurately and punting to "really far, I didn't bother to compute it" on the big ones would be an improvement over always punting.

Indeed. The longer I think about it, the more I like the "100+ commits apart" idea.

Again, I strongly suggest we drop this approach because it will be more pain than it is worth.

Good comments all. Thanks!
I will leave the patch series as it is with the existing on/off setting and call it quits.

Thanks,
Jeff

#11 lore raw
In reply to Derrick Stolee

Hi Stolee,

Quoted 11 lines · Derrick Stolee
Quoted 10 lines · Johannes Schindelin
Quoted 6 lines · Jeff King

But I don't think you can approximate both ahead and behind together without finding the actual merge base.

But even still, finding small answers quickly and accurately and punting to "really far, I didn't bother to compute it" on the big ones would be an improvement over always punting.

Quoted 5 lines
Quoted 2 lines

Indeed. The longer I think about it, the more I like the "100+ commits apart" idea.

Again, I strongly suggest we drop this approach because it will be more pain than it is worth.

So what you are saying is if there is a commit graph with *heavy* clock skew, you might overestimate how many commits apart the tips are.

I say that this is striking the balance between correctness and usability on the *wrong* side.

Sure, it might be wrong if your commit graph suffers heavily from clock skew. In most cases, you still get a pretty darn useful hint where you're at.

The alternative would be *not* to show any useful hint in most cases, i.e. when you did not find all merge bases within <N> commits. I would really hate it if Git spent so much time and did not even give me a hint. Totally unsatisfying user experience.

Ciao,
Johannes

#12 lore raw
In reply to Derrick Stolee
Quoted 9 lines · Derrick Stolee
Quoted 6 lines
Quoted 3 lines

But even still, finding small answers quickly and accurately and punting to "really far, I didn't bother to compute it" on the big ones would be an improvement over always punting.

Indeed. The longer I think about it, the more I like the "100+ commits apart" idea.

Again, I strongly suggest we drop this approach because it will be more pain than it is worth.

To be clear, which approach are we talking about? I think there are three options:

1. The user tells us not to bother computing real ahead/behind values. We always say "same" or "not the same".

2. The user tells us not to bother computing ahead/behind values with more effort than N. After traversing N commits without getting an answer, we say "same" or "not the same". But we may sometimes give a real answer if we found it within N.

3. The user tells us not to spend more effort than N. After traversing N commits we try to make some partial statement based on generations (or commit timestamps as a proxy for them).

I agree that (3) is probably not going to be useful enough in the general case to merit the implementation effort and confusion. But is there anything wrong with (2)?

-Peff

#13 lore raw
Quoted 11 lines · Jeff King

To be clear, which approach are we talking about? I think there are three options:

1. The user tells us not to bother computing real ahead/behind values. We always say "same" or "not the same".

2. The user tells us not to bother computing ahead/behind values with more effort than N. After traversing N commits without getting an answer, we say "same" or "not the same". But we may sometimes give a real answer if we found it within N.

Quoted 7 lines

3. The user tells us not to spend more effort than N. After traversing N commits we try to make some partial statement based on generations (or commit timestamps as a proxy for them).

I agree that (3) is probably not going to be useful enough in the general case to merit the implementation effort and confusion. But is there anything wrong with (2)?

I agree (3) would not be all that interesting. Offhand I do not see a problem with (2). I think with "real" in your "sometimes give a real answer" you meant to say that we limit our answers to just one three ("same", "not the same", "ahead/behind by exactly N/M") and I think it is a good choice that is easy to explain.

We might be able to say things other than these three, namely, "ahead by no more than N, behind by no more than M", but I do not know if that is useful or merely more confusing than it's worth.

#14 lore raw
Quoted 21 lines · Junio C Hamano
Quoted 11 lines · Jeff King

To be clear, which approach are we talking about? I think there are three options:

1. The user tells us not to bother computing real ahead/behind values. We always say "same" or "not the same".

2. The user tells us not to bother computing ahead/behind values with more effort than N. After traversing N commits without getting an answer, we say "same" or "not the same". But we may sometimes give a real answer if we found it within N.

Quoted 7 lines

3. The user tells us not to spend more effort than N. After traversing N commits we try to make some partial statement based on generations (or commit timestamps as a proxy for them).

I agree that (3) is probably not going to be useful enough in the general case to merit the implementation effort and confusion. But is there anything wrong with (2)?

Quoted 5 lines

I agree (3) would not be all that interesting. Offhand I do not see a problem with (2). I think with "real" in your "sometimes give a real answer" you meant to say that we limit our answers to just one three ("same", "not the same", "ahead/behind by exactly N/M") and I think it is a good choice that is easy to explain.

Yes, exactly. That's a better way of saying it.

-Peff

#15 lore raw
In reply to Johannes Schindelin
Quoted 4 lines · Johannes Schindelin
Quoted 2 lines

I like this direction a lot. I had hoped we could say "100+ commits ahead",

How about "100+ commits apart" instead?

Yeah, that is probably more accurate for the general case.

Quoted 6 lines
Quoted 1 line

but I don't think we can do so accurately without generation numbers.

Even with generation numbers, it is not possible to say whether two given commits reflect diverging branches or have an ancestor-descendant relationship (or in graph speak: whether they are comparable).

Quoted 6 lines

It could potentially make it possible to cut off the commit traversal, but I do not even see how that would be possible.

The only thing you could say for sure is that two different commits with the same generation number are for sure "uncomparable", i.e. reflect diverging branches.

I think sometimes we can say more. E.g., imagine we have two commits, A and B, with generation numbers N and N+1000. We walk back 100 commits deep from B and end up at a commit around N+900. We know that there are at least 100 commits in B that are not in A (the 100 we walked, which we know cannot be ancestors of A because of their generation numbers). That's true even if there is no ancestry relationship between the two commits at all.

But we cannot say in that case how many (if any) commits are in A but not B. So we can say "100+ commits ahead, unknown behind" (or if the two generation numbers are reversed, we can say "unknown ahead, 100+ commits behind).

In the more general case, we could actually walk _past_ generation N, and end up at N-25 or similar. There we can't say anything intelligent about the commits with generations <= N. But we could say something like "there are 75 commits in B that cannot be in A" (note that it's probably _not_ actually 75; it's however many we walked until we crossed N).

So that was what I was getting at in the earlier mail. We can sometimes give a partial answer. But I think giving that partial answer is likely to be more confusing than useful to a user, because there are a lot of caveats about how much we know for a given situation.

And I think from what you wrote below that you probably agree with that (that we can make a few claims, but not enough to really be useful).

-Peff