git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/4] Add --no-ahead-behind to status
@ 2018-01-08 15:48 Jeff Hostetler
  2018-01-08 15:48 ` [PATCH v4 1/4] stat_tracking_info: return +1 when branches not equal Jeff Hostetler
                   ` (4 more replies)
  0 siblings, 5 replies; 16+ messages in thread
From: Jeff Hostetler @ 2018-01-08 15:48 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, Jeff Hostetler

From: Jeff Hostetler <jeffhost@microsoft.com>

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(-)

-- 
2.9.3


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v4 1/4] stat_tracking_info: return +1 when branches not equal
  2018-01-08 15:48 [PATCH v4 0/4] Add --no-ahead-behind to status Jeff Hostetler
@ 2018-01-08 15:48 ` Jeff Hostetler
  2018-01-08 15:48 ` [PATCH v4 2/4] status: add --[no-]ahead-behind to status and commit for V2 format Jeff Hostetler
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 16+ messages in thread
From: Jeff Hostetler @ 2018-01-08 15:48 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, Jeff Hostetler

From: Jeff Hostetler <jeffhost@microsoft.com>

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.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
---
 ref-filter.c |  8 ++++----
 remote.c     | 34 +++++++++++++++++++++-------------
 remote.h     |  8 +++++++-
 wt-status.c  |  6 ++++--
 4 files changed, 36 insertions(+), 20 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index e728b15..23bcdc4 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -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)
diff --git a/remote.c b/remote.c
index b220f0d..23177f5 100644
--- a/remote.c
+++ b/remote.c
@@ -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;
diff --git a/remote.h b/remote.h
index 2ecf4c8..00932f5 100644
--- a/remote.h
+++ b/remote.h
@@ -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);
diff --git a/wt-status.c b/wt-status.c
index 94e5eba..8f7fdc6 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -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);
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v4 2/4] status: add --[no-]ahead-behind to status and commit for V2 format.
  2018-01-08 15:48 [PATCH v4 0/4] Add --no-ahead-behind to status Jeff Hostetler
  2018-01-08 15:48 ` [PATCH v4 1/4] stat_tracking_info: return +1 when branches not equal Jeff Hostetler
@ 2018-01-08 15:48 ` Jeff Hostetler
  2018-01-08 15:48 ` [PATCH v4 3/4] status: update short status to respect --no-ahead-behind Jeff Hostetler
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 16+ messages in thread
From: Jeff Hostetler @ 2018-01-08 15:48 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, Jeff Hostetler

From: Jeff Hostetler <jeffhost@microsoft.com>

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 <jeffhost@microsoft.com>
---
 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(-)

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.
+
 <pathspec>...::
 	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,
+			 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,
diff --git a/remote.c b/remote.c
index 23177f5..2486afb 100644
--- a/remote.c
+++ b/remote.c
@@ -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 */
diff --git a/remote.h b/remote.h
index 00932f5..27feb63 100644
--- a/remote.h
+++ b/remote.h
@@ -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 */
diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh
index e319fa2..80474e1 100755
--- a/t/t7064-wtstatus-pv2.sh
+++ b/t/t7064-wtstatus-pv2.sh
@@ -390,6 +390,75 @@ test_expect_success 'verify upstream fields in branch header' '
 	)
 '
 
+test_expect_success 'verify --[no-]ahead-behind with V2 format' '
+	git checkout master &&
+	test_when_finished "rm -rf sub_repo" &&
+	git clone . sub_repo &&
+	(
+		## Confirm local master tracks remote master.
+		cd sub_repo &&
+		HUF=$(git rev-parse HEAD) &&
+
+		# Confirm --no-ahead-behind reports traditional branch.ab with 0/0 for equal branches.
+		cat >expect <<-EOF &&
+		# branch.oid $HUF
+		# branch.head master
+		# branch.upstream origin/master
+		# branch.ab +0 -0
+		EOF
+
+		git status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
+		test_cmp expect actual &&
+
+		# Confirm --ahead-behind reports traditional branch.ab with 0/0.
+		cat >expect <<-EOF &&
+		# branch.oid $HUF
+		# branch.head master
+		# branch.upstream origin/master
+		# branch.ab +0 -0
+		EOF
+
+		git status --ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
+		test_cmp expect actual &&
+
+		## Test non-equal ahead/behind.
+		echo xyz >file_xyz &&
+		git add file_xyz &&
+		git commit -m xyz &&
+
+		HUF=$(git rev-parse HEAD) &&
+
+		# Confirm --no-ahead-behind reports branch.ab with ?/? for non-equal branches.
+		cat >expect <<-EOF &&
+		# branch.oid $HUF
+		# branch.head master
+		# branch.upstream origin/master
+		# branch.ab +? -?
+		EOF
+
+		git status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
+		test_cmp expect actual &&
+
+		# Confirm --ahead-behind reports traditional branch.ab with 1/0.
+		cat >expect <<-EOF &&
+		# branch.oid $HUF
+		# branch.head master
+		# branch.upstream origin/master
+		# branch.ab +1 -0
+		EOF
+
+		git status --ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
+		test_cmp expect actual &&
+
+		# Confirm that porcelain=v2 format does not inherit status.aheadBehind value.
+		git -c status.aheadbehind=false status --porcelain=v2 --branch --untracked-files=all >actual &&
+		test_cmp expect actual &&
+
+		git -c status.aheadbehind=true status --porcelain=v2 --branch --untracked-files=all >actual &&
+		test_cmp expect actual
+	)
+'
+
 test_expect_success 'create and add submodule, submodule appears clean (A. S...)' '
 	git checkout master &&
 	git clone . sub_repo &&
diff --git a/wt-status.c b/wt-status.c
index 8f7fdc6..3fcab57 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -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);
+			}
 		}
 	}
 
diff --git a/wt-status.h b/wt-status.h
index 64f4d33..b450b53 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -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 */
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v4 3/4] status: update short status to respect --no-ahead-behind
  2018-01-08 15:48 [PATCH v4 0/4] Add --no-ahead-behind to status Jeff Hostetler
  2018-01-08 15:48 ` [PATCH v4 1/4] stat_tracking_info: return +1 when branches not equal Jeff Hostetler
  2018-01-08 15:48 ` [PATCH v4 2/4] status: add --[no-]ahead-behind to status and commit for V2 format Jeff Hostetler
@ 2018-01-08 15:48 ` Jeff Hostetler
  2018-01-08 15:48 ` [PATCH v4 4/4] status: support --no-ahead-behind in long format Jeff Hostetler
  2018-01-08 19:49 ` [PATCH v4 0/4] Add --no-ahead-behind to status Ben Peart
  4 siblings, 0 replies; 16+ messages in thread
