Skip to content

Commit c531eab

Browse files
committed
merge-recursive: add merge function arg to merge_recursive_generic
The `merge_recursive_generic` function is a wrapper that allows running a merge on trees (rather than commits) by wrapping the trees as virtual commits. This functionality is valuable not only for use with `merge_recursive`, but also `merge_ort_recursive`. Having the merge function used by `merge_recursive_generic` be an argument allows greater flexibility of usage. Signed-off-by: Victoria Dye <[email protected]>
1 parent 46fab37 commit c531eab

File tree

6 files changed

+15
-7
lines changed

6 files changed

+15
-7
lines changed

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
15851585
if (state->quiet)
15861586
o.verbosity = 0;
15871587

1588-
if (merge_recursive_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {
1588+
if (merge_recursive_generic(&o, &our_tree, &their_tree, 1, bases, merge_recursive, &result)) {
15891589
repo_rerere(the_repository, state->allow_rerere_autoupdate);
15901590
free(their_tree_name);
15911591
return error(_("Failed to merge in the changes."));

builtin/merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
8181
if (o.verbosity >= 3)
8282
printf(_("Merging %s with %s\n"), o.branch1, o.branch2);
8383

84-
failed = merge_recursive_generic(&o, &h1, &h2, bases_count, bases, &result);
84+
failed = merge_recursive_generic(&o, &h1, &h2, bases_count, bases, merge_recursive, &result);
8585

8686
free(better1);
8787
free(better2);

builtin/stash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
541541
bases[0] = &info->b_tree;
542542

543543
ret = merge_recursive_generic(&o, &c_tree, &info->w_tree, 1, bases,
544-
&result);
544+
merge_recursive, &result);
545545
if (ret) {
546546
rerere(0);
547547

merge-ort.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4652,7 +4652,8 @@ void merge_incore_recursive(struct merge_options *opt,
46524652
trace2_region_enter("merge", "incore_recursive", opt->repo);
46534653

46544654
/* We set the ancestor label based on the merge_bases */
4655-
assert(opt->ancestor == NULL);
4655+
assert(opt->ancestor == NULL ||
4656+
!strcmp(opt->ancestor, "constructed merge base"));
46564657

46574658
trace2_region_enter("merge", "merge_start", opt->repo);
46584659
merge_start(opt, result);

merge-recursive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3785,6 +3785,7 @@ int merge_recursive_generic(struct merge_options *opt,
37853785
const struct object_id *merge,
37863786
int num_merge_bases,
37873787
const struct object_id **merge_bases,
3788+
recursive_merge_fn_t merge_fn,
37883789
struct commit **result)
37893790
{
37903791
int clean;
@@ -3808,8 +3809,7 @@ int merge_recursive_generic(struct merge_options *opt,
38083809
}
38093810

38103811
repo_hold_locked_index(opt->repo, &lock, LOCK_DIE_ON_ERROR);
3811-
clean = merge_recursive(opt, head_commit, next_commit, ca,
3812-
result);
3812+
clean = merge_fn(opt, head_commit, next_commit, ca, result);
38133813
if (clean < 0) {
38143814
rollback_lock_file(&lock);
38153815
return clean;

merge-recursive.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ struct merge_options {
5151
struct merge_options_internal *priv;
5252
};
5353

54+
typedef int (*recursive_merge_fn_t)(struct merge_options *opt,
55+
struct commit *h1,
56+
struct commit *h2,
57+
struct commit_list *merge_bases,
58+
struct commit **result);
59+
5460
void init_merge_options(struct merge_options *opt, struct repository *repo);
5561

5662
/* parse the option in s and update the relevant field of opt */
@@ -103,7 +109,7 @@ int merge_recursive(struct merge_options *opt,
103109

104110
/*
105111
* merge_recursive_generic can operate on trees instead of commits, by
106-
* wrapping the trees into virtual commits, and calling merge_recursive().
112+
* wrapping the trees into virtual commits, and calling the provided merge_fn.
107113
* It also writes out the in-memory index to disk if the merge is successful.
108114
*
109115
* Outputs:
@@ -118,6 +124,7 @@ int merge_recursive_generic(struct merge_options *opt,
118124
const struct object_id *merge,
119125
int num_merge_bases,
120126
const struct object_id **merge_bases,
127+
recursive_merge_fn_t merge_fn,
121128
struct commit **result);
122129

123130
#endif

0 commit comments

Comments
 (0)