Skip to contentSkip to conversation

Your branch is ahead of the tracked remote branch 'origin/master' by 50 commits.

OT In review Ingo Molnar 14 participants 28 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

i recently switched to 1.5.6.1.89.gd5446 and i'm getting this:

Switched to branch "master"
Your branch is ahead of the tracked remote branch 'origin/master' by 50 commits.

it's a very useful detail! It's especially useful when two branches diverge in a non-trivial way.

I used to have ad-hoc scripts to discover this in the past:

earth4:~/tip> tip-compare-remote

 master                        : differs from remote (-50 commits)
 tip                           : differs from remote (-1 commits)
 x86/ptrace                    : differs from remote (-1 commits)
 x86/unify-setup               : differs from remote (-2 commits)
 x86/xen-64bit                 : differs from remote (-1 commits)

but having a reminder at checkout time is even better (and faster as well). Kudos.

Ingo

#1 lore raw
Quoted 10 lines · Ingo Molnar

i recently switched to 1.5.6.1.89.gd5446 and i'm getting this:

Switched to branch "master"
Your branch is ahead of the tracked remote branch 'origin/master' by 50 commits.

it's a very useful detail! It's especially useful when two branches diverge in a non-trivial way.
...
but having a reminder at checkout time is even better (and faster as well). Kudos.

Thanks for a rare positive usability feedback. When I started reading your message, I almost expected that I'd hear you say "I am getting this useless cruft and it wastes extra cycles."

Somebody must have had a very bright idea that day in late February this year.

#2 lore raw
Quoted 13 lines · Junio C Hamano
Quoted 10 lines · Ingo Molnar

i recently switched to 1.5.6.1.89.gd5446 and i'm getting this:

Switched to branch "master"
Your branch is ahead of the tracked remote branch 'origin/master' by 50 commits.

it's a very useful detail! It's especially useful when two branches diverge in a non-trivial way.
...
but having a reminder at checkout time is even better (and faster as well). Kudos.

Quoted 3 lines

Thanks for a rare positive usability feedback. When I started reading your message, I almost expected that I'd hear you say "I am getting this useless cruft and it wastes extra cycles."

Git usability is certainly very good. (And what matters even more to me than absolute usability, Git's usability is improving in a monotonic way.)

[ You normally only hear from me if i find one of those rare outliers
that confuse me somewhere. So by reading my feedback you must be getting an impression of problems only - that is far from the truth :) ]

Quoted 2 lines

Somebody must have had a very bright idea that day in late February this year.

:)

There's a small detail i was thinking about: is there a way to get this extra output without actually switching branches? Right now i do this:

earth4:~/tip> git-checkout tip; git-checkout master
Checking out files: 100% (2437/2437), done.
Switched to branch "tip"
Switched to branch "master"
Your branch is ahead of the tracked remote branch 'origin/master' by 50 commits.

(Which is an admitted lame solution but the best i could figure.)

Also, and let me hijack this thread, i sometimes feel adventurous and try out git/pu for kicks. I tried it two days ago and it was quite OK, with some fallout:

