Skip to content

Commit b182658

Browse files
committed
merge: introduce {copy|clear}_merge_options()
When mostly the same set of options are to be used to perform multiple merges, one instance of the merge_options structure may want to be created and used by copying from the same template instance. We saw such a use recently in "git merge-tree". Let's make the pattern official by introducing copy_merge_options() as a supported way to make a copy of the structure, and also give clear_merge_options() to release any resources held by a copied instance. Currently we only make a shallow copy, so the former is a mere structure assignment while the latter is a no-op, but this may change in the future as the members of merge_options structure evolve. Suggested-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6a4c9e7 commit b182658

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

builtin/merge-tree.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,11 @@ static int real_merge(struct merge_tree_options *o,
425425
{
426426
struct commit *parent1, *parent2;
427427
struct commit_list *merge_bases = NULL;
428-
struct merge_options opt = o->merge_options;
429428
struct merge_result result = { 0 };
430429
int show_messages = o->show_messages;
430+
struct merge_options opt;
431431

432+
copy_merge_options(&opt, &o->merge_options);
432433
parent1 = get_merge_parent(branch1);
433434
if (!parent1)
434435
help_unknown_ref(branch1, "merge-tree",
@@ -507,6 +508,7 @@ static int real_merge(struct merge_tree_options *o,
507508
if (o->use_stdin)
508509
putchar(line_termination);
509510
merge_finalize(&opt, &result);
511+
clear_merge_options(&opt);
510512
return !result.clean; /* result.clean < 0 handled above */
511513
}
512514

merge-recursive.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3912,6 +3912,22 @@ void init_merge_options(struct merge_options *opt,
39123912
opt->buffer_output = 0;
39133913
}
39143914

3915+
/*
3916+
* For now, members of merge_options do not need deep copying, but
3917+
* it may change in the future, in which case we would need to update
3918+
* this, and also make a matching change to clear_merge_options() to
3919+
* release the resources held by a copied instance.
3920+
*/
3921+
void copy_merge_options(struct merge_options *dst, struct merge_options *src)
3922+
{
3923+
*dst = *src;
3924+
}
3925+
3926+
void clear_merge_options(struct merge_options *opt UNUSED)
3927+
{
3928+
; /* no-op as our copy is shallow right now */
3929+
}
3930+
39153931
int parse_merge_opt(struct merge_options *opt, const char *s)
39163932
{
39173933
const char *arg;

merge-recursive.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ struct merge_options {
5555

5656
void init_merge_options(struct merge_options *opt, struct repository *repo);
5757

58+
void copy_merge_options(struct merge_options *dst, struct merge_options *src);
59+
void clear_merge_options(struct merge_options *opt);
60+
5861
/* parse the option in s and update the relevant field of opt */
5962
int parse_merge_opt(struct merge_options *opt, const char *s);
6063

0 commit comments

Comments
 (0)