git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 2, 2008, 07:52 UTC
Message-ID
<7vhcb8en92.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<7vlk0lmn32.fsf@gitster.siamese.dyndns.org>

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.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
  ... 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(-)
diff --git a/builtin-branch.c b/builtin-branch.c
index d279702..0e2bb52 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -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,
-- 
1.5.6.1.156.ge903b
Previous: Junio C HamanoNext: Johannes Sixt
Message 13 of 28 in “[OT] Your branch is ahead of the tracked remote branch 'origin/master' by 50 commits.”
  1. Ingo MolnarJul 1, 2008
  2. Bruce StephensJul 1, 2008
  3. Ingo MolnarJul 1, 2008
  4. SZEDER GáborJul 1, 2008
  5. Jakub NarebskiJul 1, 2008
  6. Junio C HamanoJul 1, 2008
  7. 0/3 Making remote tracking statistics available to other toolsJunio C Hamano, Jul 2, 2008
  8. Olivier MarinJul 3, 2008
  9. Junio C HamanoJul 3, 2008
  10. Olivier MarinJul 3, 2008
  11. 1/3 Refactor "tracking statistics" code used by "git checkout"Junio C Hamano, Jul 2, 2008
  12. 2/3 git-status: show the remote tracking statisticsJunio C Hamano, Jul 2, 2008
  13. 3/3 git-branch -v: show the remote tracking statisticsJunio C Hamano, Jul 2, 2008
  14. Johannes SixtJul 2, 2008
  15. Karl HasselströmJul 2, 2008
  16. Brian GernhardtJul 2, 2008
  17. Junio C HamanoJul 2, 2008
  18. Johannes SchindelinJul 2, 2008
  19. Jakub NarebskiJul 1, 2008
  20. Junio C HamanoJul 1, 2008
  21. Ingo MolnarJul 1, 2008
  22. Miklos VajnaJul 1, 2008
  23. Ingo MolnarJul 1, 2008
  24. Miklos VajnaJul 1, 2008
  25. Junio C HamanoJul 1, 2008
  26. Pedro MeloJul 4, 2008
  27. Mikael MagnussonJul 1, 2008
  28. Björn SteinbrinkJul 1, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.