From: Jeff Hostetler @ 2018-01-08 15:48 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, Jeff Hostetler

From: Jeff Hostetler <jeffhost@microsoft.com>

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.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
---
 t/t6040-tracking-info.sh | 26 ++++++++++++++++++++++++++
 wt-status.c              | 11 +++++++----
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh
index 8f17fd9..053dff3 100755
--- a/t/t6040-tracking-info.sh
+++ b/t/t6040-tracking-info.sh
@@ -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
 
diff --git a/wt-status.c b/wt-status.c
index 3fcab57..a4d3470 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -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);
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v4 4/4] status: support --no-ahead-behind in long format
  2018-01-08 15:48 [PATCH v4 0/4] Add --no-ahead-behind to status Jeff Hostetler
                   ` (2 preceding siblings ...)
  2018-01-08 15:48 ` [PATCH v4 3/4] status: update short status to respect --no-ahead-behind Jeff Hostetler
@ 2018-01-08 15:48 ` Jeff Hostetler
  2018-01-08 19:49 ` [PATCH v4 0/4] Add --no-ahead-behind to status Ben Peart
  4 siblings, 0 replies; 16+ messages in thread
From: Jeff Hostetler @ 2018-01-08 15:48 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, Jeff Hostetler

From: Jeff Hostetler <jeffhost@microsoft.com>

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.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
---
 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(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index fc4f8fd..655dac2 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -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);