- the git-dash changes broke half of our scripts around git. (We've got about 50 tip-* scripts around various git details, about 2200 lines).

I did a mass changeover:

   31 files changed, 150 insertions(+), 150 deletions(-)

... and that broke things too - see the two fixes below. I can understand your desire for a git-dash-less world though, but it's causing some pain :-) Also, i kept typoing "git-" commands all the time so i switched back to git/master. Maybe there should be a transition period where the dash scripts warn if used interactively? Dunno.

[ and there's also a git-rerere Heisenbug i have been fighting with a
lot with git-1.5.5. It's quite hard to reproduce and unfortunately i cannot create a reproducer: but it resulted in git-rerere confusing conflict resolutions and putting arch/x86/kernel/process_64.c postimage entry into the entry for arch/x86/kernel/process_32.c's postimage file, corrupting the integration run on the _next_ run.

Was there a bug in this area fixed recently that would show up with such symptoms? The weirdness first showed up when i did a git-rerere after having done a git-add arch/x86/kernel/process_64.c, git-rerere printed that it added a new resolution for arch/x86/kernel/process_32.c. ]

and i like this warning at the end of master/pu make install:

!! You have installed git-* commands to new gitexecdir. !! Old version git-* commands still remain in bindir. !! Mixing two versions of Git will lead to problems. !! Please remove old version commands in bindir now.

that's an easily overlooked detail.

Ingo

--------------->
commit e87616175691dd7154cad049aae2b1bc1385bb7a

Author: Ingo Molnar <[email protected]>
Date:   Mon Jun 30 09:29:36 2008 +0200

- fix more git-dash fallout

.tip/bin/tip-backup +1 -1
index edd7991..682d68d 100755
@@ -7,7 +7,7 @@ check_master
 echo "backing up the full -tip repo ..."
 mkdir -p ~/tip-backups || exit -1
 
-FILE=~/tip-backups/tip-git $(get_date_for_tag).tar.bz2
+FILE=~/tip-backups/tip-git-$(get_date_for_tag).tar.bz2
 
 tar cjf $FILE .git || exit -1
 

commit 1bcce26cf0ba00ea62c051772f66d3e1c616e165

Author: H. Peter Anvin <[email protected]>
Date:   Fri Jun 27 17:05:59 2008 -0700

tip-sync-remote: quote multiword commands in variables

When assigning a multiword command to a variable, it needs to be quoted.

.tip/bin/tip-sync-remote +2 -2
index 6421e55..aeeb883 100755
@@ -65,9 +65,9 @@ do
     then
 	echo "Branch "$B" has local modifications"
 	echo "Rebasing local modifications to remote"
-	CMD=git rebase
+	CMD='git rebase'
     else
-	CMD=git merge
+	CMD='git merge'
     fi
 
     $CMD origin/$B || {
#3 lore raw
Quoted 6 lines · Ingo Molnar

!! You have installed git-* commands to new gitexecdir. !! Old version git-* commands still remain in bindir. !! Mixing two versions of Git will lead to problems. !! Please remove old version commands in bindir now.

that's an easily overlooked detail.

There is a 10-lines-length note about this in RelNotes, but I think removing the old version is a task of the package manager. At least till the git Makefile does not have an 'uninstall' target.

#4 lore raw
Quoted 11 lines · Miklos Vajna
Quoted 6 lines · Ingo Molnar

!! You have installed git-* commands to new gitexecdir. !! Old version git-* commands still remain in bindir. !! Mixing two versions of Git will lead to problems. !! Please remove old version commands in bindir now.

that's an easily overlooked detail.

There is a 10-lines-length note about this in RelNotes, but I think removing the old version is a task of the package manager. At least till the git Makefile does not have an 'uninstall' target.

random (likely stupid) idea: perhaps git could use ... a separate Git repo to track gitexecdir installations in $HOME/bin/? That could be tagged appropriately so you'd always know what to uninstall and whether there are clashes or incompatibilities.

[ Oh, and i could switch between git versions without having to rebuild
;-) ]

Ingo

#5 lore raw
Quoted 2 lines · Ingo Molnar

[ Oh, and i could switch between git versions without having to rebuild
;-) ]

I remember about a mail from Junio where he wrote he has a lot of versions installed under ~/git/git-version. So usually he has git from next as default and he can try ~/git/git-1.5.4/git if he want 1.5.4, etc.

#6 lore raw
Quoted 8 lines · Miklos Vajna
Quoted 2 lines · Ingo Molnar

[ Oh, and i could switch between git versions without having to rebuild
;-) ]

I remember about a mail from Junio where he wrote he has a lot of versions installed under ~/git/git-version. So usually he has git from next as default and he can try ~/git/git-1.5.4/git if he want 1.5.4, etc.

Yup.

I have $HOME/git-active/bin on my $PATH and then these:

lrwxrwxrwx 1 junio junio 10 2008-05-25 18:13 /home/junio/git-active -> git-master
drwxr-sr-x 6 junio junio 4096 2007-04-04 02:49 /home/junio/git-maint drwxr-sr-x 5 junio junio 4096 2007-12-14 22:46 /home/junio/git-master drwxr-sr-x 6 junio junio 4096 2008-06-23 22:02 /home/junio/git-next drwxr-sr-x 7 junio junio 4096 2007-12-02 02:52 /home/junio/git-pu drwxr-sr-x 4 junio junio 4096 2006-10-14 22:43 /home/junio/git-snap-v1.0.0 drwxr-sr-x 4 junio junio 4096 2007-01-11 22:27 /home/junio/git-snap-v1.1.0 drwxr-sr-x 4 junio junio 4096 2007-01-11 22:26 /home/junio/git-snap-v1.2.0 drwxr-sr-x 4 junio junio 4096 2007-01-11 22:24 /home/junio/git-snap-v1.3.0
...
drwxr-sr-x 5 junio junio 4096 2008-06-07 12:11 /home/junio/git-snap-v1.5.5.4 drwxr-sr-x 5 junio junio 4096 2008-06-26 17:33 /home/junio/git-snap-v1.5.5.5 drwxr-sr-x 5 junio junio 4096 2008-06-25 14:41 /home/junio/git-test

my "Make" and "Doit" scripts that arrange the $(prefix) for these builds are found in my 'todo' branch.

#8 lore raw
In reply to Ingo Molnar
Quoted 11 lines · Ingo Molnar

There's a small detail i was thinking about: is there a way to get this extra output without actually switching branches? Right now i do this:

