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

[PATCH 6/7] merge-base: limit the output to bases that are on first-parent chain

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 19, 2016, 04:23 UTC
Message-ID
<20161019042345.29766-7-gitster@pobox.com>
In-Reply-To
<20161019042345.29766-1-gitster@pobox.com>

A new option "--fp-only" limits the output to the merge bases that are on the first-parent chain from the branches being merged.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/git-merge-base.txt |  8 +++++++-
 builtin/merge-base.c             | 10 +++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-merge-base.txt b/Documentation/git-merge-base.txt
index 808426faac..f99653f138 100644
--- a/Documentation/git-merge-base.txt
+++ b/Documentation/git-merge-base.txt
@@ -9,7 +9,7 @@ git-merge-base - Find as good common ancestors as possible for a merge
 SYNOPSIS
 --------
 [verse]
-'git merge-base' [-a|--all] <commit> <commit>...
+'git merge-base' [-a|--all] [--fp-only] <commit> <commit>...
 'git merge-base' [-a|--all] --octopus <commit>...
 'git merge-base' --is-ancestor <commit> <commit>
 'git merge-base' --independent <commit>...
@@ -72,6 +72,12 @@ OPTIONS
 --all::
 	Output all merge bases for the commits, instead of just one.
 
+--fp-only::
+	Limit the output to merge bases that are on the first-parent
+	chain from none of the commits given on the command line.
+
+
+
 DISCUSSION
 ----------
 
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index c0d1822eb3..42febb20ff 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -6,11 +6,12 @@
 #include "revision.h"
 #include "parse-options.h"
 
-static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
+static int show_merge_base(struct commit **rev, int rev_nr, int show_all, int fp_only)
 {
 	struct commit_list *result;
+	unsigned flags = fp_only ? MB_FPCHAIN : 0;
 
-	result = get_merge_bases_many_dirty(rev[0], rev_nr - 1, rev + 1);
+	result = get_merge_bases_opt(rev[0], rev_nr - 1, rev + 1, flags);
 
 	if (!result)
 		return 1;
@@ -208,10 +209,13 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)
 	struct commit **rev;
 	int rev_nr = 0;
 	int show_all = 0;
+	int fp_only = 0;
 	int cmdmode = 0;
 
 	struct option options[] = {
 		OPT_BOOL('a', "all", &show_all, N_("output all common ancestors")),
+		OPT_BOOL(0, "fp-only", &fp_only,
+			 N_("limit to bases that are on first-parent chain")),
 		OPT_CMDMODE(0, "octopus", &cmdmode,
 			    N_("find ancestors for a single n-way merge"), 'o'),
 		OPT_CMDMODE(0, "independent", &cmdmode,
@@ -255,5 +259,5 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)
 	ALLOC_ARRAY(rev, argc);
 	while (argc-- > 0)
 		rev[rev_nr++] = get_commit_reference(*argv++);
-	return show_merge_base(rev, rev_nr, show_all);
+	return show_merge_base(rev, rev_nr, show_all, fp_only);
 }
-- 
2.10.1-631-gb2c64dcf30
Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 13 in “[RFD] should all merge bases be equal?”
  1. Junio C HamanoOct 17, 2016
  2. 0/7 Rejecting useless merge basesJunio C Hamano, Oct 19, 2016
  3. 1/7 commit: simplify fastpath of merge-base computationJunio C Hamano, Oct 19, 2016
  4. 3/7 merge-base: stop moving commits around in remove_redundant()Junio C Hamano, Oct 19, 2016
  5. 2/7 sha1_name: remove ONELINE_SEEN bitJunio C Hamano, Oct 19, 2016
  6. 4/7 merge-base: expose get_merge_bases_many_0() a bit moreJunio C Hamano, Oct 19, 2016
  7. 5/7 merge-base: mark bases that are on first-parent chainJunio C Hamano, Oct 19, 2016
  8. Junio C HamanoOct 19, 2016
  9. 6/7 merge-base: limit the output to bases that are on first-parent chainJunio C Hamano, Oct 19, 2016
  10. 7/7 merge: allow to use only the fp-only merge basesJunio C Hamano, Oct 19, 2016
  11. Junio C HamanoOct 19, 2016
  12. Michael HaggertyFeb 9, 2017
  13. Junio C HamanoFeb 9, 2017

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.