diff --git a/remote.c b/remote.c
index 2486afb..e668091 100644
--- a/remote.c
+++ b/remote.c
@@ -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",
diff --git a/remote.h b/remote.h
index 27feb63..b2fa5cc 100644
--- a/remote.h
+++ b/remote.h
@@ -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);
 /*
diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh
index 053dff3..febf63f 100755
--- a/t/t6040-tracking-info.sh
+++ b/t/t6040-tracking-info.sh
@@ -173,6 +173,53 @@ test_expect_success 'status.aheadbehind=false status -s -b (diverged from upstre
 '
 
 cat >expect <<\EOF
+On branch b1
+Your branch and 'origin/master' have diverged,
+and have 1 and 1 different commits each, respectively.
+EOF
+
+test_expect_success 'status --long --branch' '
+	(
+		cd test &&
+		git checkout b1 >/dev/null &&
+		git status --long -b | head -3
+	) >actual &&
+	test_i18ncmp expect actual
+'
+
+test_expect_success 'status --long --branch' '
+	(
+		cd test &&
+		git checkout b1 >/dev/null &&
+		git -c status.aheadbehind=true status --long -b | head -3
+	) >actual &&
+	test_i18ncmp expect actual
+'
+
+cat >expect <<\EOF
+On branch b1
+Your branch and 'origin/master' refer to different commits.
+EOF
+
+test_expect_success 'status --long --branch --no-ahead-behind' '
+	(
+		cd test &&
+		git checkout b1 >/dev/null &&
+		git status --long -b --no-ahead-behind | head -2
+	) >actual &&
+	test_i18ncmp expect actual
+'
+
+test_expect_success 'status.aheadbehind=false status --long --branch' '
+	(
+		cd test &&
+		git checkout b1 >/dev/null &&
+		git -c status.aheadbehind=false status --long -b | head -2
+	) >actual &&
+	test_i18ncmp expect actual
+'
+
+cat >expect <<\EOF
 ## b5...brokenbase [gone]
 EOF
 
diff --git a/wt-status.c b/wt-status.c
index a4d3470..98d0501 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -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;
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 0/4] Add --no-ahead-behind to status
  2018-01-08 15:48 [PATCH v4 0/4] Add --no-ahead-behind to status Jeff Hostetler
                   ` (3 preceding siblings ...)
  2018-01-08 15:48 ` [PATCH v4 4/4] status: support --no-ahead-behind in long format Jeff Hostetler
@ 2018-01-08 19:49 ` Ben Peart
  2018-01-08 20:04   ` Jeff Hostetler
  4 siblings, 1 reply; 16+ messages in thread
From: Ben Peart @ 2018-01-08 19:49 UTC (permalink / raw)
  To: Jeff Hostetler, git; +Cc: gitster, peff, Jeff Hostetler



On 1/8/2018 10:48 AM, Jeff Hostetler wrote:
> From: Jeff Hostetler <jeffhost@microsoft.com>
> 
> 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).

> 
> 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(-)
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 0/4] Add --no-ahead-behind to status
  2018-01-08 19:49 ` [PATCH v4 0/4] Add --no-ahead-behind to status Ben Peart
@ 2018-01-08 20:04   ` Jeff Hostetler
  2018-01-09  7:20     ` Jeff King
  0 siblings, 1 reply; 16+ messages in thread
From: Jeff Hostetler @ 2018-01-08 20:04 UTC (permalink / raw)
  To: Ben Peart, git; +Cc: gitster, peff, Jeff Hostetler



On 1/8/2018 2:49 PM, Ben Peart wrote:
> 
> 
> On 1/8/2018 10:48 AM, Jeff Hostetler wrote:
>> From: Jeff Hostetler <jeffhost@microsoft.com>
>>
>> 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 0/4] Add --no-ahead-behind to status
  2018-01-08 20:04   ` Jeff Hostetler
@ 2018-01-09  7:20     ` Jeff King
  2018-01-09 13:15       ` Johannes Schindelin
  0 siblings, 1 reply; 16+ messages in thread
From: Jeff King @ 2018-01-09  7:20 UTC (permalink / raw)
  To: Jeff Hostetler; +Cc: Ben Peart, git, gitster, Jeff Hostetler

On Mon, Jan 08, 2018 at 03:04:20PM -0500, Jeff Hostetler wrote:

> > 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.

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/20171224143318.GC23648@sigill.intra.peff.net/

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 0/4] Add --no-ahead-behind to status
  2018-01-09  7:20     ` Jeff King
@ 2018-01-09 13:15       ` Johannes Schindelin
  2018-01-09 14:29         ` Derrick Stolee
  2018-01-10  7:41         ` Jeff King
  0 siblings, 2 replies; 16+ messages in thread
From: Johannes Schindelin @ 2018-01-09 13:15 UTC (permalink / raw)
  To: Jeff King; +Cc: Jeff Hostetler, Ben Peart, git, gitster, Jeff Hostetler

Hi Peff,

On Tue, 9 Jan 2018, Jeff King wrote:

> On Mon, Jan 08, 2018 at 03:04:20PM -0500, Jeff Hostetler wrote:
> 
> > > 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.
> 
> I like this direction a lot. I had hoped we could say "100+ commits
> ahead",

How about "100+ commits apart" instead?

> 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.

> E.g., the case I mentioned at the bottom of this mail:
> 
>   https://public-inbox.org/git/20171224143318.GC23648@sigill.intra.peff.net/
> 
> 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.

> 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 0/4] Add --no-ahead-behind to status
  2018-01-09 13:15       ` Johannes Schindelin
@ 2018-01-09 14:29         ` Derrick Stolee
  2018-01-09 14:56           ` Jeff Hostetler
                             ` (2 more replies)
  2018-01-10  7:41         ` Jeff King
  1 sibling, 3 replies; 16+ messages in thread
From: Derrick Stolee @ 2018-01-09 14:29 UTC (permalink / raw)
  To: Johannes Schindelin, Jeff King
  Cc: Jeff Hostetler, Ben Peart, git, gitster, Jeff Hostetler

On 1/9/2018 8:15 AM, Johannes Schindelin wrote:
> Hi Peff,
>
> On Tue, 9 Jan 2018, Jeff King wrote:
>
>> On Mon, Jan 08, 2018 at 03:04:20PM -0500, Jeff Hostetler wrote:
>>
>>>> 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.
>> 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.)

>
>> 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.

> 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.
>
>> E.g., the case I mentioned at the bottom of this mail:
>>
>>    https://public-inbox.org/git/20171224143318.GC23648@sigill.intra.peff.net/
>>
>> 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.

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

>> 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 0/4] Add --no-ahead-behind to status
  2018-01-09 14:29         ` Derrick Stolee
@ 2018-01-09 14:56           ` Jeff Hostetler
  2018-01-09 16:48           ` Johannes Schindelin
  2018-01-10  7:47           ` Jeff King
  2 siblings, 0 replies; 16+ messages in thread
From: Jeff Hostetler @ 2018-01-09 14:56 UTC (permalink / raw)
  To: Derrick Stolee, Johannes Schindelin, Jeff King
  Cc: Ben Peart, git, gitster, Jeff Hostetler



On 1/9/2018 9:29 AM, Derrick Stolee wrote:
> On 1/9/2018 8:15 AM, Johannes Schindelin wrote:
>> Hi Peff,
>>
>> On Tue, 9 Jan 2018, Jeff King wrote:
>>
>>> On Mon, Jan 08, 2018 at 03:04:20PM -0500, Jeff Hostetler wrote:
>>>
>>>>> 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.
>>> 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.)
> 
>>
>>> 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.
> 
>> 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.
>>
>>> E.g., the case I mentioned at the bottom of this mail:
>>>
>>>    https://public-inbox.org/git/20171224143318.GC23648@sigill.intra.peff.net/
>>>
>>> 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.
> 
> This is why we cannot _always_ use generation numbers, but they do help in some cases.
> 
>>> 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.

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


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 0/4] Add --no-ahead-behind to status
  2018-01-09 14:29         ` Derrick Stolee
  2018-01-09 14:56           ` Jeff Hostetler
@ 2018-01-09 16:48           ` Johannes Schindelin
  2018-01-10  7:47           ` Jeff King
  2 siblings, 0 replies; 16+ messages in thread
From: Johannes Schindelin @ 2018-01-09 16:48 UTC (permalink / raw)
  To: Derrick Stolee
  Cc: Jeff King, Jeff Hostetler, Ben Peart, git, gitster, Jeff Hostetler

Hi Stolee,

On Tue, 9 Jan 2018, Derrick Stolee wrote:

> On 1/9/2018 8:15 AM, Johannes Schindelin wrote:
> >
> > On Tue, 9 Jan 2018, Jeff King wrote:
> >
> > > 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.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 0/4] Add --no-ahead-behind to status
  2018-01-09 13:15       ` Johannes Schindelin
  2018-01-09 14:29         ` Derrick Stolee
@ 2018-01-10  7:41         ` Jeff King
  1 sibling, 0 replies; 16+ messages in thread
From: Jeff King @ 2018-01-10  7:41 UTC (permalink / raw)
  To: Johannes Schindelin
  Cc: Jeff Hostetler, Ben Peart, git, gitster, Jeff Hostetler

On Tue, Jan 09, 2018 at 02:15:47PM +0100, Johannes Schindelin wrote:

> > 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.

> > 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.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 0/4] Add --no-ahead-behind to status
  2018-01-09 14:29         ` Derrick Stolee
  2018-01-09 14:56           ` Jeff Hostetler
  2018-01-09 16:48           ` Johannes Schindelin
@ 2018-01-10  7:47           ` Jeff King
  2018-01-10 20:22             ` Junio C Hamano
  2 siblings, 1 reply; 16+ messages in thread
From: Jeff King @ 2018-01-10  7:47 UTC (permalink / raw)
  To: Derrick Stolee
  Cc: Johannes Schindelin, Jeff Hostetler, Ben Peart, git, gitster,
	Jeff Hostetler

On Tue, Jan 09, 2018 at 09:29:31AM -0500, Derrick Stolee wrote:

> > > 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 0/4] Add --no-ahead-behind to status
  2018-01-10  7:47           ` Jeff King
@ 2018-01-10 20:22             ` Junio C Hamano
  2018-01-11  9:39               ` Jeff King
  0 siblings, 1 reply; 16+ messages in thread
From: Junio C Hamano @ 2018-01-10 20:22 UTC (permalink / raw)
  To: Jeff King
  Cc: Derrick Stolee, Johannes Schindelin, Jeff Hostetler, Ben Peart,
	git, Jeff Hostetler

Jeff King <peff@peff.net> writes:

> 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)?

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.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 0/4] Add --no-ahead-behind to status
  2018-01-10 20:22             ` Junio C Hamano
@ 2018-01-11  9:39               ` Jeff King
  0 siblings, 0 replies; 16+ messages in thread
From: Jeff King @ 2018-01-11  9:39 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Derrick Stolee, Johannes Schindelin, Jeff Hostetler, Ben Peart,
	git, Jeff Hostetler

On Wed, Jan 10, 2018 at 12:22:10PM -0800, Junio C Hamano wrote:

> Jeff King <peff@peff.net> writes:
> 
> > 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)?
> 
> 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2018-01-11  9:39 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-08 15:48 [PATCH v4 0/4] Add --no-ahead-behind to status Jeff Hostetler
2018-01-08 15:48 ` [PATCH v4 1/4] stat_tracking_info: return +1 when branches not equal Jeff Hostetler
2018-01-08 15:48 ` [PATCH v4 2/4] status: add --[no-]ahead-behind to status and commit for V2 format Jeff Hostetler
2018-01-08 15:48 ` [PATCH v4 3/4] status: update short status to respect --no-ahead-behind Jeff Hostetler
2018-01-08 15:48 ` [PATCH v4 4/4] status: support --no-ahead-behind in long format Jeff Hostetler
2018-01-08 19:49 ` [PATCH v4 0/4] Add --no-ahead-behind to status Ben Peart
2018-01-08 20:04   ` Jeff Hostetler
2018-01-09  7:20     ` Jeff King
2018-01-09 13:15       ` Johannes Schindelin
2018-01-09 14:29         ` Derrick Stolee
2018-01-09 14:56           ` Jeff Hostetler
2018-01-09 16:48           ` Johannes Schindelin
2018-01-10  7:47           ` Jeff King
2018-01-10 20:22             ` Junio C Hamano
2018-01-11  9:39               ` Jeff King
2018-01-10  7:41         ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).