Skip to content

Commit 26cc188

Browse files
committed
merge: allow to use only the fp-only merge bases
Teach "git merge" a new option "--fp-base-only" that tells it to consider only merge bases that are on the first-parent chain. This speeds up back-merges needed in the topic branch workflow. The merge of 'master' back into 'next' used as an example in the RFD article <[email protected]>, i.e. git checkout 4868def && git merge 6598894 in our history takes about 1.22-1.33 seconds without the series, while running the latter "git merge" with the "--fp-base-only" option takes about 0.54-0.59 seconds. Signed-off-by: Junio C Hamano <[email protected]>
1 parent decc17f commit 26cc188

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

Documentation/merge-options.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ ifndef::git-pull[]
116116
Note that not all merge strategies may support progress
117117
reporting.
118118

119+
--fp-base-only::
120+
Instead of using all merge bases when computing the
121+
three-way merge result, use only the merge bases on the
122+
first-parent chain of the commits being merged. This
123+
experimental feature is meant to be used when merging an
124+
older integration branch back to a newer integration branch
125+
in the topic-branch workflow.
126+
127+
119128
endif::git-pull[]
120129

121130
--allow-unrelated-histories::

builtin/merge.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ enum ff_type {
8888

8989
static enum ff_type fast_forward = FF_ALLOW;
9090

91+
static int fp_base_only;
92+
9193
static int option_parse_message(const struct option *opt,
9294
const char *arg, int unset)
9395
{
@@ -210,6 +212,8 @@ static struct option builtin_merge_options[] = {
210212
{ OPTION_SET_INT, 0, "ff-only", &fast_forward, NULL,
211213
N_("abort if fast-forward is not possible"),
212214
PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, FF_ONLY },
215+
OPT_BOOL(0, "fp-base-only", &fp_base_only,
216+
N_("use only merge bases on first-parent chain")),
213217
OPT_RERERE_AUTOUPDATE(&allow_rerere_auto),
214218
OPT_BOOL(0, "verify-signatures", &verify_signatures,
215219
N_("verify that the named commit has a valid GPG signature")),
@@ -1340,9 +1344,14 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13401344

13411345
if (!remoteheads)
13421346
; /* already up-to-date */
1343-
else if (!remoteheads->next)
1344-
common = get_merge_bases(head_commit, remoteheads->item);
1345-
else {
1347+
else if (!remoteheads->next) {
1348+
unsigned flags = MB_POSTCLEAN;
1349+
if (fp_base_only)
1350+
flags |= MB_FPCHAIN;
1351+
common = get_merge_bases_opt(head_commit,
1352+
1, &remoteheads->item,
1353+
flags);
1354+
} else {
13461355
struct commit_list *list = remoteheads;
13471356
commit_list_insert(head_commit, &list);
13481357
common = get_octopus_merge_bases(list);

0 commit comments

Comments
 (0)