mirror of
https://github.com/git/git.git
synced 2024-05-12 00:06:36 +02:00
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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
6a4c9e7b32
commit
b182658e3e
|
@ -425,10 +425,11 @@ static int real_merge(struct merge_tree_options *o,
|
|||
{
|
||||
struct commit *parent1, *parent2;
|
||||
struct commit_list *merge_bases = NULL;
|
||||
struct merge_options opt = o->merge_options;
|
||||
struct merge_result result = { 0 };
|
||||
int show_messages = o->show_messages;
|
||||
struct merge_options opt;
|
||||
|
||||
copy_merge_options(&opt, &o->merge_options);
|
||||
parent1 = get_merge_parent(branch1);
|
||||
if (!parent1)
|
||||
help_unknown_ref(branch1, "merge-tree",
|
||||
|
@ -507,6 +508,7 @@ static int real_merge(struct merge_tree_options *o,
|
|||
if (o->use_stdin)
|
||||
putchar(line_termination);
|
||||
merge_finalize(&opt, &result);
|
||||
clear_merge_options(&opt);
|
||||
return !result.clean; /* result.clean < 0 handled above */
|
||||
}
|
||||
|
||||
|
|
|
@ -3912,6 +3912,22 @@ void init_merge_options(struct merge_options *opt,
|
|||
opt->buffer_output = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* For now, members of merge_options do not need deep copying, but
|
||||
* it may change in the future, in which case we would need to update
|
||||
* this, and also make a matching change to clear_merge_options() to
|
||||
* release the resources held by a copied instance.
|
||||
*/
|
||||
void copy_merge_options(struct merge_options *dst, struct merge_options *src)
|
||||
{
|
||||
*dst = *src;
|
||||
}
|
||||
|
||||
void clear_merge_options(struct merge_options *opt UNUSED)
|
||||
{
|
||||
; /* no-op as our copy is shallow right now */
|
||||
}
|
||||
|
||||
int parse_merge_opt(struct merge_options *opt, const char *s)
|
||||
{
|
||||
const char *arg;
|
||||
|
|
|
@ -55,6 +55,9 @@ struct merge_options {
|
|||
|
||||
void init_merge_options(struct merge_options *opt, struct repository *repo);
|
||||
|
||||
void copy_merge_options(struct merge_options *dst, struct merge_options *src);
|
||||
void clear_merge_options(struct merge_options *opt);
|
||||
|
||||
/* parse the option in s and update the relevant field of opt */
|
||||
int parse_merge_opt(struct merge_options *opt, const char *s);
|
||||
|
||||
|
|
Loading…
Reference in New Issue