@matheusbsbs / matheus-bagliano / commits / 443259cf92
Fork 0

git notes merge: List conflicting notes in notes merge commit message

This brings notes merge in line with regular merge's behaviour. This patch has been improved by the following contributions: - Ævar Arnfjörð Bjarmason: Don't use C99 comments. Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johan Herland committed Nov 9, 2010 at 22:49 UTC 443259cf929c0041310e3c77946252cbfc3f787d
4 files changed +24 -3
builtin/notes.c
+1 -1
@@ -902,7 +902,7 @@ static int merge(int argc, const char **argv, const char *prefix)
902
903 strbuf_addf(&msg, "notes: Merged notes from %s into %s",
904 remote_ref.buf, default_notes_ref());
905 - o.commit_msg = msg.buf + 7; // skip "notes: " prefix
905 + strbuf_add(&(o.commit_msg), msg.buf + 7, msg.len - 7); /* skip "notes: " */
906
907 result = notes_merge(&o, t, result_sha1);
908
notes-merge.c
+10 -1
@@ -8,6 +8,7 @@
8 #include "dir.h"
9 #include "notes.h"
10 #include "notes-merge.h"
11 +#include "strbuf.h"
12
13 struct notes_merge_pair {
14 unsigned char obj[20], base[20], local[20], remote[20];
@@ -16,6 +17,7 @@ struct notes_merge_pair {
17 void init_notes_merge_options(struct notes_merge_options *o)
18 {
19 memset(o, 0, sizeof(struct notes_merge_options));
20 + strbuf_init(&(o->commit_msg), 0);
21 o->verbosity = NOTES_MERGE_VERBOSITY_DEFAULT;
22 }
23
@@ -384,6 +386,12 @@ static int merge_one_change_manual(struct notes_merge_options *o,
386 sha1_to_hex(p->obj), sha1_to_hex(p->base),
387 sha1_to_hex(p->local), sha1_to_hex(p->remote));
388
389 + /* add "Conflicts:" section to commit message first time through */
390 + if (!o->has_worktree)
391 + strbuf_addstr(&(o->commit_msg), "\n\nConflicts:\n");
392 +
393 + strbuf_addf(&(o->commit_msg), "\t%s\n", sha1_to_hex(p->obj));
394 +
395 OUTPUT(o, 2, "Auto-merging notes for %s", sha1_to_hex(p->obj));
396 check_notes_merge_worktree(o);
397 if (is_null_sha1(p->local)) {
@@ -640,12 +648,13 @@ int notes_merge(struct notes_merge_options *o,
648 struct commit_list *parents = NULL;
649 commit_list_insert(remote, &parents); /* LIFO order */
650 commit_list_insert(local, &parents);
643 - create_notes_commit(local_tree, parents, o->commit_msg,
651 + create_notes_commit(local_tree, parents, o->commit_msg.buf,
652 result_sha1);
653 }
654
655 found_result:
656 free_commit_list(bases);
657 + strbuf_release(&(o->commit_msg));
658 trace_printf("notes_merge(): result = %i, result_sha1 = %.7s\n",
659 result, sha1_to_hex(result_sha1));
660 return result;
notes-merge.h
+1 -1
@@ -11,7 +11,7 @@ enum notes_merge_verbosity {
11 struct notes_merge_options {
12 const char *local_ref;
13 const char *remote_ref;
14 - const char *commit_msg;
14 + struct strbuf commit_msg;
15 int verbosity;
16 enum {
17 NOTES_MERGE_RESOLVE_MANUAL = 0,
t/t3310-notes-merge-manual-resolve.sh
+12
@@ -333,6 +333,12 @@ EOF
333 git log -1 --format=%B refs/notes/m > merge_commit_msg &&
334 grep -q refs/notes/m merge_commit_msg &&
335 grep -q refs/notes/z merge_commit_msg &&
336 + # Merge commit mentions conflicting notes
337 + grep -q "Conflicts" merge_commit_msg &&
338 + ( for sha1 in $(cat expect_conflicts); do
339 + grep -q "$sha1" merge_commit_msg ||
340 + exit 1
341 + done ) &&
342 # Verify contents of merge result
343 verify_notes m &&
344 # Verify that other notes refs has not changed (w, x, y and z)
@@ -456,6 +462,12 @@ EOF
462 git log -1 --format=%B refs/notes/m > merge_commit_msg &&
463 grep -q refs/notes/m merge_commit_msg &&
464 grep -q refs/notes/z merge_commit_msg &&
465 + # Merge commit mentions conflicting notes
466 + grep -q "Conflicts" merge_commit_msg &&
467 + ( for sha1 in $(cat expect_conflicts); do
468 + grep -q "$sha1" merge_commit_msg ||
469 + exit 1
470 + done ) &&
471 # Verify contents of merge result
472 verify_notes m &&
473 # Verify that other notes refs has not changed (w, x, y and z)