earth4:~/tip> git-checkout tip; git-checkout master Checking out files: 100% (2437/2437), done.
Switched to branch "tip"
Switched to branch "master"
Your branch is ahead of the tracked remote branch 'origin/master' by 50 commits.

(Which is an admitted lame solution but the best i could figure.)

Just "git checkout" works for me:
git (master) $ git checkout
Your branch is behind the tracked remote branch 'origin/master' by 6 commits, and can be fast-forwarded.

Björn

#9 lore raw
In reply to Ingo Molnar

2008/7/1 Ingo Molnar <[email protected]>:

Quoted 6 lines · Junio C Hamano
Quoted 5 lines
Quoted 2 lines · Ingo Molnar

i recently switched to 1.5.6.1.89.gd5446 and i'm getting this:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Switched to branch "master"
Your branch is ahead of the tracked remote branch 'origin/master' by 50 commits.

it's a very useful detail! It's especially useful when two branches diverge in a non-trivial way.
...
but having a reminder at checkout time is even better (and faster as well). Kudos.

[snippy]

Quoted 10 lines

There's a small detail i was thinking about: is there a way to get this extra output without actually switching branches? Right now i do this:

earth4:~/tip> git-checkout tip; git-checkout master
Checking out files: 100% (2437/2437), done.
Switched to branch "tip"
Switched to branch "master"
Your branch is ahead of the tracked remote branch 'origin/master' by 50 commits.

(Which is an admitted lame solution but the best i could figure.)

{14:44:16|~code/git}% git checkout master
Checking out files: 100% (180/180), done.
Switched to branch "master"
{14:44:24|~code/git}% git shard HEAD\~5
HEAD is now at 8e69d78 Merge branch 'maint'
{14:44:28|~code/git}% git checkout HEAD
Your branch is behind the tracked remote branch 'origin/master' by 6 commits, and can be fast-forwarded.

Signature · 1 line
Mikael Magnusson
#10 lore raw
In reply to Ingo Molnar
Quoted 7 lines · Ingo Molnar

i recently switched to 1.5.6.1.89.gd5446 and i'm getting this:

Switched to branch "master"
Your branch is ahead of the tracked remote branch 'origin/master' by 50 commits.

it's a very useful detail! It's especially useful when two branches diverge in a non-trivial way.

I agree, it's a really nice little feature. Indeed, I occasionally do "git checkout master" just to get the message (to see where I am).

It feels logical for "git status" to offer the same information (when the information is appropriate).

[...]

#11 lore raw
Quoted 10 lines · Bruce Stephens
Quoted 7 lines · Ingo Molnar

i recently switched to 1.5.6.1.89.gd5446 and i'm getting this:

Switched to branch "master"
Your branch is ahead of the tracked remote branch 'origin/master' by 50 commits.

it's a very useful detail! It's especially useful when two branches diverge in a non-trivial way.

Quoted 7 lines

I agree, it's a really nice little feature. Indeed, I occasionally do "git checkout master" just to get the message (to see where I am).

It feels logical for "git status" to offer the same information (when the information is appropriate).

[...]

i have a tip-curr (shortcut: 'tc') scriptlet to answer the "where I am amongst 100+ branches" question:

earth4:~/tip> tc
tip/master 200a86b: Merge branch 'x86/unify-setup'

which is just a thin wrapper around git-log:

earth4:~/tip> cat ~/bin/tip/tip-curr
#!/bin/bash

. ~/bin/tip/tip-lib

  echo "tip/"$(get_current_branch)" "$(git log -1 --pretty=format:"%h: %s")

Ingo

#12 lore raw

Hi Ingo,

Quoted 6 lines · Ingo Molnar

i have a tip-curr (shortcut: 'tc') scriptlet to answer the "where I am amongst 100+ branches" question:

earth4:~/tip> tc
tip/master 200a86b: Merge branch 'x86/unify-setup'

Quoted 8 lines

which is just a thin wrapper around git-log:

earth4:~/tip> cat ~/bin/tip/tip-curr
#!/bin/bash

. ~/bin/tip/tip-lib

  echo "tip/"$(get_current_branch)" "$(git log -1 --pretty=format:"%h: %s")

how about displaying the current branch in the command prompt?

Quoted 1 line

From contrib/completion/git-completion.bash:

# 4) Consider changing your PS1 to also show the current branch:
# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
#

  #       The argument to __git_ps1 will be displayed only if you
  #       are currently in a git repository.  The %s token will be
  #       the name of the current branch.

Regards,
Gábor

#13 lore raw
Quoted 10 lines · SZEDER Gábor

how about displaying the current branch in the command prompt?

Quoted 1 line

From contrib/completion/git-completion.bash:

# 4) Consider changing your PS1 to also show the current branch:
# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
#

  #       The argument to __git_ps1 will be displayed only if you
  #       are currently in a git repository.  The %s token will be
  #       the name of the current branch.

Because I alos use StGit, I have added to my prompt visual differentiation if the branch is under StGit control.

