From 93efcad31777142840eaefc19b71d1a4b6a2fe24 Mon Sep 17 00:00:00 2001 From: Jacob Keller Date: Mon, 17 Aug 2015 14:33:31 -0700 Subject: notes: extract parse_notes_merge_strategy to notes-utils Signed-off-by: Jacob Keller Signed-off-by: Junio C Hamano --- builtin/notes.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'builtin/notes.c') diff --git a/builtin/notes.c b/builtin/notes.c index 63f95fc554..29816f9fbb 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -796,17 +796,7 @@ static int merge(int argc, const char **argv, const char *prefix) o.remote_ref = remote_ref.buf; if (strategy) { - if (!strcmp(strategy, "manual")) - o.strategy = NOTES_MERGE_RESOLVE_MANUAL; - else if (!strcmp(strategy, "ours")) - o.strategy = NOTES_MERGE_RESOLVE_OURS; - else if (!strcmp(strategy, "theirs")) - o.strategy = NOTES_MERGE_RESOLVE_THEIRS; - else if (!strcmp(strategy, "union")) - o.strategy = NOTES_MERGE_RESOLVE_UNION; - else if (!strcmp(strategy, "cat_sort_uniq")) - o.strategy = NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ; - else { + if (parse_notes_merge_strategy(strategy, &o.strategy)) { error("Unknown -s/--strategy: %s", strategy); usage_with_options(git_notes_merge_usage, options); } -- cgit v1.2.1 From d2d68d9975da4a15dfca0e6e59001948e5bf57f9 Mon Sep 17 00:00:00 2001 From: Jacob Keller Date: Mon, 17 Aug 2015 14:33:33 -0700 Subject: notes: add notes.mergeStrategy option to select default strategy Teach git-notes about "notes.mergeStrategy" to select a general strategy for all notes merges. This enables a user to always get expected merge strategy such as "cat_sort_uniq" without having to pass the "-s" option manually. Signed-off-by: Jacob Keller Signed-off-by: Junio C Hamano --- builtin/notes.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'builtin/notes.c') diff --git a/builtin/notes.c b/builtin/notes.c index 29816f9fbb..9026d567cd 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -737,6 +737,19 @@ static int merge_commit(struct notes_merge_options *o) return ret; } +static int git_config_get_notes_strategy(const char *key, + enum notes_merge_strategy *strategy) +{ + const char *value; + + if (git_config_get_string_const(key, &value)) + return 1; + if (parse_notes_merge_strategy(value, strategy)) + git_die_config(key, "unknown notes merge strategy %s", value); + + return 0; +} + static int merge(int argc, const char **argv, const char *prefix) { struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT; @@ -795,15 +808,17 @@ static int merge(int argc, const char **argv, const char *prefix) expand_notes_ref(&remote_ref); o.remote_ref = remote_ref.buf; + t = init_notes_check("merge"); + if (strategy) { if (parse_notes_merge_strategy(strategy, &o.strategy)) { error("Unknown -s/--strategy: %s", strategy); usage_with_options(git_notes_merge_usage, options); } + } else { + git_config_get_notes_strategy("notes.mergeStrategy", &o.strategy); } - t = init_notes_check("merge"); - strbuf_addf(&msg, "notes: Merged notes from %s into %s", remote_ref.buf, default_notes_ref()); strbuf_add(&(o.commit_msg), msg.buf + 7, msg.len - 7); /* skip "notes: " */ -- cgit v1.2.1 From 4f655e22b76fed49b0c32bcdcd899934215b9a6d Mon Sep 17 00:00:00 2001 From: Jacob Keller Date: Mon, 17 Aug 2015 14:33:34 -0700 Subject: notes: teach git-notes about notes..mergeStrategy option Teach notes about a new "notes..mergeStrategy" option for configuring the notes merge strategy when merging into refs/notes/. This option allows for the selection of merge strategy for particular notes refs, rather than all notes ref merges, as user may not want cat_sort_uniq for all refs, but only some. Note that the is the local reference we are merging into, not the remote ref we merged from. The assumption is that users will mostly want to configure separate local ref merge strategies rather than strategies depending on which remote ref they merge from. notes..mergeStrategy overrides the general behavior as it is more specific. Signed-off-by: Jacob Keller Signed-off-by: Junio C Hamano --- builtin/notes.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'builtin/notes.c') diff --git a/builtin/notes.c b/builtin/notes.c index 9026d567cd..ebd3e62e87 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -816,7 +816,19 @@ static int merge(int argc, const char **argv, const char *prefix) usage_with_options(git_notes_merge_usage, options); } } else { - git_config_get_notes_strategy("notes.mergeStrategy", &o.strategy); + struct strbuf merge_key = STRBUF_INIT; + const char *short_ref = NULL; + + if (!skip_prefix(o.local_ref, "refs/notes/", &short_ref)) + die("BUG: local ref %s is outside of refs/notes/", + o.local_ref); + + strbuf_addf(&merge_key, "notes.%s.mergeStrategy", short_ref); + + if (git_config_get_notes_strategy(merge_key.buf, &o.strategy)) + git_config_get_notes_strategy("notes.mergeStrategy", &o.strategy); + + strbuf_release(&merge_key); } strbuf_addf(&msg, "notes: Merged notes from %s into %s", -- cgit v1.2.1