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

[PATCH 5/5] branch: give patchsame count with -vvv

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Aug 25, 2011, 08:30 UTC
Message-ID
<1b532b894c26c6b31c94760222715b5eb5cc45bb.1314259226.git.git@drmicha.warpmail.net>
In-Reply-To
<4E5607E0.1050300@drmicha.warpmail.net>
This results in output like such as
  mjg/attr-filetype                    9d2536e [origin/next: ahead 35,
behind 1430, same 46] attr: make attributes depend on file type
all on one line.
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
 Documentation/git-branch.txt |    2 ++
 builtin/branch.c             |   24 ++++++++++++++++--------
 remote.c                     |   12 +++++++++---
 remote.h                     |    2 +-
 t/t6040-tracking-info.sh     |   19 ++++++++++++++++++-
 wt-status.c                  |    2 +-
 6 files changed, 47 insertions(+), 14 deletions(-)
diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 59d729a..770b2e4 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -117,6 +117,8 @@ OPTIONS
 	Show sha1 and commit subject line for each head, along with
 	the name of the upstream branch (if any). If given twice, print
 	the relationship to the upstream branch (ahead/behind), as well.
+	If given three times, show ahead/behind/same information like
+	`git rev-list --count --cherry-mark`.
 	`--list` is implied by all verbosity options.
 
 --abbrev=<length>::
diff --git a/builtin/branch.c b/builtin/branch.c
index 21ef5fc..0984bb7 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -361,7 +361,7 @@ static int ref_cmp(const void *r1, const void *r2)
 static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
 		int verbose)
 {
-	int ours, theirs;
+	int ours, theirs, patchsame = 0;
 	struct branch *branch = branch_get(branch_name);
 
 	/* verbose >= 1 */
@@ -370,14 +370,22 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
 	strbuf_addch(stat, '[');
 	strbuf_addstr(stat, shorten_unambiguous_ref(branch->merge[0]->dst, 0));
 
-	if (verbose >= 2 && stat_tracking_info(branch, &ours, &theirs)) {
-		strbuf_addstr(stat, ": ");
-		if (!ours)
-			strbuf_addf(stat, _("behind %d"), theirs);
-		else if (!theirs)
+	if (verbose >= 2 && stat_tracking_info(branch, &ours, &theirs, (verbose >=3) ? &patchsame : NULL)) {
+		strbuf_addstr(stat, _(": "));
+		const char *sep = "";
+		if (ours) {
 			strbuf_addf(stat, _("ahead %d"), ours);
-		else
-			strbuf_addf(stat, _("ahead %d, behind %d"), ours, theirs);
+			sep = _(", ");
+		}
+		if (theirs) {
+			strbuf_addstr(stat, sep);
+			strbuf_addf(stat, _("behind %d"), theirs);
+			sep = _(", ");
+		}
+		if (patchsame) {
+			strbuf_addstr(stat, sep);
+			strbuf_addf(stat, _("same %d"), patchsame);
+		}
 	}
 	strbuf_addstr(stat, "] ");
 }
diff --git a/remote.c b/remote.c
index b8ecfa5..40cebef 100644
--- a/remote.c
+++ b/remote.c
@@ -1510,7 +1510,7 @@ int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1)
 /*
  * Return true if there is anything to report, otherwise false.
  */
-int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs)
+int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs, int *num_patchsame)
 {
 	unsigned char sha1[20];
 	struct commit *ours, *theirs;
@@ -1553,6 +1553,8 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs)
 	rev_argv[rev_argc++] = NULL;
 	rev_argv[rev_argc++] = "--left-right";
 	rev_argv[rev_argc++] = symmetric;
+	if (num_patchsame)
+		rev_argv[rev_argc++] = "--cherry-mark";
 	rev_argv[rev_argc++] = "--";
 	rev_argv[rev_argc] = NULL;
 
@@ -1567,11 +1569,15 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs)
 	/* ... and count the commits on each side. */
 	*num_ours = 0;
 	*num_theirs = 0;