But I have my own git prompt function, based on git-completion.bash but different. It shows current branch (or "HEAD" if on detached HEAD), current repository, and current working directory. It laso has number of command in history, the same as in my ordinary prompt.

Signature · 3 lines
Jakub Narebski
Poland
ShadeHawk on #git
#14 lore raw
In reply to Ingo Molnar
Quoted 9 lines · Ingo Molnar

* Bruce Stephens <[email protected]> wrote:
...

Quoted 4 lines

It feels logical for "git status" to offer the same information (when the information is appropriate).

[...]

i have a tip-curr (shortcut: 'tc') scriptlet to answer the "where I am amongst 100+ branches" question:

Perhaps like this, but be warned this is untested except for compilation testing.

 builtin-checkout.c |   39 +++++++++++++++++++++------------------
 wt-status.c        |   22 ++++++++++++++++++++++
 2 files changed, 43 insertions(+), 18 deletions(-)
builtin-checkout.c +21 -18
index 93ea69b..2cbc39c 100644
@@ -305,7 +305,7 @@ static int merge_working_tree(struct checkout_opts *opts,
 	return 0;
 }
 
-static void report_tracking(struct branch_info *new, struct checkout_opts *opts)
+void report_tracking(FILE *fp, const char *name, struct commit *commit)
 {
 	/*
 	 * We have switched to a new branch; is it building on
@@ -321,7 +321,7 @@ static void report_tracking(struct branch_info *new, struct checkout_opts *opts)
 	int rev_argc;
 	int num_ours, num_theirs;
 	const char *remote_msg;
-	struct branch *branch = branch_get(new->name);
+	struct branch *branch = branch_get(name);
 
 	/*
 	 * Nothing to report unless we are marked to build on top of
@@ -339,7 +339,7 @@ static void report_tracking(struct branch_info *new, struct checkout_opts *opts)
 		return;
 
 	theirs = lookup_commit(sha1);
-	ours = new->commit;
+	ours = commit;
 	if (!hashcmp(sha1, ours->object.sha1))
 		return; /* we are the same */
 
@@ -380,22 +380,25 @@ static void report_tracking(struct branch_info *new, struct checkout_opts *opts)
 	}
 
 	if (!num_theirs)
-		printf("Your branch is ahead of the tracked%s branch '%s' "
-		       "by %d commit%s.\n",
-		       remote_msg, base,
-		       num_ours, (num_ours == 1) ? "" : "s");
+		fprintf(fp,
+			"Your branch is ahead of the tracked%s branch '%s' "
+			"by %d commit%s.\n",
+			remote_msg, base,
+			num_ours, (num_ours == 1) ? "" : "s");
 	else if (!num_ours)
-		printf("Your branch is behind the tracked%s branch '%s' "
-		       "by %d commit%s,\n"
-		       "and can be fast-forwarded.\n",
-		       remote_msg, base,
-		       num_theirs, (num_theirs == 1) ? "" : "s");
+		fprintf(fp,
+			"Your branch is behind the tracked%s branch '%s' "
+			"by %d commit%s,\n"
+			"and can be fast-forwarded.\n",
+			remote_msg, base,
+			num_theirs, (num_theirs == 1) ? "" : "s");
 	else
-		printf("Your branch and the tracked%s branch '%s' "
-		       "have diverged,\nand respectively "
-		       "have %d and %d different commit(s) each.\n",
-		       remote_msg, base,
-		       num_ours, num_theirs);
+		fprintf(fp,
+			"Your branch and the tracked%s branch '%s' "
+			"have diverged,\nand respectively "
+			"have %d and %d different commit(s) each.\n",
+			remote_msg, base,
+			num_ours, num_theirs);
 }
 
 static void update_refs_for_switch(struct checkout_opts *opts,
@@ -441,7 +444,7 @@ static void update_refs_for_switch(struct checkout_opts *opts,
 	remove_branch_state();
 	strbuf_release(&msg);
 	if (!opts->quiet && (new->path || !strcmp(new->name, "HEAD")))
-		report_tracking(new, opts);
+		report_tracking(stdout, new->name, new->commit);
 }
 
 static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
wt-status.c +22 -0
index 28c9e63..e02171a 100644
@@ -315,6 +315,26 @@ static void wt_status_print_verbose(struct wt_status *s)
 	run_diff_index(&rev, 1);
 }
 
