Skip to content

Commit 93efcad

Browse files
jacob-kellergitster
authored andcommitted
notes: extract parse_notes_merge_strategy to notes-utils
Signed-off-by: Jacob Keller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4d03dd1 commit 93efcad

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

builtin/notes.c

+1-11
Original file line numberDiff line numberDiff line change
@@ -796,17 +796,7 @@ static int merge(int argc, const char **argv, const char *prefix)
796796
o.remote_ref = remote_ref.buf;
797797

798798
if (strategy) {
799-
if (!strcmp(strategy, "manual"))
800-
o.strategy = NOTES_MERGE_RESOLVE_MANUAL;
801-
else if (!strcmp(strategy, "ours"))
802-
o.strategy = NOTES_MERGE_RESOLVE_OURS;
803-
else if (!strcmp(strategy, "theirs"))
804-
o.strategy = NOTES_MERGE_RESOLVE_THEIRS;
805-
else if (!strcmp(strategy, "union"))
806-
o.strategy = NOTES_MERGE_RESOLVE_UNION;
807-
else if (!strcmp(strategy, "cat_sort_uniq"))
808-
o.strategy = NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ;
809-
else {
799+
if (parse_notes_merge_strategy(strategy, &o.strategy)) {
810800
error("Unknown -s/--strategy: %s", strategy);
811801
usage_with_options(git_notes_merge_usage, options);
812802
}

notes-utils.c

+18
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@ void commit_notes(struct notes_tree *t, const char *msg)
5454
strbuf_release(&buf);
5555
}
5656

57+
int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s)
58+
{
59+
if (!strcmp(v, "manual"))
60+
*s = NOTES_MERGE_RESOLVE_MANUAL;
61+
else if (!strcmp(v, "ours"))
62+
*s = NOTES_MERGE_RESOLVE_OURS;
63+
else if (!strcmp(v, "theirs"))
64+
*s = NOTES_MERGE_RESOLVE_THEIRS;
65+
else if (!strcmp(v, "union"))
66+
*s = NOTES_MERGE_RESOLVE_UNION;
67+
else if (!strcmp(v, "cat_sort_uniq"))
68+
*s = NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ;
69+
else
70+
return -1;
71+
72+
return 0;
73+
}
74+
5775
static combine_notes_fn parse_combine_notes_fn(const char *v)
5876
{
5977
if (!strcasecmp(v, "overwrite"))

notes-utils.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct notes_rewrite_cfg {
3737
int mode_from_env;
3838
};
3939

40+
int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s);
4041
struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd);
4142
int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
4243
const unsigned char *from_obj, const unsigned char *to_obj);

0 commit comments

Comments
 (0)