+	if (num_patchsame)
+		*num_patchsame = 0;
 	while (1) {
 		struct commit *c = get_revision(&revs);
 		if (!c)
 			break;
-		if (c->object.flags & SYMMETRIC_LEFT)
+		if (c->object.flags & PATCHSAME)
+			(*num_patchsame)++;
+		else if (c->object.flags & SYMMETRIC_LEFT)
 			(*num_ours)++;
 		else
 			(*num_theirs)++;
@@ -1591,7 +1597,7 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
 	int num_ours, num_theirs;
 	const char *base;
 
-	if (!stat_tracking_info(branch, &num_ours, &num_theirs))
+	if (!stat_tracking_info(branch, &num_ours, &num_theirs, NULL))
 		return 0;
 
 	base = branch->merge[0]->dst;
diff --git a/remote.h b/remote.h
index 9a30a9d..31c1f28 100644
--- a/remote.h
+++ b/remote.h
@@ -149,7 +149,7 @@ enum match_refs_flags {
 };
 
 /* Reporting of tracking info */
-int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs);
+int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs, int *num_patchsame);
 int format_tracking_info(struct branch *branch, struct strbuf *sb);
 
 struct ref *get_local_heads(void);
diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh
index 9539882..f8bff61 100755
--- a/t/t6040-tracking-info.sh
+++ b/t/t6040-tracking-info.sh
@@ -24,6 +24,7 @@ test_expect_success setup '
 		advance d &&
 		git checkout -b b2 origin &&
 		git reset --hard b1 &&
+		git cherry-pick origin &&
 		git checkout -b b3 origin &&
 		git reset --hard HEAD^ &&
 		git checkout -b b4 origin &&
@@ -53,7 +54,7 @@ test_expect_success 'branch -v' '
 
 cat >expect <<\EOF
 b1 origin/master: ahead 1, behind 1
-b2 origin/master: ahead 1, behind 1
+b2 origin/master: ahead 2, behind 1
 b3 origin/master: behind 1
 b4 origin/master: ahead 2
 EOF
@@ -67,6 +68,22 @@ test_expect_success 'branch -vv' '
 	test_i18ncmp expect actual
 '
 
