21
o->verbosity = NOTES_MERGE_VERBOSITY_DEFAULT;
22
}
23
24
-#define OUTPUT(o, v, ...) \
25
- do { \
26
- if ((o)->verbosity >= (v)) { \
27
- printf(__VA_ARGS__); \
28
- puts(""); \
29
- } \
30
- } while (0)
31
-
24
static int path_to_sha1(const char *path, unsigned char *sha1)
25
{
26
char hex_sha1[40];
384
385
strbuf_addf(&(o->commit_msg), "\t%s\n", sha1_to_hex(p->obj));
386
395
- OUTPUT(o, 2, "Auto-merging notes for %s", sha1_to_hex(p->obj));
387
+ if (o->verbosity >= 2)
388
+ printf("Auto-merging notes for %s\n", sha1_to_hex(p->obj));
389
check_notes_merge_worktree(o);
390
if (is_null_sha1(p->local)) {
391
/* D/F conflict, checkout p->remote */
392
assert(!is_null_sha1(p->remote));
400
- OUTPUT(o, 1, "CONFLICT (delete/modify): Notes for object %s "
401
- "deleted in %s and modified in %s. Version from %s "
402
- "left in tree.", sha1_to_hex(p->obj), lref, rref, rref);
393
+ if (o->verbosity >= 1)
394
+ printf("CONFLICT (delete/modify): Notes for object %s "
395
+ "deleted in %s and modified in %s. Version from %s "
396
+ "left in tree.\n",
397
+ sha1_to_hex(p->obj), lref, rref, rref);
398
write_note_to_worktree(p->obj, p->remote);
399
} else if (is_null_sha1(p->remote)) {
400
/* D/F conflict, checkout p->local */
401
assert(!is_null_sha1(p->local));
407
- OUTPUT(o, 1, "CONFLICT (delete/modify): Notes for object %s "
408
- "deleted in %s and modified in %s. Version from %s "
409
- "left in tree.", sha1_to_hex(p->obj), rref, lref, lref);
402
+ if (o->verbosity >= 1)
403
+ printf("CONFLICT (delete/modify): Notes for object %s "
404
+ "deleted in %s and modified in %s. Version from %s "
405
+ "left in tree.\n",
406
+ sha1_to_hex(p->obj), rref, lref, lref);
407
write_note_to_worktree(p->obj, p->local);
408
} else {
409
/* "regular" conflict, checkout result of ll_merge() */
412
reason = "add/add";
413
assert(!is_null_sha1(p->local));
414
assert(!is_null_sha1(p->remote));
418
- OUTPUT(o, 1, "CONFLICT (%s): Merge conflict in notes for "
419
- "object %s", reason, sha1_to_hex(p->obj));
415
+ if (o->verbosity >= 1)
416
+ printf("CONFLICT (%s): Merge conflict in notes for "
417
+ "object %s\n", reason, sha1_to_hex(p->obj));
418
ll_merge_in_worktree(o, p);
419
}
420
436
case NOTES_MERGE_RESOLVE_MANUAL:
437
return merge_one_change_manual(o, p, t);
438
case NOTES_MERGE_RESOLVE_OURS:
441
- OUTPUT(o, 2, "Using local notes for %s", sha1_to_hex(p->obj));
439
+ if (o->verbosity >= 2)
440
+ printf("Using local notes for %s\n",
441
+ sha1_to_hex(p->obj));
442
/* nothing to do */
443
return 0;
444
case NOTES_MERGE_RESOLVE_THEIRS:
445
- OUTPUT(o, 2, "Using remote notes for %s", sha1_to_hex(p->obj));
445
+ if (o->verbosity >= 2)
446
+ printf("Using remote notes for %s\n",
447
+ sha1_to_hex(p->obj));
448
if (add_note(t, p->obj, p->remote, combine_notes_overwrite))
449
die("BUG: combine_notes_overwrite failed");
450
return 0;
451
case NOTES_MERGE_RESOLVE_UNION:
450
- OUTPUT(o, 2, "Concatenating local and remote notes for %s",
451
- sha1_to_hex(p->obj));
452
+ if (o->verbosity >= 2)
453
+ printf("Concatenating local and remote notes for %s\n",
454
+ sha1_to_hex(p->obj));
455
if (add_note(t, p->obj, p->remote, combine_notes_concatenate))
456
die("failed to concatenate notes "
457
"(combine_notes_concatenate)");
458
return 0;
459
case NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ:
457
- OUTPUT(o, 2, "Concatenating unique lines in local and remote "
458
- "notes for %s", sha1_to_hex(p->obj));
460
+ if (o->verbosity >= 2)
461
+ printf("Concatenating unique lines in local and remote "
462
+ "notes for %s\n", sha1_to_hex(p->obj));
463
if (add_note(t, p->obj, p->remote, combine_notes_cat_sort_uniq))
464
die("failed to concatenate notes "
465
"(combine_notes_cat_sort_uniq)");
522
conflicts = merge_changes(o, changes, &num_changes, t);
523
free(changes);
524
521
- OUTPUT(o, 4, "Merge result: %i unmerged notes and a %s notes tree",
522
- conflicts, t->dirty ? "dirty" : "clean");
525
+ if (o->verbosity >= 4)
526
+ printf("Merge result: %i unmerged notes and a %s notes tree\n",
527
+ conflicts, t->dirty ? "dirty" : "clean");
528
529
return conflicts ? -1 : 1;
530
}
621
if (!bases) {
622
base_sha1 = null_sha1;
623
base_tree_sha1 = EMPTY_TREE_SHA1_BIN;
619
- OUTPUT(o, 4, "No merge base found; doing history-less merge");
624
+ if (o->verbosity >= 4)
625
+ printf("No merge base found; doing history-less merge\n");
626
} else if (!bases->next) {
627
base_sha1 = bases->item->object.sha1;
628
base_tree_sha1 = bases->item->tree->object.sha1;
623
- OUTPUT(o, 4, "One merge base found (%.7s)",
624
- sha1_to_hex(base_sha1));
629
+ if (o->verbosity >= 4)
630
+ printf("One merge base found (%.7s)\n",
631
+ sha1_to_hex(base_sha1));
632
} else {
633
/* TODO: How to handle multiple merge-bases? */
634
base_sha1 = bases->item->object.sha1;
635
base_tree_sha1 = bases->item->tree->object.sha1;
629
- OUTPUT(o, 3, "Multiple merge bases found. Using the first "
630
- "(%.7s)", sha1_to_hex(base_sha1));
636
+ if (o->verbosity >= 3)
637
+ printf("Multiple merge bases found. Using the first "
638
+ "(%.7s)\n", sha1_to_hex(base_sha1));
639
}
640
633
- OUTPUT(o, 4, "Merging remote commit %.7s into local commit %.7s with "
634
- "merge-base %.7s", sha1_to_hex(remote->object.sha1),
635
- sha1_to_hex(local->object.sha1), sha1_to_hex(base_sha1));
641
+ if (o->verbosity >= 4)
642
+ printf("Merging remote commit %.7s into local commit %.7s with "
643
+ "merge-base %.7s\n", sha1_to_hex(remote->object.sha1),
644
+ sha1_to_hex(local->object.sha1),
645
+ sha1_to_hex(base_sha1));
646
647
if (!hashcmp(remote->object.sha1, base_sha1)) {
648
/* Already merged; result == local commit */
639
- OUTPUT(o, 2, "Already up-to-date!");
649
+ if (o->verbosity >= 2)
650
+ printf("Already up-to-date!\n");
651
hashcpy(result_sha1, local->object.sha1);
652
goto found_result;
653
}
654
if (!hashcmp(local->object.sha1, base_sha1)) {
655
/* Fast-forward; result == remote commit */
645
- OUTPUT(o, 2, "Fast-forward");
656
+ if (o->verbosity >= 2)
657
+ printf("Fast-forward\n");
658
hashcpy(result_sha1, remote->object.sha1);
659
goto found_result;
660
}
696
int path_len = strlen(path), i;
697
const char *msg = strstr(partial_commit->buffer, "\n\n");
698
687
- OUTPUT(o, 3, "Committing notes in notes merge worktree at %.*s",
688
- path_len - 1, path);
699
+ if (o->verbosity >= 3)
700
+ printf("Committing notes in notes merge worktree at %.*s\n",
701
+ path_len - 1, path);
702
703
if (!msg || msg[2] == '\0')
704
die("partial notes commit has empty message");
713
unsigned char obj_sha1[20], blob_sha1[20];
714
715
if (ent->len - path_len != 40 || get_sha1_hex(relpath, obj_sha1)) {
703
- OUTPUT(o, 3, "Skipping non-SHA1 entry '%s'", ent->name);
716
+ if (o->verbosity >= 3)
717
+ printf("Skipping non-SHA1 entry '%s'\n",
718
+ ent->name);
719
continue;
720
}
721
727
if (add_note(partial_tree, obj_sha1, blob_sha1, NULL))
728
die("Failed to add resolved note '%s' to notes tree",
729
ent->name);
715
- OUTPUT(o, 4, "Added resolved note for object %s: %s",
716
- sha1_to_hex(obj_sha1), sha1_to_hex(blob_sha1));
730
+ if (o->verbosity >= 4)
731
+ printf("Added resolved note for object %s: %s\n",
732
+ sha1_to_hex(obj_sha1), sha1_to_hex(blob_sha1));
733
}
734
735
create_notes_commit(partial_tree, partial_commit->parents, msg,
736
result_sha1);
721
- OUTPUT(o, 4, "Finalized notes merge commit: %s",
722
- sha1_to_hex(result_sha1));
737
+ if (o->verbosity >= 4)
738
+ printf("Finalized notes merge commit: %s\n",
739
+ sha1_to_hex(result_sha1));
740
return 0;
741
}
742
747
int ret;
748
749
strbuf_addstr(&buf, git_path(NOTES_MERGE_WORKTREE));
733
- OUTPUT(o, 3, "Removing notes merge worktree at %s", buf.buf);
750
+ if (o->verbosity >= 3)
751
+ printf("Removing notes merge worktree at %s\n", buf.buf);
752
ret = remove_dir_recursively(&buf, 0);
753
strbuf_release(&buf);
754
return ret;