notes: extract parse_notes_merge_strategy to notes-utils
Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jacob Keller committed
Aug 17, 2015 at 14:33 UTC
93efcad31777142840eaefc19b71d1a4b6a2fe24
3 files changed
+20
-11
builtin/notes.c
+1
-11
@@ -796,17 +796,7 @@ static int merge(int argc, const char **argv, const char *prefix)
796
o.remote_ref = remote_ref.buf;
797
798
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)) {
800
error("Unknown -s/--strategy: %s", strategy);
801
usage_with_options(git_notes_merge_usage, options);
802
}
notes-utils.c
+18
@@ -54,6 +54,24 @@ void commit_notes(struct notes_tree *t, const char *msg)
54
strbuf_release(&buf);
55
}
56
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
+
75
static combine_notes_fn parse_combine_notes_fn(const char *v)
76
{
77
if (!strcasecmp(v, "overwrite"))
notes-utils.h
+1
@@ -37,6 +37,7 @@ struct notes_rewrite_cfg {
37
int mode_from_env;
38
};
39
40
+int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s);
41
struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd);
42
int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
43
const unsigned char *from_obj, const unsigned char *to_obj);