+cat >expect <<\EOF
+b1 origin/master: ahead 1, behind 1
+b2 origin/master: ahead 1, same 2
+b3 origin/master: behind 1
+b4 origin/master: ahead 2
+EOF
+
+test_expect_success 'branch -vvv' '
+	(
+		cd test &&
+		git branch -vvv
+	) |
+	sed -n -e "$script" >actual &&
+	test_i18ncmp expect actual
+'
+
 test_expect_success 'checkout' '
 	(
 		cd test && git checkout b1
diff --git a/wt-status.c b/wt-status.c
index 8836a52..522318a 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -890,7 +890,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
 	branch = branch_get(s->branch + 11);
 	if (s->is_initial)
 		color_fprintf(s->fp, header_color, _("Initial commit on "));
-	if (!stat_tracking_info(branch, &num_ours, &num_theirs)) {
+	if (!stat_tracking_info(branch, &num_ours, &num_theirs, NULL)) {
 		color_fprintf_ln(s->fp, branch_color_local,
 			"%s", branch_name);
 		return;
-- 
1.7.6.845.gc3c05
Previous: Junio C Hamano
Message 77 of 77 in “[RFC] branch: list branches by single remote”
  1. Michael SchubertAug 2, 2011
  2. Jeff KingAug 4, 2011
  3. Michael J GruberAug 16, 2011
  4. Michael SchubertAug 16, 2011
  5. Jeff KingAug 16, 2011
  6. Michael SchubertAug 24, 2011
  7. Michael J GruberAug 24, 2011
  8. Michael SchubertAug 24, 2011
  9. Junio C HamanoAug 24, 2011
  10. Thiago FarinaAug 25, 2011
  11. Junio C HamanoAug 25, 2011
  12. Michael J GruberAug 25, 2011
  13. 0/5 RFC: patterns for branch listMichael J Gruber, Aug 25, 2011
  14. Jeff KingAug 25, 2011
  15. Michael J GruberAug 26, 2011
  16. Junio C HamanoAug 26, 2011
  17. Jeff KingSep 7, 2011
  18. Michael J GruberSep 8, 2011
  19. 0/5 patterns for branch listMichael J Gruber, Aug 26, 2011
  20. 0/5 patterns for branch listMichael J Gruber, Aug 28, 2011
  21. 1/5 t6040: test branch -vvMichael J Gruber, Aug 28, 2011
  22. 2/5 git-tag: introduce long forms for the optionsMichael J Gruber, Aug 28, 2011
  23. 3/5 git-branch: introduce missing long forms for the optionsMichael J Gruber, Aug 28, 2011
  24. 4/5 branch: introduce --list optionMichael J Gruber, Aug 28, 2011
  25. Junio C HamanoAug 29, 2011
  26. Michael J GruberAug 29, 2011
  27. Junio C HamanoAug 29, 2011
  28. 5/5 branch: allow pattern argumentsMichael J Gruber, Aug 28, 2011
  29. Michael SchubertSep 6, 2011
  30. Michael J GruberSep 6, 2011
  31. Sverre RabbelierSep 6, 2011
  32. Michael J GruberSep 6, 2011
  33. 1/5 t6040: test branch -vvMichael J Gruber, Aug 26, 2011
  34. 2/5 git-tag: introduce long forms for the optionsMichael J Gruber, Aug 26, 2011
  35. Junio C HamanoAug 26, 2011
  36. Michael J GruberAug 28, 2011
  37. 3/5 git-branch: introduce missing long forms for the optionsMichael J Gruber, Aug 26, 2011
  38. Junio C HamanoAug 26, 2011
  39. Michael J GruberAug 28, 2011
  40. 4/5 branch: introduce --list optionMichael J Gruber, Aug 26, 2011
  41. Junio C HamanoAug 26, 2011
  42. Michael J GruberAug 28, 2011
  43. Jeff KingSep 7, 2011
  44. Michael J GruberSep 8, 2011
  45. 0/5 mg/branch-list amendmentMichael J Gruber, Sep 8, 2011
  46. 4/5 branch: introduce --list optionMichael J Gruber, Sep 8, 2011
  47. 5/5 branch: allow pattern argumentsMichael J Gruber, Sep 8, 2011
  48. Junio C HamanoSep 8, 2011
  49. Jeff KingSep 8, 2011
  50. Junio C HamanoSep 8, 2011
  51. Jeff KingSep 9, 2011
  52. Michael J GruberSep 9, 2011
  53. Junio C HamanoSep 9, 2011
  54. Michael J GruberSep 9, 2011
  55. Jeff KingSep 9, 2011
  56. t3200: test branch creation with -vMichael J Gruber, Sep 9, 2011
  57. Jeff KingSep 9, 2011
  58. Jeff KingSep 9, 2011
  59. Michael J GruberSep 10, 2011
  60. Jeff KingSep 13, 2011
  61. Michael J GruberSep 13, 2011
  62. t3200: clean up checks for file existenceJeff King, Sep 13, 2011
  63. Junio C HamanoSep 13, 2011
  64. Jeff KingSep 13, 2011
  65. 5/5 branch: allow pattern argumentsMichael J Gruber, Aug 26, 2011
  66. Junio C HamanoAug 26, 2011
  67. 1/5 branch: allow pattern argumentsMichael J Gruber, Aug 25, 2011
  68. Jeff KingAug 25, 2011
  69. Junio C HamanoAug 25, 2011
  70. Junio C HamanoAug 25, 2011
  71. 2/5 branch: introduce --list argumentMichael J Gruber, Aug 25, 2011
  72. Junio C HamanoAug 25, 2011
  73. Junio C HamanoAug 25, 2011
  74. 3/5 t6040; test branch -vvMichael J Gruber, Aug 25, 2011
  75. 4/5 branch: restructure -v vs. -vvMichael J Gruber, Aug 25, 2011
  76. Junio C HamanoAug 25, 2011
  77. 5/5 branch: give patchsame count with -vvvMichael J Gruber, Aug 25, 2011

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.