Skip to content

Commit decc17f

Browse files
committed
merge-base: limit the output to bases that are on first-parent chain
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 <[email protected]>
1 parent 752b7b2 commit decc17f

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Documentation/git-merge-base.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-merge-base - Find as good common ancestors as possible for a merge
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git merge-base' [-a|--all] <commit> <commit>...
12+
'git merge-base' [-a|--all] [--fp-only] <commit> <commit>...
1313
'git merge-base' [-a|--all] --octopus <commit>...
1414
'git merge-base' --is-ancestor <commit> <commit>
1515
'git merge-base' --independent <commit>...
@@ -72,6 +72,12 @@ OPTIONS
7272
--all::
7373
Output all merge bases for the commits, instead of just one.
7474

75+
--fp-only::
76+
Limit the output to merge bases that are on the first-parent
77+
chain from none of the commits given on the command line.
78+
79+
80+
7581
DISCUSSION
7682
----------
7783

builtin/merge-base.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
#include "revision.h"
77
#include "parse-options.h"
88

9-
static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
9+
static int show_merge_base(struct commit **rev, int rev_nr, int show_all, int fp_only)
1010
{
1111
struct commit_list *result;
12+
unsigned flags = fp_only ? MB_FPCHAIN : 0;
1213

13-
result = get_merge_bases_many_dirty(rev[0], rev_nr - 1, rev + 1);
14+
result = get_merge_bases_opt(rev[0], rev_nr - 1, rev + 1, flags);
1415

1516
if (!result)
1617
return 1;
@@ -208,10 +209,13 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)
208209
struct commit **rev;
209210
int rev_nr = 0;
210211
int show_all = 0;
212+
int fp_only = 0;
211213
int cmdmode = 0;
212214

213215
struct option options[] = {
214216
OPT_BOOL('a', "all", &show_all, N_("output all common ancestors")),
217+
OPT_BOOL(0, "fp-only", &fp_only,
218+
N_("limit to bases that are on first-parent chain")),
215219
OPT_CMDMODE(0, "octopus", &cmdmode,
216220
N_("find ancestors for a single n-way merge"), 'o'),
217221
OPT_CMDMODE(0, "independent", &cmdmode,
@@ -255,5 +259,5 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)
255259
ALLOC_ARRAY(rev, argc);
256260
while (argc-- > 0)
257261
rev[rev_nr++] = get_commit_reference(*argv++);
258-
return show_merge_base(rev, rev_nr, show_all);
262+
return show_merge_base(rev, rev_nr, show_all, fp_only);
259263
}

0 commit comments

Comments
 (0)