aboutsummaryrefslogtreecommitdiff
path: root/builtin/notes.c
diff options
context:
space:
mode:
authorJohan Herland <johan@herland.net>2010-11-15 00:55:12 +0100
committerJunio C Hamano <gitster@pobox.com>2010-11-17 13:21:58 -0800
commit3228e67120a8c71bf7804a5c52448a841d6f3b58 (patch)
tree7cd1562259a3942cc2811c2a4f557d077649698a /builtin/notes.c
parent2085b16aefdbb1dc081aa40c62eb8110a222731d (diff)
downloadgit-3228e67120a8c71bf7804a5c52448a841d6f3b58.tar.gz
git-3228e67120a8c71bf7804a5c52448a841d6f3b58.tar.xz
git notes merge: Add automatic conflict resolvers (ours, theirs, union)
The new -s/--strategy command-line option to 'git notes merge' allow the user to choose how notes merge conflicts should be resolved. There are four valid strategies to choose from: 1. "manual" (the default): This will let the user manually resolve conflicts. This option currently fails with an error message. It will be implemented properly in future patches. 2. "ours": This automatically chooses the local version of a conflict, and discards the remote version. 3. "theirs": This automatically chooses the remote version of a conflict, and discards the local version. 4. "union": This automatically resolves the conflict by appending the remote version to the local version. The strategies are implemented using the combine_notes_* functions from the notes.h API. The patch also includes testcases verifying the correct implementation of these strategies. This patch has been improved by the following contributions: - Jonathan Nieder: Future-proof by always checking add_note() return value - Stephen Boyd: Use test_commit - Stephen Boyd: Use correct option name Thanks-to: Jonathan Nieder <jrnieder@gmail.com> Thanks-to: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/notes.c')
-rw-r--r--builtin/notes.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/builtin/notes.c b/builtin/notes.c
index c7761b114..64b2be97e 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -26,7 +26,7 @@ static const char * const git_notes_usage[] = {
"git notes [--ref <notes_ref>] append [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]",
"git notes [--ref <notes_ref>] edit [<object>]",
"git notes [--ref <notes_ref>] show [<object>]",
- "git notes [--ref <notes_ref>] merge [-v | -q] <notes_ref>",
+ "git notes [--ref <notes_ref>] merge [-v | -q] [-s <strategy> ] <notes_ref>",
"git notes [--ref <notes_ref>] remove [<object>]",
"git notes [--ref <notes_ref>] prune [-n | -v]",
NULL
@@ -768,8 +768,12 @@ static int merge(int argc, const char **argv, const char *prefix)
struct notes_tree *t;
struct notes_merge_options o;
int verbosity = 0, result;
+ const char *strategy = NULL;
struct option options[] = {
OPT__VERBOSITY(&verbosity),
+ OPT_STRING('s', "strategy", &strategy, "strategy",
+ "resolve notes conflicts using the given "
+ "strategy (manual/ours/theirs/union)"),
OPT_END()
};
@@ -789,6 +793,21 @@ static int merge(int argc, const char **argv, const char *prefix)
expand_notes_ref(&remote_ref);
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 {
+ error("Unknown -s/--strategy: %s", strategy);
+ usage_with_options(git_notes_merge_usage, options);
+ }
+ }
+
t = init_notes_check("merge");
strbuf_addf(&msg, "notes: Merged notes from %s into %s",