71
static struct path_list current_directory_set = {NULL, 0, 0, 1};
72
73
static int call_depth = 0;
74
+static int verbosity = 2;
75
75
-static void output(const char *fmt, ...)
76
+static int show (int v)
77
+{
78
+ return (!call_depth && verbosity >= v) || verbosity >= 5;
79
+}
80
+
81
+static void output(int v, const char *fmt, ...)
82
{
83
va_list args;
78
- int i;
79
- for (i = call_depth; i--;)
80
- fputs(" ", stdout);
84
va_start(args, fmt);
82
- vfprintf(stdout, fmt, args);
85
+ if (show(v)) {
86
+ int i;
87
+ for (i = call_depth; i--;)
88
+ fputs(" ", stdout);
89
+ vfprintf(stdout, fmt, args);
90
+ fputc('\n', stdout);
91
+ }
92
va_end(args);
84
- fputc('\n', stdout);
93
}
94
95
static void output_commit_title(struct commit *commit)
648
const char *dst_name2 = ren2_dst;
649
if (path_list_has_path(¤t_directory_set, ren1_dst)) {
650
dst_name1 = del[delp++] = unique_path(ren1_dst, branch1);
643
- output("%s is a directory in %s adding as %s instead",
651
+ output(1, "%s is a directory in %s adding as %s instead",
652
ren1_dst, branch2, dst_name1);
653
remove_file(0, ren1_dst, 0);
654
}
655
if (path_list_has_path(¤t_directory_set, ren2_dst)) {
656
dst_name2 = del[delp++] = unique_path(ren2_dst, branch2);
649
- output("%s is a directory in %s adding as %s instead",
657
+ output(1, "%s is a directory in %s adding as %s instead",
658
ren2_dst, branch1, dst_name2);
659
remove_file(0, ren2_dst, 0);
660
}
668
const char *branch1)
669
{
670
char *new_path = unique_path(ren1->pair->two->path, branch1);
663
- output("Renaming %s to %s instead", ren1->pair->one->path, new_path);
671
+ output(1, "Renaming %s to %s instead", ren1->pair->one->path, new_path);
672
remove_file(0, ren1->pair->two->path, 0);
673
update_file(0, ren1->pair->two->sha1, ren1->pair->two->mode, new_path);
674
free(new_path);
681
{
682
char *new_path1 = unique_path(ren1->pair->two->path, branch1);
683
char *new_path2 = unique_path(ren2->pair->two->path, branch2);
676
- output("Renaming %s to %s and %s to %s instead",
684
+ output(1, "Renaming %s to %s and %s to %s instead",
685
ren1->pair->one->path, new_path1,
686
ren2->pair->one->path, new_path2);
687
remove_file(0, ren1->pair->two->path, 0);
774
ren2->processed = 1;
775
if (strcmp(ren1_dst, ren2_dst) != 0) {
776
clean_merge = 0;
769
- output("CONFLICT (rename/rename): "
777
+ output(1, "CONFLICT (rename/rename): "
778
"Rename %s->%s in branch %s "
779
"rename %s->%s in %s",
780
src, ren1_dst, branch1,
789
branch1,
790
branch2);
791
if (mfi.merge || !mfi.clean)
784
- output("Renaming %s->%s", src, ren1_dst);
792
+ output(1, "Renaming %s->%s", src, ren1_dst);
793
794
if (mfi.merge)
787
- output("Auto-merging %s", ren1_dst);
795
+ output(2, "Auto-merging %s", ren1_dst);
796
797
if (!mfi.clean) {
790
- output("CONFLICT (content): merge conflict in %s",
798
+ output(1, "CONFLICT (content): merge conflict in %s",
799
ren1_dst);
800
clean_merge = 0;
801
826
827
if (path_list_has_path(¤t_directory_set, ren1_dst)) {
828
clean_merge = 0;
821
- output("CONFLICT (rename/directory): Rename %s->%s in %s "
829
+ output(1, "CONFLICT (rename/directory): Rename %s->%s in %s "
830
" directory %s added in %s",
831
ren1_src, ren1_dst, branch1,
832
ren1_dst, branch2);
833
conflict_rename_dir(ren1, branch1);
834
} else if (sha_eq(src_other.sha1, null_sha1)) {
835
clean_merge = 0;
828
- output("CONFLICT (rename/delete): Rename %s->%s in %s "
836
+ output(1, "CONFLICT (rename/delete): Rename %s->%s in %s "
837
"and deleted in %s",
838
ren1_src, ren1_dst, branch1,
839
branch2);
842
const char *new_path;
843
clean_merge = 0;
844
try_merge = 1;
837
- output("CONFLICT (rename/add): Rename %s->%s in %s. "
845
+ output(1, "CONFLICT (rename/add): Rename %s->%s in %s. "
846
"%s added in %s",
847
ren1_src, ren1_dst, branch1,
848
ren1_dst, branch2);
849
new_path = unique_path(ren1_dst, branch2);
842
- output("Adding as %s instead", new_path);
850
+ output(1, "Adding as %s instead", new_path);
851
update_file(0, dst_other.sha1, dst_other.mode, new_path);
852
} else if ((item = path_list_lookup(ren1_dst, renames2Dst))) {
853
ren2 = item->util;
854
clean_merge = 0;
855
ren2->processed = 1;
848
- output("CONFLICT (rename/rename): Rename %s->%s in %s. "
856
+ output(1, "CONFLICT (rename/rename): Rename %s->%s in %s. "
857
"Rename %s->%s in %s",
858
ren1_src, ren1_dst, branch1,
859
ren2->pair->one->path, ren2->pair->two->path, branch2);
878
a_branch, b_branch);
879
880
if (mfi.merge || !mfi.clean)
873
- output("Renaming %s => %s", ren1_src, ren1_dst);
881
+ output(1, "Renaming %s => %s", ren1_src, ren1_dst);
882
if (mfi.merge)
875
- output("Auto-merging %s", ren1_dst);
883
+ output(2, "Auto-merging %s", ren1_dst);
884
if (!mfi.clean) {
877
- output("CONFLICT (rename/modify): Merge conflict in %s",
885
+ output(1, "CONFLICT (rename/modify): Merge conflict in %s",
886
ren1_dst);
887
clean_merge = 0;
888
930
/* Deleted in both or deleted in one and
931
* unchanged in the other */
932
if (a_sha)
925
- output("Removing %s", path);
933
+ output(2, "Removing %s", path);
934
/* do not touch working file if it did not exist */
935
remove_file(1, path, !a_sha);
936
} else {
937
/* Deleted in one and changed in the other */
938
clean_merge = 0;
939
if (!a_sha) {
932
- output("CONFLICT (delete/modify): %s deleted in %s "
940
+ output(1, "CONFLICT (delete/modify): %s deleted in %s "
941
"and modified in %s. Version %s of %s left in tree.",
942
path, branch1,
943
branch2, branch2, path);
944
update_file(0, b_sha, b_mode, path);
945
} else {
938
- output("CONFLICT (delete/modify): %s deleted in %s "
946
+ output(1, "CONFLICT (delete/modify): %s deleted in %s "
947
"and modified in %s. Version %s of %s left in tree.",
948
path, branch2,
949
branch1, branch1, path);
976
if (path_list_has_path(¤t_directory_set, path)) {
977
const char *new_path = unique_path(path, add_branch);
978
clean_merge = 0;
971
- output("CONFLICT (%s): There is a directory with name %s in %s. "
979
+ output(1, "CONFLICT (%s): There is a directory with name %s in %s. "
980
"Adding %s as %s",
981
conf, path, other_branch, path, new_path);
982
remove_file(0, path, 0);
983
update_file(0, sha, mode, new_path);
984
} else {
977
- output("Adding %s", path);
985
+ output(2, "Adding %s", path);
986
update_file(1, sha, mode, path);
987
}
988
} else if (a_sha && b_sha) {
996
reason = "add/add";
997
o_sha = (unsigned char *)null_sha1;
998
}
991
- output("Auto-merging %s", path);
999
+ output(2, "Auto-merging %s", path);
1000
o.path = a.path = b.path = (char *)path;
1001
hashcpy(o.sha1, o_sha);
1002
o.mode = o_mode;
1012
update_file(1, mfi.sha, mfi.mode, path);
1013
else {
1014
clean_merge = 0;
1007
- output("CONFLICT (%s): Merge conflict in %s",
1015
+ output(1, "CONFLICT (%s): Merge conflict in %s",
1016
reason, path);
1017
1018
if (index_only)
1036
{
1037
int code, clean;
1038
if (sha_eq(common->object.sha1, merge->object.sha1)) {
1031
- output("Already uptodate!");
1039
+ output(0, "Already uptodate!");
1040
*result = head;
1041
return 1;
1042
}
1111
struct tree *mrtree;
1112
int clean;
1113
1106
- output("Merging:");
1107
- output_commit_title(h1);
1108
- output_commit_title(h2);
1114
+ if (show(4)) {
1115
+ output(4, "Merging:");
1116
+ output_commit_title(h1);
1117
+ output_commit_title(h2);
1118
+ }
1119
1120
if (!ca) {
1121
ca = get_merge_bases(h1, h2, 1);
1122
ca = reverse_commit_list(ca);
1123
}
1124
1115
- output("found %u common ancestor(s):", commit_list_count(ca));
1116
- for (iter = ca; iter; iter = iter->next)
1117
- output_commit_title(iter->item);
1125
+ if (show(5)) {
1126
+ output(5, "found %u common ancestor(s):", commit_list_count(ca));
1127
+ for (iter = ca; iter; iter = iter->next)
1128
+ output_commit_title(iter->item);
1129
+ }
1130
1131
merged_common_ancestors = pop_commit(&ca);
1132
if (merged_common_ancestors == NULL) {
1208
return (struct commit *)object;
1209
}
1210
1211
+static int merge_config(const char *var, const char *value)
1212
+{
1213
+ if (!strcasecmp(var, "merge.verbosity")) {
1214
+ verbosity = git_config_int(var, value);
1215
+ return 0;
1216
+ }
1217
+ return git_default_config(var, value);
1218
+}
1219
+
1220
int main(int argc, char *argv[])
1221
{
1222
static const char *bases[20];
1228
struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
1229
int index_fd;
1230
1210
- git_config(git_default_config); /* core.filemode */
1231
+ git_config(merge_config);
1232
+ if (getenv("GIT_MERGE_VERBOSITY"))
1233
+ verbosity = strtol(getenv("GIT_MERGE_VERBOSITY"), NULL, 10);
1234
1235
if (argc < 4)
1236
die("Usage: %s <base>... -- <head> <remote> ...\n", argv[0]);
1252
1253
branch1 = better_branch_name(branch1);
1254
branch2 = better_branch_name(branch2);
1232
- printf("Merging %s with %s\n", branch1, branch2);
1255
+ if (show(3))
1256
+ printf("Merging %s with %s\n", branch1, branch2);
1257
1258
index_fd = hold_lock_file_for_update(lock, get_index_file(), 1);
1259