+/* NEEDSWORK */
+extern void report_tracking(FILE *fp, const char *name, struct commit *commit);
+
+static void wt_status_print_tracking(struct wt_status *s)
+{
+	unsigned char sha1[20];
+	struct commit *commit;
+
+	assert(s->branch && !s->is_initial);
+
+	if (prefixcmp(s->branch, "refs/heads/") ||
+	    !resolve_ref(s->branch, sha1, 1, NULL))
+		return;
+	commit = lookup_commit(sha1);
+	if (!commit)
+		return;
+	fprintf(s->fp, "# ");
+	report_tracking(s->fp, s->branch + 11, commit);
+}
+
 void wt_status_print(struct wt_status *s)
 {
 	unsigned char sha1[20];
@@ -333,6 +353,8 @@ void wt_status_print(struct wt_status *s)
 		}
 		color_fprintf(s->fp, color(WT_STATUS_HEADER), "# ");
 		color_fprintf_ln(s->fp, branch_color, "%s%s", on_what, branch_name);
+		if (!s->is_initial)
+			wt_status_print_tracking(s);
 	}
 
 	if (s->is_initial) {
#15 lore raw

cover Making remote tracking statistics available to other tools

The one I sent out was a bit hacky as the existing implementation inside git-checkout was not designed to be cleanly reusable.

Here is a cleaned up series that could be applied.

[PATCH 1/3] Refactor "tracking statistics" code used by "git checkout" [PATCH 2/3] git-status: show the remote tracking statistics [PATCH 3/3] git-branch -v: show the remote tracking statistics

#19 lore raw

PATCH 1/3 Refactor "tracking statistics" code used by "git checkout"

In reply to Junio C Hamano

People seem to like "Your branch is ahead by N commit" report made by "git checkout", but the interface into the statistics function was a bit clunky. This splits the function into three parts:

* The core "commit counting" function that takes "struct branch" and returns number of commits to show if we are ahead, behind or forked;

* Convenience "stat formating" function that takes "struct branch" and formats the report into a given strbuf, using the above function;

* "checkout" specific function that takes "branch_info" (type that is internal to checkout implementation), calls the above function and print the formatted result.

in the hope that the former two can be more easily reusable.

---
 builtin-checkout.c |   94 +++----------------------------------------
 remote.c           |  113 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 remote.h           |    4 ++
 3 files changed, 123 insertions(+), 88 deletions(-)
builtin-checkout.c +6 -88
index 93ea69b..d6641c2 100644
@@ -305,97 +305,15 @@ static int merge_working_tree(struct checkout_opts *opts,
 	return 0;
 }
 
-static void report_tracking(struct branch_info *new, struct checkout_opts *opts)
+static void report_tracking(struct branch_info *new)
 {
-	/*
-	 * We have switched to a new branch; is it building on
-	 * top of another branch, and if so does that other branch
-	 * have changes we do not have yet?
-	 */
-	char *base;
-	unsigned char sha1[20];
-	struct commit *ours, *theirs;
-	char symmetric[84];
-	struct rev_info revs;
-	const char *rev_argv[10];
-	int rev_argc;
-	int num_ours, num_theirs;
-	const char *remote_msg;
+	struct strbuf sb = STRBUF_INIT;
 	struct branch *branch = branch_get(new->name);
 
-	/*
-	 * Nothing to report unless we are marked to build on top of
-	 * somebody else.
-	 */
-	if (!branch || !branch->merge || !branch->merge[0] || !branch->merge[0]->dst)
-		return;
-
-	/*
-	 * If what we used to build on no longer exists, there is
-	 * nothing to report.
-	 */
-	base = branch->merge[0]->dst;
-	if (!resolve_ref(base, sha1, 1, NULL))
+	if (!format_tracking_info(branch, &sb))
 		return;
-
-	theirs = lookup_commit(sha1);
-	ours = new->commit;
-	if (!hashcmp(sha1, ours->object.sha1))
-		return; /* we are the same */
-
-	/* Run "rev-list --left-right ours...theirs" internally... */
-	rev_argc = 0;
-	rev_argv[rev_argc++] = NULL;
-	rev_argv[rev_argc++] = "--left-right";
-	rev_argv[rev_argc++] = symmetric;
-	rev_argv[rev_argc++] = "--";
-	rev_argv[rev_argc] = NULL;
-
-	strcpy(symmetric, sha1_to_hex(ours->object.sha1));
-	strcpy(symmetric + 40, "...");
-	strcpy(symmetric + 43, sha1_to_hex(theirs->object.sha1));
-
-	init_revisions(&revs, NULL);
-	setup_revisions(rev_argc, rev_argv, &revs, NULL);
-	prepare_revision_walk(&revs);
-
-	/* ... and count the commits on each side. */
-	num_ours = 0;
-	num_theirs = 0;
-	while (1) {
-		struct commit *c = get_revision(&revs);
-		if (!c)
-			break;
-		if (c->object.flags & SYMMETRIC_LEFT)
-			num_ours++;
-		else
-			num_theirs++;
-	}
-
-	if (!prefixcmp(base, "refs/remotes/")) {
-		remote_msg = " remote";
-		base += strlen("refs/remotes/");
-	} else {
-		remote_msg = "";
-	}
-
-	if (!num_theirs)
-		printf("Your branch is ahead of the tracked%s branch '%s' "
-		       "by %d commit%s.\n",
-		       remote_msg, base,
-		       num_ours, (num_ours == 1) ? "" : "s");
-	else if (!num_ours)
-		printf("Your branch is behind the tracked%s branch '%s' "
-		       "by %d commit%s,\n"
-		       "and can be fast-forwarded.\n",
-		       remote_msg, base,
-		       num_theirs, (num_theirs == 1) ? "" : "s");
-	else
-		printf("Your branch and the tracked%s branch '%s' "
-		       "have diverged,\nand respectively "
-		       "have %d and %d different commit(s) each.\n",
-		       remote_msg, base,
-		       num_ours, num_theirs);
+	fputs(sb.buf, stdout);
+	strbuf_release(&sb);
 }
 
 static void update_refs_for_switch(struct checkout_opts *opts,
@@ -441,7 +359,7 @@ static void update_refs_for_switch(struct checkout_opts *opts,
 	remove_branch_state();
 	strbuf_release(&msg);
 	if (!opts->quiet && (new->path || !strcmp(new->name, "HEAD")))
-		report_tracking(new, opts);
+		report_tracking(new);
 }
 
 static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
remote.c +113 -0

122 lines not on this page · raw message

remote.h +4 -0
index 8eed87b..091b1d0 100644
@@ -129,4 +129,8 @@ enum match_refs_flags {
 	MATCH_REFS_MIRROR	= (1 << 1),
 };
 
+/* Reporting of tracking info */
+int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs);
+int format_tracking_info(struct branch *branch, struct strbuf *sb);
+
 #endif
Signature · 1 line
1.5.6.1.156.ge903b
#20 lore raw

PATCH 2/3 git-status: show the remote tracking statistics

In reply to Junio C Hamano

This teaches "git status" to show the same remote tracking statistics "git checkout" gives at the beginning of the output.

Now the necessary low-level machinery is properly factored out, we can do this quite cleanly.

---
 wt-status.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
wt-status.c +22 -0
index 28c9e63..eeb106e 100644
@@ -9,6 +9,7 @@
 #include "diffcore.h"
 #include "quote.h"
 #include "run-command.h"
+#include "remote.h"
 
 int wt_status_relative_paths = 1;
 int wt_status_use_color = -1;
@@ -315,6 +316,25 @@ static void wt_status_print_verbose(struct wt_status *s)
 	run_diff_index(&rev, 1);
 }
 
