@matheusbsbs / matheus-bagliano / commits / 8c3275abca
Fork 0

Allow the user to control the verbosity of merge-recursive.

Junio C Hamano <junkio@cox.net> writes: > > I think the output from merge-recursive can be categorized into 5 > verbosity levels: > > 1. "CONFLICT", "Rename", "Adding here instead due to D/F conflict" > (outermost) > > 2. "Auto-merged successfully" (outermost) > > 3. The first "Merging X with Y". > > 4. outermost "Merging:\ntitle1\ntitle2". > > 5. outermost "found N common ancestors\nancestor1\nancestor2\n..." > and anything from inner merge. > > I would prefer the default verbosity level to be 2 (that is, show > both 1 and 2). and this change makes it so. I think level 3 is probably pointless as its only one line of output above level 2, but I can see how some users may want to view it but not view the slightly more verbose output of level 4. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn O. Pearce committed Jan 14, 2007 at 00:28 UTC 8c3275abcacb83ea3f4c4f4ceb2376799fc282bd
2 files changed +69 -38
Documentation/config.txt
+7
@@ -321,6 +321,13 @@ merge.summary::
321 Whether to include summaries of merged commits in newly created
322 merge commit messages. False by default.
323
324 +merge.verbosity::
325 + Controls the amount of output shown by the recursive merge
326 + strategy. Level 0 outputs nothing except a final error
327 + message if conflicts were detected. Level 1 outputs only
328 + conflicts, 2 outputs conflicts and file changes. Level 5 and
329 + above outputs debugging information. The default is level 2.
330 +
331 pack.window::
332 The size of the window used by gitlink:git-pack-objects[1] when no
333 window size is given on the command line. Defaults to 10.
merge-recursive.c
+62 -38
@@ -71,17 +71,25 @@ static struct path_list current_file_set = {NULL, 0, 0, 1};
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)
@@ -640,13 +648,13 @@ static void conflict_rename_rename(struct rename *ren1,
648 const char *dst_name2 = ren2_dst;
649 if (path_list_has_path(&current_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(&current_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 }
@@ -660,7 +668,7 @@ static void conflict_rename_dir(struct rename *ren1,
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);
@@ -673,7 +681,7 @@ static void conflict_rename_rename_2(struct rename *ren1,
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);
@@ -766,7 +774,7 @@ static int process_renames(struct path_list *a_renames,
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,
@@ -781,13 +789,13 @@ static int process_renames(struct path_list *a_renames,
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
@@ -818,14 +826,14 @@ static int process_renames(struct path_list *a_renames,
826
827 if (path_list_has_path(&current_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);
@@ -834,18 +842,18 @@ static int process_renames(struct path_list *a_renames,
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);
@@ -870,11 +878,11 @@ static int process_renames(struct path_list *a_renames,
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
@@ -922,20 +930,20 @@ static int process_entry(const char *path, struct stage_data *entry,
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);
@@ -968,13 +976,13 @@ static int process_entry(const char *path, struct stage_data *entry,
976 if (path_list_has_path(&current_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) {
@@ -988,7 +996,7 @@ static int process_entry(const char *path, struct stage_data *entry,
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;
@@ -1004,7 +1012,7 @@ static int process_entry(const char *path, struct stage_data *entry,
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)
@@ -1028,7 +1036,7 @@ static int merge_trees(struct tree *head,
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 }
@@ -1103,18 +1111,22 @@ static int merge(struct commit *h1,
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) {
@@ -1196,6 +1208,15 @@ static struct commit *get_ref(const char *ref)
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];
@@ -1207,7 +1228,9 @@ int main(int argc, char *argv[])
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]);
@@ -1229,7 +1252,8 @@ int main(int argc, char *argv[])
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