{"thread":{"id":"6369","subject":"[PATCH 4/4] Display a progress meter during merge-recursive.","startedAt":"2007-01-14T05:28:48Z","lastAt":"2007-01-14T22:50:32Z","messageCount":6,"participants":["Shawn O. Pearce","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"31676","messageId":"20070114052848.GB19113@spearce.org","threadId":"6369","inReplyTo":"d352c8adb1ec1c4e74b33d51d397d5756b82ceac.1168752482.git.spearce@spearce.org","subject":"[PATCH 2/4] Allow the user to control the verbosity of merge-recursive.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-01-14T05:28:48Z","receivedAt":"2007-01-14T05:28:48Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> writes:\n> I think the output from merge-recursive can be categorized into 5\n> verbosity levels:\n>\n> 1. \"CONFLICT\", \"Rename\", \"Adding here instead due to D/F conflict\"\n> (outermost)\n>\n> 2. \"Auto-merged successfully\" (outermost)\n>\n> 3. The first \"Merging X with Y\".\n>\n> 4. outermost \"Merging:\\ntitle1\\ntitle2\".\n>\n> 5. outermost \"found N common ancestors\\nancestor1\\nancestor2\\n...\"\n> and anything from inner merge.\n>\n> I would prefer the default verbosity level to be 2 (that is, show\n> both 1 and 2).\n\nand this change makes it so.  I think level 3 is probably pointless\nas its only one line of output above level 2, but I can see how some\nusers may want to view it but not view the slightly more verbose\noutput of level 4.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n Documentation/config.txt |    7 +++\n merge-recursive.c        |  100 ++++++++++++++++++++++++++++-----------------\n 2 files changed, 69 insertions(+), 38 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex f7dba89..faa17ba 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -321,6 +321,13 @@ merge.summary::\n \tWhether to include summaries of merged commits in newly created\n \tmerge commit messages. False by default.\n \n+merge.verbosity::\n+\tControls the amount of output shown by the recursive merge\n+\tstrategy.  Level 0 outputs nothing except a final error\n+\tmessage if conflicts were detected. Level 1 outputs only\n+\tconflicts, 2 outputs conflicts and file changes.  Level 5 and\n+\tabove outputs debugging information.  The default is level 2.\n+\n pack.window::\n \tThe size of the window used by gitlink:git-pack-objects[1] when no\n \twindow size is given on the command line. Defaults to 10.\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 8738f09..05f9311 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -71,17 +71,25 @@ static struct path_list current_file_set = {NULL, 0, 0, 1};\n static struct path_list current_directory_set = {NULL, 0, 0, 1};\n \n static int call_depth = 0;\n+static int verbosity = 2;\n \n-static void output(const char *fmt, ...)\n+static int show (int v)\n+{\n+\treturn (!call_depth && verbosity >= v) || verbosity >= 5;\n+}\n+\n+static void output(int v, const char *fmt, ...)\n {\n \tva_list args;\n-\tint i;\n-\tfor (i = call_depth; i--;)\n-\t\tfputs(\"  \", stdout);\n \tva_start(args, fmt);\n-\tvfprintf(stdout, fmt, args);\n+\tif (show(v)) {\n+\t\tint i;\n+\t\tfor (i = call_depth; i--;)\n+\t\t\tfputs(\"  \", stdout);\n+\t\tvfprintf(stdout, fmt, args);\n+\t\tfputc('\\n', stdout);\n+\t}\n \tva_end(args);\n-\tfputc('\\n', stdout);\n }\n \n static void output_commit_title(struct commit *commit)\n@@ -640,13 +648,13 @@ static void conflict_rename_rename(struct rename *ren1,\n \tconst char *dst_name2 = ren2_dst;\n \tif (path_list_has_path(&current_directory_set, ren1_dst)) {\n \t\tdst_name1 = del[delp++] = unique_path(ren1_dst, branch1);\n-\t\toutput(\"%s is a directory in %s adding as %s instead\",\n+\t\toutput(1, \"%s is a directory in %s adding as %s instead\",\n \t\t       ren1_dst, branch2, dst_name1);\n \t\tremove_file(0, ren1_dst, 0);\n \t}\n \tif (path_list_has_path(&current_directory_set, ren2_dst)) {\n \t\tdst_name2 = del[delp++] = unique_path(ren2_dst, branch2);\n-\t\toutput(\"%s is a directory in %s adding as %s instead\",\n+\t\toutput(1, \"%s is a directory in %s adding as %s instead\",\n \t\t       ren2_dst, branch1, dst_name2);\n \t\tremove_file(0, ren2_dst, 0);\n \t}\n@@ -660,7 +668,7 @@ static void conflict_rename_dir(struct rename *ren1,\n \t\t\t\tconst char *branch1)\n {\n \tchar *new_path = unique_path(ren1->pair->two->path, branch1);\n-\toutput(\"Renaming %s to %s instead\", ren1->pair->one->path, new_path);\n+\toutput(1, \"Renaming %s to %s instead\", ren1->pair->one->path, new_path);\n \tremove_file(0, ren1->pair->two->path, 0);\n \tupdate_file(0, ren1->pair->two->sha1, ren1->pair->two->mode, new_path);\n \tfree(new_path);\n@@ -673,7 +681,7 @@ static void conflict_rename_rename_2(struct rename *ren1,\n {\n \tchar *new_path1 = unique_path(ren1->pair->two->path, branch1);\n \tchar *new_path2 = unique_path(ren2->pair->two->path, branch2);\n-\toutput(\"Renaming %s to %s and %s to %s instead\",\n+\toutput(1, \"Renaming %s to %s and %s to %s instead\",\n \t       ren1->pair->one->path, new_path1,\n \t       ren2->pair->one->path, new_path2);\n \tremove_file(0, ren1->pair->two->path, 0);\n@@ -766,7 +774,7 @@ static int process_renames(struct path_list *a_renames,\n \t\t\tren2->processed = 1;\n \t\t\tif (strcmp(ren1_dst, ren2_dst) != 0) {\n \t\t\t\tclean_merge = 0;\n-\t\t\t\toutput(\"CONFLICT (rename/rename): \"\n+\t\t\t\toutput(1, \"CONFLICT (rename/rename): \"\n \t\t\t\t       \"Rename %s->%s in branch %s \"\n \t\t\t\t       \"rename %s->%s in %s\",\n \t\t\t\t       src, ren1_dst, branch1,\n@@ -781,13 +789,13 @@ static int process_renames(struct path_list *a_renames,\n \t\t\t\t\t\t branch1,\n \t\t\t\t\t\t branch2);\n \t\t\t\tif (mfi.merge || !mfi.clean)\n-\t\t\t\t\toutput(\"Renaming %s->%s\", src, ren1_dst);\n+\t\t\t\t\toutput(2, \"Renaming %s->%s\", src, ren1_dst);\n \n \t\t\t\tif (mfi.merge)\n-\t\t\t\t\toutput(\"Auto-merging %s\", ren1_dst);\n+\t\t\t\t\toutput(2, \"Auto-merging %s\", ren1_dst);\n \n \t\t\t\tif (!mfi.clean) {\n-\t\t\t\t\toutput(\"CONFLICT (content): merge conflict in %s\",\n+\t\t\t\t\toutput(1, \"CONFLICT (content): merge conflict in %s\",\n \t\t\t\t\t       ren1_dst);\n \t\t\t\t\tclean_merge = 0;\n \n@@ -818,14 +826,14 @@ static int process_renames(struct path_list *a_renames,\n \n \t\t\tif (path_list_has_path(&current_directory_set, ren1_dst)) {\n \t\t\t\tclean_merge = 0;\n-\t\t\t\toutput(\"CONFLICT (rename/directory): Rename %s->%s in %s \"\n+\t\t\t\toutput(1, \"CONFLICT (rename/directory): Rename %s->%s in %s \"\n \t\t\t\t       \" directory %s added in %s\",\n \t\t\t\t       ren1_src, ren1_dst, branch1,\n \t\t\t\t       ren1_dst, branch2);\n \t\t\t\tconflict_rename_dir(ren1, branch1);\n \t\t\t} else if (sha_eq(src_other.sha1, null_sha1)) {\n \t\t\t\tclean_merge = 0;\n-\t\t\t\toutput(\"CONFLICT (rename/delete): Rename %s->%s in %s \"\n+\t\t\t\toutput(1, \"CONFLICT (rename/delete): Rename %s->%s in %s \"\n \t\t\t\t       \"and deleted in %s\",\n \t\t\t\t       ren1_src, ren1_dst, branch1,\n \t\t\t\t       branch2);\n@@ -834,18 +842,18 @@ static int process_renames(struct path_list *a_renames,\n \t\t\t\tconst char *new_path;\n \t\t\t\tclean_merge = 0;\n \t\t\t\ttry_merge = 1;\n-\t\t\t\toutput(\"CONFLICT (rename/add): Rename %s->%s in %s. \"\n+\t\t\t\toutput(1, \"CONFLICT (rename/add): Rename %s->%s in %s. \"\n \t\t\t\t       \"%s added in %s\",\n \t\t\t\t       ren1_src, ren1_dst, branch1,\n \t\t\t\t       ren1_dst, branch2);\n \t\t\t\tnew_path = unique_path(ren1_dst, branch2);\n-\t\t\t\toutput(\"Adding as %s instead\", new_path);\n+\t\t\t\toutput(1, \"Adding as %s instead\", new_path);\n \t\t\t\tupdate_file(0, dst_other.sha1, dst_other.mode, new_path);\n \t\t\t} else if ((item = path_list_lookup(ren1_dst, renames2Dst))) {\n \t\t\t\tren2 = item->util;\n \t\t\t\tclean_merge = 0;\n \t\t\t\tren2->processed = 1;\n-\t\t\t\toutput(\"CONFLICT (rename/rename): Rename %s->%s in %s. \"\n+\t\t\t\toutput(1, \"CONFLICT (rename/rename): Rename %s->%s in %s. \"\n \t\t\t\t       \"Rename %s->%s in %s\",\n \t\t\t\t       ren1_src, ren1_dst, branch1,\n \t\t\t\t       ren2->pair->one->path, ren2->pair->two->path, branch2);\n@@ -870,11 +878,11 @@ static int process_renames(struct path_list *a_renames,\n \t\t\t\t\t\ta_branch, b_branch);\n \n \t\t\t\tif (mfi.merge || !mfi.clean)\n-\t\t\t\t\toutput(\"Renaming %s => %s\", ren1_src, ren1_dst);\n+\t\t\t\t\toutput(2, \"Renaming %s => %s\", ren1_src, ren1_dst);\n \t\t\t\tif (mfi.merge)\n-\t\t\t\t\toutput(\"Auto-merging %s\", ren1_dst);\n+\t\t\t\t\toutput(2, \"Auto-merging %s\", ren1_dst);\n \t\t\t\tif (!mfi.clean) {\n-\t\t\t\t\toutput(\"CONFLICT (rename/modify): Merge conflict in %s\",\n+\t\t\t\t\toutput(1, \"CONFLICT (rename/modify): Merge conflict in %s\",\n \t\t\t\t\t       ren1_dst);\n \t\t\t\t\tclean_merge = 0;\n \n@@ -922,20 +930,20 @@ static int process_entry(const char *path, struct stage_data *entry,\n \t\t\t/* Deleted in both or deleted in one and\n \t\t\t * unchanged in the other */\n \t\t\tif (a_sha)\n-\t\t\t\toutput(\"Removing %s\", path);\n+\t\t\t\toutput(2, \"Removing %s\", path);\n \t\t\t/* do not touch working file if it did not exist */\n \t\t\tremove_file(1, path, !a_sha);\n \t\t} else {\n \t\t\t/* Deleted in one and changed in the other */\n \t\t\tclean_merge = 0;\n \t\t\tif (!a_sha) {\n-\t\t\t\toutput(\"CONFLICT (delete/modify): %s deleted in %s \"\n+\t\t\t\toutput(1, \"CONFLICT (delete/modify): %s deleted in %s \"\n \t\t\t\t       \"and modified in %s. Version %s of %s left in tree.\",\n \t\t\t\t       path, branch1,\n \t\t\t\t       branch2, branch2, path);\n \t\t\t\tupdate_file(0, b_sha, b_mode, path);\n \t\t\t} else {\n-\t\t\t\toutput(\"CONFLICT (delete/modify): %s deleted in %s \"\n+\t\t\t\toutput(1, \"CONFLICT (delete/modify): %s deleted in %s \"\n \t\t\t\t       \"and modified in %s. Version %s of %s left in tree.\",\n \t\t\t\t       path, branch2,\n \t\t\t\t       branch1, branch1, path);\n@@ -968,13 +976,13 @@ static int process_entry(const char *path, struct stage_data *entry,\n \t\tif (path_list_has_path(&current_directory_set, path)) {\n \t\t\tconst char *new_path = unique_path(path, add_branch);\n \t\t\tclean_merge = 0;\n-\t\t\toutput(\"CONFLICT (%s): There is a directory with name %s in %s. \"\n+\t\t\toutput(1, \"CONFLICT (%s): There is a directory with name %s in %s. \"\n \t\t\t       \"Adding %s as %s\",\n \t\t\t       conf, path, other_branch, path, new_path);\n \t\t\tremove_file(0, path, 0);\n \t\t\tupdate_file(0, sha, mode, new_path);\n \t\t} else {\n-\t\t\toutput(\"Adding %s\", path);\n+\t\t\toutput(2, \"Adding %s\", path);\n \t\t\tupdate_file(1, sha, mode, path);\n \t\t}\n \t} else if (a_sha && b_sha) {\n@@ -988,7 +996,7 @@ static int process_entry(const char *path, struct stage_data *entry,\n \t\t\treason = \"add/add\";\n \t\t\to_sha = (unsigned char *)null_sha1;\n \t\t}\n-\t\toutput(\"Auto-merging %s\", path);\n+\t\toutput(2, \"Auto-merging %s\", path);\n \t\to.path = a.path = b.path = (char *)path;\n \t\thashcpy(o.sha1, o_sha);\n \t\to.mode = o_mode;\n@@ -1004,7 +1012,7 @@ static int process_entry(const char *path, struct stage_data *entry,\n \t\t\tupdate_file(1, mfi.sha, mfi.mode, path);\n \t\telse {\n \t\t\tclean_merge = 0;\n-\t\t\toutput(\"CONFLICT (%s): Merge conflict in %s\",\n+\t\t\toutput(1, \"CONFLICT (%s): Merge conflict in %s\",\n \t\t\t\t\treason, path);\n \n \t\t\tif (index_only)\n@@ -1028,7 +1036,7 @@ static int merge_trees(struct tree *head,\n {\n \tint code, clean;\n \tif (sha_eq(common->object.sha1, merge->object.sha1)) {\n-\t\toutput(\"Already uptodate!\");\n+\t\toutput(0, \"Already uptodate!\");\n \t\t*result = head;\n \t\treturn 1;\n \t}\n@@ -1103,18 +1111,22 @@ static int merge(struct commit *h1,\n \tstruct tree *mrtree;\n \tint clean;\n \n-\toutput(\"Merging:\");\n-\toutput_commit_title(h1);\n-\toutput_commit_title(h2);\n+\tif (show(4)) {\n+\t\toutput(4, \"Merging:\");\n+\t\toutput_commit_title(h1);\n+\t\toutput_commit_title(h2);\n+\t}\n \n \tif (!ca) {\n \t\tca = get_merge_bases(h1, h2, 1);\n \t\tca = reverse_commit_list(ca);\n \t}\n \n-\toutput(\"found %u common ancestor(s):\", commit_list_count(ca));\n-\tfor (iter = ca; iter; iter = iter->next)\n-\t\toutput_commit_title(iter->item);\n+\tif (show(5)) {\n+\t\toutput(5, \"found %u common ancestor(s):\", commit_list_count(ca));\n+\t\tfor (iter = ca; iter; iter = iter->next)\n+\t\t\toutput_commit_title(iter->item);\n+\t}\n \n \tmerged_common_ancestors = pop_commit(&ca);\n \tif (merged_common_ancestors == NULL) {\n@@ -1196,6 +1208,15 @@ static struct commit *get_ref(const char *ref)\n \treturn (struct commit *)object;\n }\n \n+static int merge_config(const char *var, const char *value)\n+{\n+\tif (!strcasecmp(var, \"merge.verbosity\")) {\n+\t\tverbosity = git_config_int(var, value);\n+\t\treturn 0;\n+\t}\n+\treturn git_default_config(var, value);\n+}\n+\n int main(int argc, char *argv[])\n {\n \tstatic const char *bases[20];\n@@ -1207,7 +1228,9 @@ int main(int argc, char *argv[])\n \tstruct lock_file *lock = xcalloc(1, sizeof(struct lock_file));\n \tint index_fd;\n \n-\tgit_config(git_default_config); /* core.filemode */\n+\tgit_config(merge_config);\n+\tif (getenv(\"GIT_MERGE_VERBOSITY\"))\n+\t\tverbosity = strtol(getenv(\"GIT_MERGE_VERBOSITY\"), NULL, 10);\n \n \tif (argc < 4)\n \t\tdie(\"Usage: %s <base>... -- <head> <remote> ...\\n\", argv[0]);\n@@ -1229,7 +1252,8 @@ int main(int argc, char *argv[])\n \n \tbranch1 = better_branch_name(branch1);\n \tbranch2 = better_branch_name(branch2);\n-\tprintf(\"Merging %s with %s\\n\", branch1, branch2);\n+\tif (show(3))\n+\t\tprintf(\"Merging %s with %s\\n\", branch1, branch2);\n \n \tindex_fd = hold_lock_file_for_update(lock, get_index_file(), 1);\n \n-- \n1.5.0.rc1.g4494\n"},{"id":"31675","messageId":"20070114052853.GC19113@spearce.org","threadId":"6369","inReplyTo":"d352c8adb1ec1c4e74b33d51d397d5756b82ceac.1168752482.git.spearce@spearce.org","subject":"[PATCH 3/4] Enable output buffering in merge-recursive.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-01-14T05:28:53Z","receivedAt":"2007-01-14T05:28:53Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Buffering all message output until a merge invocation is complete is\nnecessary to prevent intereferring with a progress meter that would\nindicate the number of files completely merged, and how many remain.\nThis change does not introduce a progress meter, but merely lays\nthe groundwork to buffer the output.\n\nTo aid debugging output buffering is only enabled if verbosity\nis lower than 5.  When using verbosity levels above 5 the user is\nprobably debugging the merge program itself and does not want to\nsee the output delayed, especially if they are stepping through\nportions of the code in a debugger.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n merge-recursive.c |   40 +++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 39 insertions(+), 1 deletions(-)\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 05f9311..c16062b 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -67,11 +67,19 @@ struct stage_data\n \tunsigned processed:1;\n };\n \n+struct output_buffer\n+{\n+\tstruct output_buffer *next;\n+\tchar *str;\n+};\n+\n static struct path_list current_file_set = {NULL, 0, 0, 1};\n static struct path_list current_directory_set = {NULL, 0, 0, 1};\n \n static int call_depth = 0;\n static int verbosity = 2;\n+static int buffer_output = 1;\n+static struct output_buffer *output_list, *output_end;\n \n static int show (int v)\n {\n@@ -82,7 +90,16 @@ static void output(int v, const char *fmt, ...)\n {\n \tva_list args;\n \tva_start(args, fmt);\n-\tif (show(v)) {\n+\tif (buffer_output && show(v)) {\n+\t\tstruct output_buffer *b = xmalloc(sizeof(*b));\n+\t\tnfvasprintf(&b->str, fmt, args);\n+\t\tb->next = NULL;\n+\t\tif (output_end)\n+\t\t\toutput_end->next = b;\n+\t\telse\n+\t\t\toutput_list = b;\n+\t\toutput_end = b;\n+\t} else if (show(v)) {\n \t\tint i;\n \t\tfor (i = call_depth; i--;)\n \t\t\tfputs(\"  \", stdout);\n@@ -92,9 +109,27 @@ static void output(int v, const char *fmt, ...)\n \tva_end(args);\n }\n \n+static void flush_output()\n+{\n+\tstruct output_buffer *b, *n;\n+\tfor (b = output_list; b; b = n) {\n+\t\tint i;\n+\t\tfor (i = call_depth; i--;)\n+\t\t\tfputs(\"  \", stdout);\n+\t\tfputs(b->str, stdout);\n+\t\tfputc('\\n', stdout);\n+\t\tn = b->next;\n+\t\tfree(b->str);\n+\t\tfree(b);\n+\t}\n+\toutput_list = NULL;\n+\toutput_end = NULL;\n+}\n+\n static void output_commit_title(struct commit *commit)\n {\n \tint i;\n+\tflush_output();\n \tfor (i = call_depth; i--;)\n \t\tfputs(\"  \", stdout);\n \tif (commit->util)\n@@ -1175,6 +1210,7 @@ static int merge(struct commit *h1,\n \t\tcommit_list_insert(h1, &(*result)->parents);\n \t\tcommit_list_insert(h2, &(*result)->parents->next);\n \t}\n+\tflush_output();\n \treturn clean;\n }\n \n@@ -1252,6 +1288,8 @@ int main(int argc, char *argv[])\n \n \tbranch1 = better_branch_name(branch1);\n \tbranch2 = better_branch_name(branch2);\n+\tif (verbosity >= 5)\n+\t\tbuffer_output = 0;\n \tif (show(3))\n \t\tprintf(\"Merging %s with %s\\n\", branch1, branch2);\n \n-- \n1.5.0.rc1.g4494\n"},{"id":"31674","messageId":"20070114052858.GD19113@spearce.org","threadId":"6369","inReplyTo":"d352c8adb1ec1c4e74b33d51d397d5756b82ceac.1168752482.git.spearce@spearce.org","subject":"[PATCH 4/4] Display a progress meter during merge-recursive.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-01-14T05:28:58Z","receivedAt":"2007-01-14T05:28:58Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Because large merges on slow systems can take up to a minute to\nexecute we should try to keep the user entertained with a progress\nmeter to let them know how far we have progressed through the\ncurrent merge.\n\nThe progress meter considers each entry in the in-memory index to\nbe a unit, which means a single recursive merge will double the\nnumber of units in the progress meter.  Files which are unmerged\nafter the 3-way tree merge are also considered a unit within the\nprogress meter.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n merge-recursive.c |   69 ++++++++++++++++++++++++++++++++++++++++++++++++----\n 1 files changed, 63 insertions(+), 6 deletions(-)\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex c16062b..c4e21bc 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -79,6 +79,11 @@ static struct path_list current_directory_set = {NULL, 0, 0, 1};\n static int call_depth = 0;\n static int verbosity = 2;\n static int buffer_output = 1;\n+static int do_progress = 1;\n+static unsigned last_percent;\n+static unsigned merged_cnt;\n+static unsigned total_cnt;\n+static volatile sig_atomic_t progress_update;\n static struct output_buffer *output_list, *output_end;\n \n static int show (int v)\n@@ -153,6 +158,39 @@ static void output_commit_title(struct commit *commit)\n \t}\n }\n \n+static void progress_interval(int signum)\n+{\n+\tprogress_update = 1;\n+}\n+\n+static void setup_progress_signal(void)\n+{\n+\tstruct sigaction sa;\n+\tstruct itimerval v;\n+\n+\tmemset(&sa, 0, sizeof(sa));\n+\tsa.sa_handler = progress_interval;\n+\tsigemptyset(&sa.sa_mask);\n+\tsa.sa_flags = SA_RESTART;\n+\tsigaction(SIGALRM, &sa, NULL);\n+\n+\tv.it_interval.tv_sec = 1;\n+\tv.it_interval.tv_usec = 0;\n+\tv.it_value = v.it_interval;\n+\tsetitimer(ITIMER_REAL, &v, NULL);\n+}\n+\n+static void display_progress()\n+{\n+\tunsigned percent = merged_cnt * 100 / total_cnt;\n+\tif (progress_update || percent != last_percent) {\n+\t\tfprintf(stderr, \"%4u%% (%u/%u) done\\r\",\n+\t\t\tpercent, merged_cnt, total_cnt);\n+\t\tprogress_update = 0;\n+\t\tlast_percent = percent;\n+\t}\n+}\n+\n static struct cache_entry *make_cache_entry(unsigned int mode,\n \t\tconst unsigned char *sha1, const char *path, int stage, int refresh)\n {\n@@ -315,11 +353,14 @@ static struct path_list *get_unmerged(void)\n \tint i;\n \n \tunmerged->strdup_paths = 1;\n+\ttotal_cnt += active_nr;\n \n-\tfor (i = 0; i < active_nr; i++) {\n+\tfor (i = 0; i < active_nr; i++, merged_cnt++) {\n \t\tstruct path_list_item *item;\n \t\tstruct stage_data *e;\n \t\tstruct cache_entry *ce = active_cache[i];\n+\t\tif (do_progress)\n+\t\t\tdisplay_progress();\n \t\tif (!ce_stage(ce))\n \t\t\tcontinue;\n \n@@ -1096,13 +1137,15 @@ static int merge_trees(struct tree *head,\n \t\tre_merge = get_renames(merge, common, head, merge, entries);\n \t\tclean = process_renames(re_head, re_merge,\n \t\t\t\tbranch1, branch2);\n-\t\tfor (i = 0; i < entries->nr; i++) {\n+\t\ttotal_cnt += entries->nr;\n+\t\tfor (i = 0; i < entries->nr; i++, merged_cnt++) {\n \t\t\tconst char *path = entries->items[i].path;\n \t\t\tstruct stage_data *e = entries->items[i].util;\n-\t\t\tif (e->processed)\n-\t\t\t\tcontinue;\n-\t\t\tif (!process_entry(path, e, branch1, branch2))\n+\t\t\tif (!e->processed\n+\t\t\t\t&& !process_entry(path, e, branch1, branch2))\n \t\t\t\tclean = 0;\n+\t\t\tif (do_progress)\n+\t\t\t\tdisplay_progress();\n \t\t}\n \n \t\tpath_list_clear(re_merge, 0);\n@@ -1210,6 +1253,12 @@ static int merge(struct commit *h1,\n \t\tcommit_list_insert(h1, &(*result)->parents);\n \t\tcommit_list_insert(h2, &(*result)->parents->next);\n \t}\n+\tif (!call_depth && do_progress) {\n+\t\tmerged_cnt = total_cnt;\n+\t\tprogress_update = 1;\n+\t\tdisplay_progress();\n+\t\tfputc('\\n', stderr);\n+\t}\n \tflush_output();\n \treturn clean;\n }\n@@ -1279,6 +1328,10 @@ int main(int argc, char *argv[])\n \t}\n \tif (argc - i != 3) /* \"--\" \"<head>\" \"<remote>\" */\n \t\tdie(\"Not handling anything other than two heads merge.\");\n+\tif (verbosity >= 5) {\n+\t\tbuffer_output = 0;\n+\t\tdo_progress = 0;\n+\t}\n \n \tbranch1 = argv[++i];\n \tbranch2 = argv[++i];\n@@ -1288,8 +1341,12 @@ int main(int argc, char *argv[])\n \n \tbranch1 = better_branch_name(branch1);\n \tbranch2 = better_branch_name(branch2);\n-\tif (verbosity >= 5)\n+\tif (verbosity >= 5) {\n \t\tbuffer_output = 0;\n+\t\tdo_progress = 0;\n+\t}\n+\tif (do_progress)\n+\t\tsetup_progress_signal();\n \tif (show(3))\n \t\tprintf(\"Merging %s with %s\\n\", branch1, branch2);\n \n-- \n1.5.0.rc1.g4494\n"},{"id":"31685","messageId":"Pine.LNX.4.63.0701141404160.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6369","inReplyTo":"20070114052858.GD19113@spearce.org","subject":"Re: [PATCH 4/4] Display a progress meter during merge-recursive.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-01-14T13:04:55Z","receivedAt":"2007-01-14T13:04:55Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nthis is a nice idea, but I think you lack a \"if (!isatty(1)) do_progress = \n0;\" somewhere.\n\nCiao,\nDscho\n"},{"id":"31707","messageId":"7vwt3pfmph.fsf@assigned-by-dhcp.cox.net","threadId":"6369","inReplyTo":"Pine.LNX.4.63.0701141404160.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH 4/4] Display a progress meter during merge-recursive.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-14T19:11:06Z","receivedAt":"2007-01-14T19:11:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> this is a nice idea, but I think you lack a \"if (!isatty(1)) do_progress = \n> 0;\" somewhere.\n\nVery true.  Something like this?\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 27a861b..fa320eb 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -1335,6 +1335,8 @@ int main(int argc, char *argv[])\n \t\tbuffer_output = 0;\n \t\tdo_progress = 0;\n \t}\n+\telse\n+\t\tdo_progress = isatty(1);\n \n \tbranch1 = argv[++i];\n \tbranch2 = argv[++i];\n@@ -1344,10 +1346,7 @@ int main(int argc, char *argv[])\n \n \tbranch1 = better_branch_name(branch1);\n \tbranch2 = better_branch_name(branch2);\n-\tif (verbosity >= 5) {\n-\t\tbuffer_output = 0;\n-\t\tdo_progress = 0;\n-\t}\n+\n \tif (do_progress)\n \t\tsetup_progress_signal();\n \tif (show(3))\n"},{"id":"31747","messageId":"20070114225031.GC10888@spearce.org","threadId":"6369","inReplyTo":"7vwt3pfmph.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 4/4] Display a progress meter during merge-recursive.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-01-14T22:50:32Z","receivedAt":"2007-01-14T22:50:32Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > this is a nice idea, but I think you lack a \"if (!isatty(1)) do_progress = \n> > 0;\" somewhere.\n> \n> Very true.  Something like this?\n\nAck'd.  I see its already in next.  Thanks for the cleanup.\n\n-- \nShawn.\n"}]}