+static void wt_status_print_tracking(struct wt_status *s)
+{
+	struct strbuf sb = STRBUF_INIT;
+	const char *cp, *ep;
+	struct branch *branch;
+
+	assert(s->branch && !s->is_initial);
+	if (prefixcmp(s->branch, "refs/heads/"))
+		return;
+	branch = branch_get(s->branch + 11);
+	if (!format_tracking_info(branch, &sb))
+		return;
+
+	for (cp = sb.buf; (ep = strchr(cp, '\n')) != NULL; cp = ep + 1)
+		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER),
+				 "# %.*s", (int)(ep - cp), cp);
+	color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#");
+}
+
 void wt_status_print(struct wt_status *s)
 {
 	unsigned char sha1[20];
@@ -333,6 +353,8 @@ void wt_status_print(struct wt_status *s)
 		}
 		color_fprintf(s->fp, color(WT_STATUS_HEADER), "# ");
 		color_fprintf_ln(s->fp, branch_color, "%s%s", on_what, branch_name);
+		if (!s->is_initial)
+			wt_status_print_tracking(s);
 	}
 
 	if (s->is_initial) {
Signature · 1 line
1.5.6.1.156.ge903b
#21 lore raw

PATCH 3/3 git-branch -v: show the remote tracking statistics

In reply to Junio C Hamano

This teaches "git branch -v" to insert the remote tracking statistics in the form of [ours/theirs] just before the one-liner commit log message for the branch.

---
... which means that you would see something like this.

* jc/report-tracking 41666f7 [3/117] git-branch -v: show the remo...

I did not think we want to spend extra columns to show the name of remote branch each of them tracks, so I am showing only counts.

 builtin-branch.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
builtin-branch.c +12 -2
index d279702..0e2bb52 100644
@@ -310,6 +310,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
 	if (verbose) {
 		struct strbuf subject;
 		const char *sub = " **** invalid ref ****";
+		char stat[128];
 
 		strbuf_init(&subject, 0);
 
@@ -319,10 +320,19 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
 					    &subject, 0, NULL, NULL, 0, 0);
 			sub = subject.buf;
 		}
-		printf("%c %s%-*s%s %s %s\n", c, branch_get_color(color),
+
+		stat[0] = '\0';
+		if (item->kind == REF_LOCAL_BRANCH) {
+			int ours, theirs;
+			struct branch *branch = branch_get(item->name);
+			if (stat_tracking_info(branch, &ours, &theirs))
+				sprintf(stat, "[%d/%d] ", ours, theirs);
+		}
+		printf("%c %s%-*s%s %s %s%s\n", c, branch_get_color(color),
 		       maxwidth, item->name,
 		       branch_get_color(COLOR_BRANCH_RESET),
-		       find_unique_abbrev(item->sha1, abbrev), sub);
+		       find_unique_abbrev(item->sha1, abbrev),
+		       stat, sub);
 		strbuf_release(&subject);
 	} else {
 		printf("%c %s%s%s\n", c, branch_get_color(color), item->name,
Signature · 1 line
1.5.6.1.156.ge903b
#22 lore raw

Re: [PATCH 3/3] git-branch -v: show the remote tracking statistics

Quoted 4 lines · Junio C Hamano

This teaches "git branch -v" to insert the remote tracking statistics in the form of [ours/theirs] just before the one-liner commit log message for the branch.

Quoted 8 lines

---
... which means that you would see something like this.

* jc/report-tracking 41666f7 [3/117] git-branch -v: show the remo...

I did not think we want to spend extra columns to show the name of remote branch each of them tracks, so I am showing only counts.

What makes the "tracking statistics" so useful, is that it explains the situation in clear words. But here you throw in a few numbers without explanation. It's practically undiscoverable what the numbers mean. Therefore, I personally would prefer not to have them here and to save the space for the commit summary.

What do you think about showing the tracking information only if --track is supplied? But then even write more information:

* jc/report-tracking   41666f7 diverged 3 vs. 117
  foo                  1234567 behind 22
  bar                  fedcba9 ahead 6

and filter the output to show only tracking branches.

-- Hannes

#23 lore raw

Re: [PATCH 3/3] git-branch -v: show the remote tracking statistics

Quoted 1 line · Johannes Sixt

* jc/report-tracking 41666f7 diverged 3 vs. 117

Or even "ahead 3, behind 117" here. Otherwise the user has to remember which number is which, which kind of defeats your point. And it's just one more character.

Quoted 2 lines

foo 1234567 behind 22
bar fedcba9 ahead 6

Signature · 2 lines
Karl Hasselström, [email protected]
      www.treskal.com/kalle
#24 lore raw

Re: [PATCH 3/3] git-branch -v: show the remote tracking statistics

Quoted 10 lines · Karl Hasselström
Quoted 1 line · Johannes Sixt

* jc/report-tracking 41666f7 diverged 3 vs. 117

Or even "ahead 3, behind 117" here. Otherwise the user has to remember which number is which, which kind of defeats your point. And it's just one more character.

Quoted 2 lines

foo 1234567 behind 22
bar fedcba9 ahead 6

This is probably the most useful for a new user. The short version of that (config option to give it for power users and hide it from those it would confuse) should use plus and minus for ahead and behind:

* jc/report-tracking 41666f7 [+3 -117] git-branch -v: show
the remo...

I can't follow the code with the ten seconds I have to look at it. Is this ahead/behind current branch, tracking branch, or other?

~~ Brian

#25 lore raw

Re: [PATCH 3/3] git-branch -v: show the remote tracking statistics

In reply to Johannes Sixt
Quoted 8 lines · Johannes Sixt

What do you think about showing the tracking information only if --track is supplied? But then even write more information:

* jc/report-tracking   41666f7 diverged 3 vs. 117
  foo                  1234567 behind 22
  bar                  fedcba9 ahead 6

and filter the output to show only tracking branches.

I am not sure about the use of --track option, but now the infrastructure is clean enough for anybody to paint it in his favorite color, and I do not care deeply about how it would look like. Discuss away and give me an applicable patch that the list has concensus on, and I'll apply it.

#26 lore raw

Re: [PATCH 3/3] git-branch -v: show the remote tracking statistics

In reply to Junio C Hamano

Hi,

Quoted 9 lines · Junio C Hamano

This teaches "git branch -v" to insert the remote tracking statistics in the form of [ours/theirs] just before the one-liner commit log message for the branch.

---
... which means that you would see something like this.

* jc/report-tracking 41666f7 [3/117] git-branch -v: show the remo...

Actually, I would like to have something like

$ git branch --explain-relationship master next

Ciao,
Dscho

#27 lore raw
In reply to Bruce Stephens
Quoted 7 lines · Bruce Stephens
Quoted 5 lines · Ingo Molnar

i recently switched to 1.5.6.1.89.gd5446 and i'm getting this:

Switched to branch "master"
Your branch is ahead of the tracked remote branch 'origin/master' by 50 commits.

Quoted 8 lines
Quoted 2 lines

it's a very useful detail! It's especially useful when two branches diverge in a non-trivial way.

I agree, it's a really nice little feature. Indeed, I occasionally do "git checkout master" just to get the message (to see where I am).

It feels logical for "git status" to offer the same information (when the information is appropriate).

I agree that having this information in git-status would be useful, especially that it would make having this reminder in buffer/editor when editing commit message.

Signature · 3 lines
Jakub Narebski
Poland
ShadeHawk on #git
#7 lore raw
In reply to Ingo Molnar

Hi,

Quoted 2 lines · Ingo Molnar

[ Oh, and i could switch between git versions without having to rebuild
;-) ]

hmms... Can you just use

version=git-describe
./configure --prefix=/usr/local/git-$version
make && sudo make install
sudo sh -c 'rm -f /usr/local/git && ln -s /usr/local/git-$version /usr/local/git'

and stick /usr/local/git/bin in your path?

Changing git versions is just a ln -s away.

Best regards,

Signature · 4 lines
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: [email protected]
Use XMPP!
#16 lore raw

Re: [PATCH 0/3] Making remote tracking statistics available to other tools

In reply to Junio C Hamano
Quoted 8 lines · Junio C Hamano

The one I sent out was a bit hacky as the existing implementation inside git-checkout was not designed to be cleanly reusable.

Here is a cleaned up series that could be applied.

[PATCH 1/3] Refactor "tracking statistics" code used by "git checkout" [PATCH 2/3] git-status: show the remote tracking statistics [PATCH 3/3] git-branch -v: show the remote tracking statistics

Sorry, but the third patch does not work for me. FWIU, the problem comes from the revision walking code that is not reentrant because of the object cache. IOW, calling stats_tracking_info() more than once does not work: objects states changed after first call.

I do not understand the code enough yet and I failed to fix it. The only way I found is by clearing obj_hash (object.c) but this seems the wrong thing to do.

Ideas?

This test case should trigger the bug:

$ for i in a b c; do echo $i>$i && git add $i && git commit -m $i; done
$ git clone . clone1
$ cd clone1
$ git checkout -b b1 origin/master
$ git reset --hard HEAD~
$ echo d>d && git add d && git commit -m d
$ git checkout -b b2 origin/master
$ git reset --hard HEAD~
$ git merge b1
$ git branch -v
  b1     c07015a [ahead 1, behind 1] d
* b2     c07015a d
  master 08ca18b c

b1 and b2 are both 1 commit ahead and 1 commit behind.

$ git branch -D b1
$ git branch -v
* b2     c07015a [ahead 1, behind 1] d
  master 08ca18b c

deleting b1 show us the side effect.

Olivier.

#17 lore raw

Re: [PATCH 0/3] Making remote tracking statistics available to other tools

Quoted 15 lines · Olivier Marin
Quoted 8 lines · Junio C Hamano

The one I sent out was a bit hacky as the existing implementation inside git-checkout was not designed to be cleanly reusable.

Here is a cleaned up series that could be applied.

[PATCH 1/3] Refactor "tracking statistics" code used by "git checkout" [PATCH 2/3] git-status: show the remote tracking statistics [PATCH 3/3] git-branch -v: show the remote tracking statistics

Sorry, but the third patch does not work for me. FWIU, the problem comes from the revision walking code that is not reentrant because of the object cache. IOW, calling stats_tracking_info() more than once does not work: objects states changed after first call.

Quoted 5 lines

I do not understand the code enough yet and I failed to fix it. The only way I found is by clearing obj_hash (object.c) but this seems the wrong thing to do.

Ideas?

Thanks.

 remote.c                 |    4 +++
 revision.h               |    1 +
 t/t6040-tracking-info.sh |   52 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+), 0 deletions(-)
remote.c +4 -0
index bd5c3be..df8bd72 100644
@@ -1295,6 +1295,10 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs)
 		else
 			(*num_theirs)++;
 	}
+
+	/* clear object flags smudged by the above traversal */
+	clear_commit_marks(ours, ALL_REV_FLAGS);
+	clear_commit_marks(theirs, ALL_REV_FLAGS);
 	return 1;
 }
 
revision.h +1 -0
index abce500..e8bac6d 100644
@@ -11,6 +11,7 @@
 #define ADDED		(1u<<7)	/* Parents already parsed and added? */
 #define SYMMETRIC_LEFT	(1u<<8)
 #define TOPOSORT	(1u<<9)	/* In the active toposort list.. */
+#define ALL_REV_FLAGS	((1u<<10)-1)
 
 struct rev_info;
 struct log_info;
t/t6040-tracking-info.sh new file +52 -0

52 lines not on this page · raw message

#18 lore raw

Re: [PATCH 0/3] Making remote tracking statistics available to other tools

Quoted 5 lines · Junio C Hamano
 remote.c                 |    4 +++
 revision.h               |    1 +
 t/t6040-tracking-info.sh |   52 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+), 0 deletions(-)

Tested: it works. Thanks.

Olivier.