{"thread":{"id":"15340","subject":"[PATCH 1/2] merge-recursive: move call_depth to struct merge_options","startedAt":"2008-09-02T22:05:31Z","lastAt":"2008-09-05T17:26:42Z","messageCount":15,"participants":["Miklos Vajna","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"89558","messageId":"cover.1220392547.git.vmiklos@frugalware.org","threadId":"15340","inReplyTo":"7v1w02l3jc.fsf@gitster.siamese.dyndns.org","subject":"[PATCH 0/2] Move call_depth and index_only to struct merge_options","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-09-02T22:05:31Z","receivedAt":"2008-09-02T22:05:31Z","isPatch":true,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"On Tue, Sep 02, 2008 at 01:02:31PM -0700, Junio C Hamano <gitster@pobox.com> wrote:\n> I found it a bit disturbing that \"index_only\" and \"call_depth\" were\n> not\n> part of merge_options structure.\n\nHere are two patches to do it, on top of current mv/merge-recursive.\n\nBoth patches are pretty trivial, I think, but I split them as the second\none is larger.\n\nNow in some cases we have function calls like\n\nmerge_file(o, one, a, b, o->branch1, o->branch2);\n\nbut I don't think we can avoid it, as the last two parameters are not\nalways like this (two times are like this, and once conditionally\nswapped). I'm not sure if it worth to introduce a new \"int swap\"\nparameter, just to avoid the last two one.\n\nMiklos Vajna (2):\n  merge-recursive: move call_depth to struct merge_options\n  merge-recursive: move index_only to struct merge_options\n\n merge-recursive.c |  164 ++++++++++++++++++++++++++---------------------------\n merge-recursive.h |   13 ++++\n 2 files changed, 93 insertions(+), 84 deletions(-)\n"},{"id":"89557","messageId":"b96b1e10babd379daea483e72d99d8e520e34506.1220392547.git.vmiklos@frugalware.org","threadId":"15340","inReplyTo":"cover.1220392547.git.vmiklos@frugalware.org","subject":"[PATCH 1/2] merge-recursive: move call_depth to struct merge_options","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-09-02T22:05:32Z","receivedAt":"2008-09-02T22:05:32Z","isPatch":true,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>\n---\n merge-recursive.c |   25 ++++++++++++-------------\n merge-recursive.h |    1 +\n 2 files changed, 13 insertions(+), 13 deletions(-)\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 457ad84..5bb20aa 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -80,12 +80,11 @@ struct stage_data\n static struct string_list current_file_set = {NULL, 0, 0, 1};\n static struct string_list current_directory_set = {NULL, 0, 0, 1};\n \n-static int call_depth = 0;\n static struct strbuf obuf = STRBUF_INIT;\n \n static int show(struct merge_options *o, int v)\n {\n-\treturn (!call_depth && o->verbosity >= v) || o->verbosity >= 5;\n+\treturn (!o->call_depth && o->verbosity >= v) || o->verbosity >= 5;\n }\n \n static void flush_output(void)\n@@ -104,9 +103,9 @@ static void output(struct merge_options *o, int v, const char *fmt, ...)\n \tif (!show(o, v))\n \t\treturn;\n \n-\tstrbuf_grow(&obuf, call_depth * 2 + 2);\n-\tmemset(obuf.buf + obuf.len, ' ', call_depth * 2);\n-\tstrbuf_setlen(&obuf, obuf.len + call_depth * 2);\n+\tstrbuf_grow(&obuf, o->call_depth * 2 + 2);\n+\tmemset(obuf.buf + obuf.len, ' ', o->call_depth * 2);\n+\tstrbuf_setlen(&obuf, obuf.len + o->call_depth * 2);\n \n \tva_start(ap, fmt);\n \tlen = vsnprintf(obuf.buf + obuf.len, strbuf_avail(&obuf), fmt, ap);\n@@ -129,11 +128,11 @@ static void output(struct merge_options *o, int v, const char *fmt, ...)\n \t\tflush_output();\n }\n \n-static void output_commit_title(struct commit *commit)\n+static void output_commit_title(struct merge_options *o, struct commit *commit)\n {\n \tint i;\n \tflush_output();\n-\tfor (i = call_depth; i--;)\n+\tfor (i = o->call_depth; i--;)\n \t\tfputs(\"  \", stdout);\n \tif (commit->util)\n \t\tprintf(\"virtual %s\\n\", (char *)commit->util);\n@@ -1230,8 +1229,8 @@ int merge_recursive(struct merge_options *o,\n \n \tif (show(o, 4)) {\n \t\toutput(o, 4, \"Merging:\");\n-\t\toutput_commit_title(h1);\n-\t\toutput_commit_title(h2);\n+\t\toutput_commit_title(o, h1);\n+\t\toutput_commit_title(o, h2);\n \t}\n \n \tif (!ca) {\n@@ -1242,7 +1241,7 @@ int merge_recursive(struct merge_options *o,\n \tif (show(o, 5)) {\n \t\toutput(o, 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\t\toutput_commit_title(o, iter->item);\n \t}\n \n \tmerged_common_ancestors = pop_commit(&ca);\n@@ -1258,7 +1257,7 @@ int merge_recursive(struct merge_options *o,\n \n \tfor (iter = ca; iter; iter = iter->next) {\n \t\tconst char *saved_b1, *saved_b2;\n-\t\tcall_depth++;\n+\t\to->call_depth++;\n \t\t/*\n \t\t * When the merge fails, the result contains files\n \t\t * with conflict markers. The cleanness flag is\n@@ -1275,14 +1274,14 @@ int merge_recursive(struct merge_options *o,\n \t\t\t\tNULL, &merged_common_ancestors);\n \t\to->branch1 = saved_b1;\n \t\to->branch2 = saved_b2;\n-\t\tcall_depth--;\n+\t\to->call_depth--;\n \n \t\tif (!merged_common_ancestors)\n \t\t\tdie(\"merge returned no commit\");\n \t}\n \n \tdiscard_cache();\n-\tif (!call_depth) {\n+\tif (!o->call_depth) {\n \t\tread_cache();\n \t\tindex_only = 0;\n \t} else\ndiff --git a/merge-recursive.h b/merge-recursive.h\nindex 72f0a28..4f55374 100644\n--- a/merge-recursive.h\n+++ b/merge-recursive.h\n@@ -9,6 +9,7 @@ struct merge_options {\n \tint verbosity;\n \tint diff_rename_limit;\n \tint merge_rename_limit;\n+\tint call_depth;\n };\n \n /* merge_trees() but with recursive ancestor consolidation */\n-- \n1.6.0.1\n"},{"id":"89559","messageId":"07ec53323899e255b858751fbbaa3b29bb4108c3.1220392547.git.vmiklos@frugalware.org","threadId":"15340","inReplyTo":"b96b1e10babd379daea483e72d99d8e520e34506.1220392547.git.vmiklos@frugalware.org","subject":"[PATCH 2/2] merge-recursive: move index_only to struct merge_options","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-09-02T22:05:33Z","receivedAt":"2008-09-02T22:05:33Z","isPatch":true,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>\n---\n merge-recursive.c |  139 ++++++++++++++++++++++++++---------------------------\n merge-recursive.h |   12 +++++\n 2 files changed, 80 insertions(+), 71 deletions(-)\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 5bb20aa..4af657c 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -165,17 +165,6 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,\n \treturn add_cache_entry(ce, options);\n }\n \n-/*\n- * This is a global variable which is used in a number of places but\n- * only written to in the 'merge' function.\n- *\n- * index_only == 1    => Don't leave any non-stage 0 entries in the cache and\n- *                       don't update the working directory.\n- *               0    => Leave unmerged entries in the cache and update\n- *                       the working directory.\n- */\n-static int index_only = 0;\n-\n static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree)\n {\n \tparse_tree(tree);\n@@ -428,10 +417,11 @@ static int remove_path(const char *name)\n \treturn ret;\n }\n \n-static int remove_file(int clean, const char *path, int no_wd)\n+static int remove_file(struct merge_options *o, int clean,\n+\t\t       const char *path, int no_wd)\n {\n-\tint update_cache = index_only || clean;\n-\tint update_working_directory = !index_only && !no_wd;\n+\tint update_cache = o->index_only || clean;\n+\tint update_working_directory = !o->index_only && !no_wd;\n \n \tif (update_cache) {\n \t\tif (remove_file_from_cache(path))\n@@ -509,13 +499,14 @@ static int make_room_for_path(const char *path)\n \treturn error(msg, path, \": perhaps a D/F conflict?\");\n }\n \n-static void update_file_flags(const unsigned char *sha,\n+static void update_file_flags(struct merge_options *o,\n+\t\t\t      const unsigned char *sha,\n \t\t\t      unsigned mode,\n \t\t\t      const char *path,\n \t\t\t      int update_cache,\n \t\t\t      int update_wd)\n {\n-\tif (index_only)\n+\tif (o->index_only)\n \t\tupdate_wd = 0;\n \n \tif (update_wd) {\n@@ -574,12 +565,13 @@ static void update_file_flags(const unsigned char *sha,\n \t\tadd_cacheinfo(mode, sha, path, 0, update_wd, ADD_CACHE_OK_TO_ADD);\n }\n \n-static void update_file(int clean,\n+static void update_file(struct merge_options *o,\n+\t\t\tint clean,\n \t\t\tconst unsigned char *sha,\n \t\t\tunsigned mode,\n \t\t\tconst char *path)\n {\n-\tupdate_file_flags(sha, mode, path, index_only || clean, !index_only);\n+\tupdate_file_flags(o, sha, mode, path, o->index_only || clean, !o->index_only);\n }\n \n /* Low level file merging, update and removal */\n@@ -609,8 +601,9 @@ static void fill_mm(const unsigned char *sha1, mmfile_t *mm)\n \tmm->size = size;\n }\n \n-static int merge_3way(mmbuffer_t *result_buf,\n-\t\t      struct diff_filespec *o,\n+static int merge_3way(struct merge_options *o,\n+\t\t      mmbuffer_t *result_buf,\n+\t\t      struct diff_filespec *one,\n \t\t      struct diff_filespec *a,\n \t\t      struct diff_filespec *b,\n \t\t      const char *branch1,\n@@ -623,13 +616,13 @@ static int merge_3way(mmbuffer_t *result_buf,\n \tname1 = xstrdup(mkpath(\"%s:%s\", branch1, a->path));\n \tname2 = xstrdup(mkpath(\"%s:%s\", branch2, b->path));\n \n-\tfill_mm(o->sha1, &orig);\n+\tfill_mm(one->sha1, &orig);\n \tfill_mm(a->sha1, &src1);\n \tfill_mm(b->sha1, &src2);\n \n \tmerge_status = ll_merge(result_buf, a->path, &orig,\n \t\t\t\t&src1, name1, &src2, name2,\n-\t\t\t\tindex_only);\n+\t\t\t\to->index_only);\n \n \tfree(name1);\n \tfree(name2);\n@@ -639,9 +632,12 @@ static int merge_3way(mmbuffer_t *result_buf,\n \treturn merge_status;\n }\n \n-static struct merge_file_info merge_file(struct diff_filespec *o,\n-\t\tstruct diff_filespec *a, struct diff_filespec *b,\n-\t\tconst char *branch1, const char *branch2)\n+static struct merge_file_info merge_file(struct merge_options *o,\n+\t\t\t\t         struct diff_filespec *one,\n+\t\t\t\t\t struct diff_filespec *a,\n+\t\t\t\t\t struct diff_filespec *b,\n+\t\t\t\t\t const char *branch1,\n+\t\t\t\t\t const char *branch2)\n {\n \tstruct merge_file_info result;\n \tresult.merge = 0;\n@@ -657,31 +653,31 @@ static struct merge_file_info merge_file(struct diff_filespec *o,\n \t\t\thashcpy(result.sha, b->sha1);\n \t\t}\n \t} else {\n-\t\tif (!sha_eq(a->sha1, o->sha1) && !sha_eq(b->sha1, o->sha1))\n+\t\tif (!sha_eq(a->sha1, one->sha1) && !sha_eq(b->sha1, one->sha1))\n \t\t\tresult.merge = 1;\n \n \t\t/*\n \t\t * Merge modes\n \t\t */\n-\t\tif (a->mode == b->mode || a->mode == o->mode)\n+\t\tif (a->mode == b->mode || a->mode == one->mode)\n \t\t\tresult.mode = b->mode;\n \t\telse {\n \t\t\tresult.mode = a->mode;\n-\t\t\tif (b->mode != o->mode) {\n+\t\t\tif (b->mode != one->mode) {\n \t\t\t\tresult.clean = 0;\n \t\t\t\tresult.merge = 1;\n \t\t\t}\n \t\t}\n \n-\t\tif (sha_eq(a->sha1, b->sha1) || sha_eq(a->sha1, o->sha1))\n+\t\tif (sha_eq(a->sha1, b->sha1) || sha_eq(a->sha1, one->sha1))\n \t\t\thashcpy(result.sha, b->sha1);\n-\t\telse if (sha_eq(b->sha1, o->sha1))\n+\t\telse if (sha_eq(b->sha1, one->sha1))\n \t\t\thashcpy(result.sha, a->sha1);\n \t\telse if (S_ISREG(a->mode)) {\n \t\t\tmmbuffer_t result_buf;\n \t\t\tint merge_status;\n \n-\t\t\tmerge_status = merge_3way(&result_buf, o, a, b,\n+\t\t\tmerge_status = merge_3way(o, &result_buf, one, a, b,\n \t\t\t\t\t\t  branch1, branch2);\n \n \t\t\tif ((merge_status < 0) || !result_buf.ptr)\n@@ -726,22 +722,22 @@ static void conflict_rename_rename(struct merge_options *o,\n \t\tdst_name1 = del[delp++] = unique_path(ren1_dst, branch1);\n \t\toutput(o, 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\tremove_file(o, 0, ren1_dst, 0);\n \t}\n \tif (string_list_has_string(&current_directory_set, ren2_dst)) {\n \t\tdst_name2 = del[delp++] = unique_path(ren2_dst, branch2);\n \t\toutput(o, 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\tremove_file(o, 0, ren2_dst, 0);\n \t}\n-\tif (index_only) {\n+\tif (o->index_only) {\n \t\tremove_file_from_cache(dst_name1);\n \t\tremove_file_from_cache(dst_name2);\n \t\t/*\n \t\t * Uncomment to leave the conflicting names in the resulting tree\n \t\t *\n-\t\t * update_file(0, ren1->pair->two->sha1, ren1->pair->two->mode, dst_name1);\n-\t\t * update_file(0, ren2->pair->two->sha1, ren2->pair->two->mode, dst_name2);\n+\t\t * update_file(o, 0, ren1->pair->two->sha1, ren1->pair->two->mode, dst_name1);\n+\t\t * update_file(o, 0, ren2->pair->two->sha1, ren2->pair->two->mode, dst_name2);\n \t\t */\n \t} else {\n \t\tupdate_stages(dst_name1, NULL, ren1->pair->two, NULL, 1);\n@@ -757,8 +753,8 @@ static void conflict_rename_dir(struct merge_options *o,\n {\n \tchar *new_path = unique_path(ren1->pair->two->path, branch1);\n \toutput(o, 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+\tremove_file(o, 0, ren1->pair->two->path, 0);\n+\tupdate_file(o, 0, ren1->pair->two->sha1, ren1->pair->two->mode, new_path);\n \tfree(new_path);\n }\n \n@@ -773,9 +769,9 @@ static void conflict_rename_rename_2(struct merge_options *o,\n \toutput(o, 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-\tupdate_file(0, ren1->pair->two->sha1, ren1->pair->two->mode, new_path1);\n-\tupdate_file(0, ren2->pair->two->sha1, ren2->pair->two->mode, new_path2);\n+\tremove_file(o, 0, ren1->pair->two->path, 0);\n+\tupdate_file(o, 0, ren1->pair->two->sha1, ren1->pair->two->mode, new_path1);\n+\tupdate_file(o, 0, ren2->pair->two->sha1, ren2->pair->two->mode, new_path2);\n \tfree(new_path2);\n \tfree(new_path1);\n }\n@@ -867,17 +863,18 @@ static int process_renames(struct merge_options *o,\n \t\t\t\t       \"rename \\\"%s\\\"->\\\"%s\\\" in \\\"%s\\\"%s\",\n \t\t\t\t       src, ren1_dst, branch1,\n \t\t\t\t       src, ren2_dst, branch2,\n-\t\t\t\t       index_only ? \" (left unresolved)\": \"\");\n-\t\t\t\tif (index_only) {\n+\t\t\t\t       o->index_only ? \" (left unresolved)\": \"\");\n+\t\t\t\tif (o->index_only) {\n \t\t\t\t\tremove_file_from_cache(src);\n-\t\t\t\t\tupdate_file(0, ren1->pair->one->sha1,\n+\t\t\t\t\tupdate_file(o, 0, ren1->pair->one->sha1,\n \t\t\t\t\t\t    ren1->pair->one->mode, src);\n \t\t\t\t}\n \t\t\t\tconflict_rename_rename(o, ren1, branch1, ren2, branch2);\n \t\t\t} else {\n \t\t\t\tstruct merge_file_info mfi;\n-\t\t\t\tremove_file(1, ren1_src, 1);\n-\t\t\t\tmfi = merge_file(ren1->pair->one,\n+\t\t\t\tremove_file(o, 1, ren1_src, 1);\n+\t\t\t\tmfi = merge_file(o,\n+\t\t\t\t\t\t ren1->pair->one,\n \t\t\t\t\t\t ren1->pair->two,\n \t\t\t\t\t\t ren2->pair->two,\n \t\t\t\t\t\t branch1,\n@@ -893,14 +890,14 @@ static int process_renames(struct merge_options *o,\n \t\t\t\t\t       ren1_dst);\n \t\t\t\t\tclean_merge = 0;\n \n-\t\t\t\t\tif (!index_only)\n+\t\t\t\t\tif (!o->index_only)\n \t\t\t\t\t\tupdate_stages(ren1_dst,\n \t\t\t\t\t\t\t      ren1->pair->one,\n \t\t\t\t\t\t\t      ren1->pair->two,\n \t\t\t\t\t\t\t      ren2->pair->two,\n \t\t\t\t\t\t\t      1 /* clear */);\n \t\t\t\t}\n-\t\t\t\tupdate_file(mfi.clean, mfi.sha, mfi.mode, ren1_dst);\n+\t\t\t\tupdate_file(o, mfi.clean, mfi.sha, mfi.mode, ren1_dst);\n \t\t\t}\n \t\t} else {\n \t\t\t/* Renamed in 1, maybe changed in 2 */\n@@ -909,7 +906,7 @@ static int process_renames(struct merge_options *o,\n \t\t\tstruct diff_filespec src_other, dst_other;\n \t\t\tint try_merge, stage = a_renames == renames1 ? 3: 2;\n \n-\t\t\tremove_file(1, ren1_src, index_only || stage == 3);\n+\t\t\tremove_file(o, 1, ren1_src, o->index_only || stage == 3);\n \n \t\t\thashcpy(src_other.sha1, ren1->src_entry->stages[stage].sha);\n \t\t\tsrc_other.mode = ren1->src_entry->stages[stage].mode;\n@@ -931,7 +928,7 @@ static int process_renames(struct merge_options *o,\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-\t\t\t\tupdate_file(0, ren1->pair->two->sha1, ren1->pair->two->mode, ren1_dst);\n+\t\t\t\tupdate_file(o, 0, ren1->pair->two->sha1, ren1->pair->two->mode, ren1_dst);\n \t\t\t} else if (!sha_eq(dst_other.sha1, null_sha1)) {\n \t\t\t\tconst char *new_path;\n \t\t\t\tclean_merge = 0;\n@@ -942,7 +939,7 @@ static int process_renames(struct merge_options *o,\n \t\t\t\t       ren1_dst, branch2);\n \t\t\t\tnew_path = unique_path(ren1_dst, branch2);\n \t\t\t\toutput(o, 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\tupdate_file(o, 0, dst_other.sha1, dst_other.mode, new_path);\n \t\t\t} else if ((item = string_list_lookup(ren1_dst, renames2Dst))) {\n \t\t\t\tren2 = item->util;\n \t\t\t\tclean_merge = 0;\n@@ -969,7 +966,7 @@ static int process_renames(struct merge_options *o,\n \t\t\t\t\tb = ren1->pair->two;\n \t\t\t\t\ta = &src_other;\n \t\t\t\t}\n-\t\t\t\tmfi = merge_file(one, a, b,\n+\t\t\t\tmfi = merge_file(o, one, a, b,\n \t\t\t\t\t\to->branch1, o->branch2);\n \n \t\t\t\tif (mfi.clean &&\n@@ -991,11 +988,11 @@ static int process_renames(struct merge_options *o,\n \t\t\t\t\t\t       ren1_dst);\n \t\t\t\t\t\tclean_merge = 0;\n \n-\t\t\t\t\t\tif (!index_only)\n+\t\t\t\t\t\tif (!o->index_only)\n \t\t\t\t\t\t\tupdate_stages(ren1_dst,\n \t\t\t\t\t\t\t\t      one, a, b, 1);\n \t\t\t\t\t}\n-\t\t\t\t\tupdate_file(mfi.clean, mfi.sha, mfi.mode, ren1_dst);\n+\t\t\t\t\tupdate_file(o, mfi.clean, mfi.sha, mfi.mode, ren1_dst);\n \t\t\t\t}\n \t\t\t}\n \t\t}\n@@ -1037,7 +1034,7 @@ static int process_entry(struct merge_options *o,\n \t\t\tif (a_sha)\n \t\t\t\toutput(o, 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\tremove_file(o, 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@@ -1046,13 +1043,13 @@ static int process_entry(struct merge_options *o,\n \t\t\t\t       \"and modified in %s. Version %s of %s left in tree.\",\n \t\t\t\t       path, o->branch1,\n \t\t\t\t       o->branch2, o->branch2, path);\n-\t\t\t\tupdate_file(0, b_sha, b_mode, path);\n+\t\t\t\tupdate_file(o, 0, b_sha, b_mode, path);\n \t\t\t} else {\n \t\t\t\toutput(o, 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, o->branch2,\n \t\t\t\t       o->branch1, o->branch1, path);\n-\t\t\t\tupdate_file(0, a_sha, a_mode, path);\n+\t\t\t\tupdate_file(o, 0, a_sha, a_mode, path);\n \t\t\t}\n \t\t}\n \n@@ -1084,11 +1081,11 @@ static int process_entry(struct merge_options *o,\n \t\t\toutput(o, 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\tremove_file(o, 0, path, 0);\n+\t\t\tupdate_file(o, 0, sha, mode, new_path);\n \t\t} else {\n \t\t\toutput(o, 2, \"Adding %s\", path);\n-\t\t\tupdate_file(1, sha, mode, path);\n+\t\t\tupdate_file(o, 1, sha, mode, path);\n \t\t}\n \t} else if (a_sha && b_sha) {\n \t\t/* Case C: Added in both (check for same permissions) and */\n@@ -1110,12 +1107,12 @@ static int process_entry(struct merge_options *o,\n \t\thashcpy(b.sha1, b_sha);\n \t\tb.mode = b_mode;\n \n-\t\tmfi = merge_file(&one, &a, &b,\n+\t\tmfi = merge_file(o, &one, &a, &b,\n \t\t\t\t o->branch1, o->branch2);\n \n \t\tclean_merge = mfi.clean;\n \t\tif (mfi.clean)\n-\t\t\tupdate_file(1, mfi.sha, mfi.mode, path);\n+\t\t\tupdate_file(o, 1, mfi.sha, mfi.mode, path);\n \t\telse if (S_ISGITLINK(mfi.mode))\n \t\t\toutput(o, 1, \"CONFLICT (submodule): Merge conflict in %s \"\n \t\t\t       \"- needs %s\", path, sha1_to_hex(b.sha1));\n@@ -1123,10 +1120,10 @@ static int process_entry(struct merge_options *o,\n \t\t\toutput(o, 1, \"CONFLICT (%s): Merge conflict in %s\",\n \t\t\t\t\treason, path);\n \n-\t\t\tif (index_only)\n-\t\t\t\tupdate_file(0, mfi.sha, mfi.mode, path);\n+\t\t\tif (o->index_only)\n+\t\t\t\tupdate_file(o, 0, mfi.sha, mfi.mode, path);\n \t\t\telse\n-\t\t\t\tupdate_file_flags(mfi.sha, mfi.mode, path,\n+\t\t\t\tupdate_file_flags(o, mfi.sha, mfi.mode, path,\n \t\t\t\t\t      0 /* update_cache */, 1 /* update_working_directory */);\n \t\t}\n \t} else if (!o_sha && !a_sha && !b_sha) {\n@@ -1134,7 +1131,7 @@ static int process_entry(struct merge_options *o,\n \t\t * this entry was deleted altogether. a_mode == 0 means\n \t\t * we had that path and want to actively remove it.\n \t\t */\n-\t\tremove_file(1, path, !a_mode);\n+\t\tremove_file(o, 1, path, !a_mode);\n \t} else\n \t\tdie(\"Fatal merge failure, shouldn't happen.\");\n \n@@ -1160,7 +1157,7 @@ int merge_trees(struct merge_options *o,\n \t\treturn 1;\n \t}\n \n-\tcode = git_merge_trees(index_only, common, head, merge);\n+\tcode = git_merge_trees(o->index_only, common, head, merge);\n \n \tif (code != 0)\n \t\tdie(\"merging of trees %s and %s failed\",\n@@ -1195,7 +1192,7 @@ int merge_trees(struct merge_options *o,\n \telse\n \t\tclean = 1;\n \n-\tif (index_only)\n+\tif (o->index_only)\n \t\t*result = write_tree_from_memory(o);\n \n \treturn clean;\n@@ -1283,14 +1280,14 @@ int merge_recursive(struct merge_options *o,\n \tdiscard_cache();\n \tif (!o->call_depth) {\n \t\tread_cache();\n-\t\tindex_only = 0;\n+\t\to->index_only = 0;\n \t} else\n-\t\tindex_only = 1;\n+\t\to->index_only = 1;\n \n \tclean = merge_trees(o, h1->tree, h2->tree, merged_common_ancestors->tree,\n \t\t\t    &mrtree);\n \n-\tif (index_only) {\n+\tif (o->index_only) {\n \t\t*result = make_virtual_commit(mrtree, \"merged tree\");\n \t\tcommit_list_insert(h1, &(*result)->parents);\n \t\tcommit_list_insert(h2, &(*result)->parents->next);\ndiff --git a/merge-recursive.h b/merge-recursive.h\nindex 4f55374..6622c3e 100644\n--- a/merge-recursive.h\n+++ b/merge-recursive.h\n@@ -10,6 +10,18 @@ struct merge_options {\n \tint diff_rename_limit;\n \tint merge_rename_limit;\n \tint call_depth;\n+\t/*\n+\t * This variable is used in a number of places but only written\n+\t * to in the 'merge_recursive' function.\n+\t *\n+\t * index_only == 1    => Don't leave any non-stage 0 entries in\n+\t *                       the cache and don't update the working\n+\t *                       directory.\n+\t *               0    => Leave unmerged entries in the cache and\n+\t *                       update the working directory.\n+\t */\n+\tint index_only;\n+\n };\n \n /* merge_trees() but with recursive ancestor consolidation */\n-- \n1.6.0.1\n"},{"id":"89561","messageId":"1220393639-20433-1-git-send-email-vmiklos@frugalware.org","threadId":"15340","inReplyTo":"b96b1e10babd379daea483e72d99d8e520e34506.1220392547.git.vmiklos@frugalware.org","subject":"[PATCH] Makefile: add merge_recursive.h to LIB_H","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-09-02T22:13:59Z","receivedAt":"2008-09-02T22:13:59Z","isPatch":true,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"When modifying merge-recursive.h, for example builtin-merge-recursive.c\nhave to be recompiled which was not true till now, causing various\nruntime errors using an incremental build.\n\nSigned-off-by: Miklos Vajna <vmiklos@frugalware.org>\n---\n\nOn Wed, Sep 03, 2008 at 12:05:32AM +0200, Miklos Vajna <vmiklos@frugalware.org> wrote:\n> Subject: Re: [PATCH 1/2] merge-recursive: move call_depth to struct\n>       merge_options\n\nWhile testing this one, I got some weird errors, finally they gone after\na 'touch builtin-merge-recursive.c', I guess this is the right fix.\n\n Makefile |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex f697618..bec6a84 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -362,6 +362,7 @@ LIB_H += list-objects.h\n LIB_H += ll-merge.h\n LIB_H += log-tree.h\n LIB_H += mailmap.h\n+LIB_H += merge_recursive.h\n LIB_H += object.h\n LIB_H += pack.h\n LIB_H += pack-refs.h\n-- \n1.6.0.1\n"},{"id":"89562","messageId":"7vk5dui34q.fsf@gitster.siamese.dyndns.org","threadId":"15340","inReplyTo":"cover.1220392547.git.vmiklos@frugalware.org","subject":"Re: [PATCH 0/2] Move call_depth and index_only to struct merge_options","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-09-02T22:39:33Z","receivedAt":"2008-09-02T22:39:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Miklos Vajna <vmiklos@frugalware.org> writes:\n\n> On Tue, Sep 02, 2008 at 01:02:31PM -0700, Junio C Hamano <gitster@pobox.com> wrote:\n>> I found it a bit disturbing that \"index_only\" and \"call_depth\" were\n>> not\n>> part of merge_options structure.\n>\n> Here are two patches to do it, on top of current mv/merge-recursive.\n\nI suspected that it always holds that \"index_only === !!call_depth\".\n\nShouldn't strbuf obuf be part of the merge_options structure that\ndescribes the current call status?\n"},{"id":"89563","messageId":"7vfxoii342.fsf@gitster.siamese.dyndns.org","threadId":"15340","inReplyTo":"1220393639-20433-1-git-send-email-vmiklos@frugalware.org","subject":"Re: [PATCH] Makefile: add merge_recursive.h to LIB_H","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-09-02T22:39:57Z","receivedAt":"2008-09-02T22:39:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Miklos Vajna <vmiklos@frugalware.org> writes:\n\n> When modifying merge-recursive.h, for example builtin-merge-recursive.c\n> have to be recompiled which was not true till now, causing various\n> runtime errors using an incremental build.\n>\n> Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>\n> ---\n>\n> On Wed, Sep 03, 2008 at 12:05:32AM +0200, Miklos Vajna <vmiklos@frugalware.org> wrote:\n>> Subject: Re: [PATCH 1/2] merge-recursive: move call_depth to struct\n>>       merge_options\n>\n> While testing this one, I got some weird errors, finally they gone after\n> a 'touch builtin-merge-recursive.c', I guess this is the right fix.\n\nThanks.\n"},{"id":"89573","messageId":"1220399345-21135-1-git-send-email-vmiklos@frugalware.org","threadId":"15340","inReplyTo":"7vfxoii342.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] Makefile: add merge_recursive.h to LIB_H","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-09-02T23:49:05Z","receivedAt":"2008-09-02T23:49:05Z","isPatch":true,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"When modifying merge-recursive.h, for example builtin-merge-recursive.c\nhave to be recompiled which was not true till now, causing various\nruntime errors using an incremental build.\n\nSigned-off-by: Miklos Vajna <vmiklos@frugalware.org>\n---\n\nn Tue, Sep 02, 2008 at 03:39:57PM -0700, Junio C Hamano <gitster@pobox.com> wrote:\n> > While testing this one, I got some weird errors, finally they gone\n> > after\n> > a 'touch builtin-merge-recursive.c', I guess this is the right fix.\n>\n> Thanks.\n\nUgh, typo. It is called 'merge-recursive.h'.\n\nSorry.\n\n Makefile |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex f697618..1647831 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -362,6 +362,7 @@ LIB_H += list-objects.h\n LIB_H += ll-merge.h\n LIB_H += log-tree.h\n LIB_H += mailmap.h\n+LIB_H += merge-recursive.h\n LIB_H += object.h\n LIB_H += pack.h\n LIB_H += pack-refs.h\n-- \n1.6.0.1\n"},{"id":"89579","messageId":"1220401019-30763-1-git-send-email-vmiklos@frugalware.org","threadId":"15340","inReplyTo":"7vk5dui34q.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] merge-recursive: get rid of the index_only global variable","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-09-03T00:16:59Z","receivedAt":"2008-09-03T00:16:59Z","isPatch":true,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"struct merge_options as already a call_depth member, where index_only ==\n!!call_depth. We always use index_only as a condition, so we can just\nuse call_depth instead of index_only.\n\nSigned-off-by: Miklos Vajna <vmiklos@frugalware.org>\n---\n\nOn Tue, Sep 02, 2008 at 03:39:33PM -0700, Junio C Hamano <gitster@pobox.com> wrote:\n> I suspected that it always holds that \"index_only === !!call_depth\".\n\nUhm, yes. Here is an updated version that just removes the global\nindex_only and does not touch the header.\n\nThe patch is still large, as I still needed to introduce struct\nmerge_options as the first parameter in several functions.\n\n merge-recursive.c |  140 +++++++++++++++++++++++++---------------------------\n 1 files changed, 67 insertions(+), 73 deletions(-)\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 5bb20aa..c426589 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -165,17 +165,6 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,\n \treturn add_cache_entry(ce, options);\n }\n \n-/*\n- * This is a global variable which is used in a number of places but\n- * only written to in the 'merge' function.\n- *\n- * index_only == 1    => Don't leave any non-stage 0 entries in the cache and\n- *                       don't update the working directory.\n- *               0    => Leave unmerged entries in the cache and update\n- *                       the working directory.\n- */\n-static int index_only = 0;\n-\n static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree)\n {\n \tparse_tree(tree);\n@@ -428,10 +417,11 @@ static int remove_path(const char *name)\n \treturn ret;\n }\n \n-static int remove_file(int clean, const char *path, int no_wd)\n+static int remove_file(struct merge_options *o, int clean,\n+\t\t       const char *path, int no_wd)\n {\n-\tint update_cache = index_only || clean;\n-\tint update_working_directory = !index_only && !no_wd;\n+\tint update_cache = o->call_depth || clean;\n+\tint update_working_directory = !o->call_depth && !no_wd;\n \n \tif (update_cache) {\n \t\tif (remove_file_from_cache(path))\n@@ -509,13 +499,14 @@ static int make_room_for_path(const char *path)\n \treturn error(msg, path, \": perhaps a D/F conflict?\");\n }\n \n-static void update_file_flags(const unsigned char *sha,\n+static void update_file_flags(struct merge_options *o,\n+\t\t\t      const unsigned char *sha,\n \t\t\t      unsigned mode,\n \t\t\t      const char *path,\n \t\t\t      int update_cache,\n \t\t\t      int update_wd)\n {\n-\tif (index_only)\n+\tif (o->call_depth)\n \t\tupdate_wd = 0;\n \n \tif (update_wd) {\n@@ -574,12 +565,13 @@ static void update_file_flags(const unsigned char *sha,\n \t\tadd_cacheinfo(mode, sha, path, 0, update_wd, ADD_CACHE_OK_TO_ADD);\n }\n \n-static void update_file(int clean,\n+static void update_file(struct merge_options *o,\n+\t\t\tint clean,\n \t\t\tconst unsigned char *sha,\n \t\t\tunsigned mode,\n \t\t\tconst char *path)\n {\n-\tupdate_file_flags(sha, mode, path, index_only || clean, !index_only);\n+\tupdate_file_flags(o, sha, mode, path, o->call_depth || clean, !o->call_depth);\n }\n \n /* Low level file merging, update and removal */\n@@ -609,8 +601,9 @@ static void fill_mm(const unsigned char *sha1, mmfile_t *mm)\n \tmm->size = size;\n }\n \n-static int merge_3way(mmbuffer_t *result_buf,\n-\t\t      struct diff_filespec *o,\n+static int merge_3way(struct merge_options *o,\n+\t\t      mmbuffer_t *result_buf,\n+\t\t      struct diff_filespec *one,\n \t\t      struct diff_filespec *a,\n \t\t      struct diff_filespec *b,\n \t\t      const char *branch1,\n@@ -623,13 +616,13 @@ static int merge_3way(mmbuffer_t *result_buf,\n \tname1 = xstrdup(mkpath(\"%s:%s\", branch1, a->path));\n \tname2 = xstrdup(mkpath(\"%s:%s\", branch2, b->path));\n \n-\tfill_mm(o->sha1, &orig);\n+\tfill_mm(one->sha1, &orig);\n \tfill_mm(a->sha1, &src1);\n \tfill_mm(b->sha1, &src2);\n \n \tmerge_status = ll_merge(result_buf, a->path, &orig,\n \t\t\t\t&src1, name1, &src2, name2,\n-\t\t\t\tindex_only);\n+\t\t\t\to->call_depth);\n \n \tfree(name1);\n \tfree(name2);\n@@ -639,9 +632,12 @@ static int merge_3way(mmbuffer_t *result_buf,\n \treturn merge_status;\n }\n \n-static struct merge_file_info merge_file(struct diff_filespec *o,\n-\t\tstruct diff_filespec *a, struct diff_filespec *b,\n-\t\tconst char *branch1, const char *branch2)\n+static struct merge_file_info merge_file(struct merge_options *o,\n+\t\t\t\t         struct diff_filespec *one,\n+\t\t\t\t\t struct diff_filespec *a,\n+\t\t\t\t\t struct diff_filespec *b,\n+\t\t\t\t\t const char *branch1,\n+\t\t\t\t\t const char *branch2)\n {\n \tstruct merge_file_info result;\n \tresult.merge = 0;\n@@ -657,31 +653,31 @@ static struct merge_file_info merge_file(struct diff_filespec *o,\n \t\t\thashcpy(result.sha, b->sha1);\n \t\t}\n \t} else {\n-\t\tif (!sha_eq(a->sha1, o->sha1) && !sha_eq(b->sha1, o->sha1))\n+\t\tif (!sha_eq(a->sha1, one->sha1) && !sha_eq(b->sha1, one->sha1))\n \t\t\tresult.merge = 1;\n \n \t\t/*\n \t\t * Merge modes\n \t\t */\n-\t\tif (a->mode == b->mode || a->mode == o->mode)\n+\t\tif (a->mode == b->mode || a->mode == one->mode)\n \t\t\tresult.mode = b->mode;\n \t\telse {\n \t\t\tresult.mode = a->mode;\n-\t\t\tif (b->mode != o->mode) {\n+\t\t\tif (b->mode != one->mode) {\n \t\t\t\tresult.clean = 0;\n \t\t\t\tresult.merge = 1;\n \t\t\t}\n \t\t}\n \n-\t\tif (sha_eq(a->sha1, b->sha1) || sha_eq(a->sha1, o->sha1))\n+\t\tif (sha_eq(a->sha1, b->sha1) || sha_eq(a->sha1, one->sha1))\n \t\t\thashcpy(result.sha, b->sha1);\n-\t\telse if (sha_eq(b->sha1, o->sha1))\n+\t\telse if (sha_eq(b->sha1, one->sha1))\n \t\t\thashcpy(result.sha, a->sha1);\n \t\telse if (S_ISREG(a->mode)) {\n \t\t\tmmbuffer_t result_buf;\n \t\t\tint merge_status;\n \n-\t\t\tmerge_status = merge_3way(&result_buf, o, a, b,\n+\t\t\tmerge_status = merge_3way(o, &result_buf, one, a, b,\n \t\t\t\t\t\t  branch1, branch2);\n \n \t\t\tif ((merge_status < 0) || !result_buf.ptr)\n@@ -726,22 +722,22 @@ static void conflict_rename_rename(struct merge_options *o,\n \t\tdst_name1 = del[delp++] = unique_path(ren1_dst, branch1);\n \t\toutput(o, 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\tremove_file(o, 0, ren1_dst, 0);\n \t}\n \tif (string_list_has_string(&current_directory_set, ren2_dst)) {\n \t\tdst_name2 = del[delp++] = unique_path(ren2_dst, branch2);\n \t\toutput(o, 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\tremove_file(o, 0, ren2_dst, 0);\n \t}\n-\tif (index_only) {\n+\tif (o->call_depth) {\n \t\tremove_file_from_cache(dst_name1);\n \t\tremove_file_from_cache(dst_name2);\n \t\t/*\n \t\t * Uncomment to leave the conflicting names in the resulting tree\n \t\t *\n-\t\t * update_file(0, ren1->pair->two->sha1, ren1->pair->two->mode, dst_name1);\n-\t\t * update_file(0, ren2->pair->two->sha1, ren2->pair->two->mode, dst_name2);\n+\t\t * update_file(o, 0, ren1->pair->two->sha1, ren1->pair->two->mode, dst_name1);\n+\t\t * update_file(o, 0, ren2->pair->two->sha1, ren2->pair->two->mode, dst_name2);\n \t\t */\n \t} else {\n \t\tupdate_stages(dst_name1, NULL, ren1->pair->two, NULL, 1);\n@@ -757,8 +753,8 @@ static void conflict_rename_dir(struct merge_options *o,\n {\n \tchar *new_path = unique_path(ren1->pair->two->path, branch1);\n \toutput(o, 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+\tremove_file(o, 0, ren1->pair->two->path, 0);\n+\tupdate_file(o, 0, ren1->pair->two->sha1, ren1->pair->two->mode, new_path);\n \tfree(new_path);\n }\n \n@@ -773,9 +769,9 @@ static void conflict_rename_rename_2(struct merge_options *o,\n \toutput(o, 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-\tupdate_file(0, ren1->pair->two->sha1, ren1->pair->two->mode, new_path1);\n-\tupdate_file(0, ren2->pair->two->sha1, ren2->pair->two->mode, new_path2);\n+\tremove_file(o, 0, ren1->pair->two->path, 0);\n+\tupdate_file(o, 0, ren1->pair->two->sha1, ren1->pair->two->mode, new_path1);\n+\tupdate_file(o, 0, ren2->pair->two->sha1, ren2->pair->two->mode, new_path2);\n \tfree(new_path2);\n \tfree(new_path1);\n }\n@@ -867,17 +863,18 @@ static int process_renames(struct merge_options *o,\n \t\t\t\t       \"rename \\\"%s\\\"->\\\"%s\\\" in \\\"%s\\\"%s\",\n \t\t\t\t       src, ren1_dst, branch1,\n \t\t\t\t       src, ren2_dst, branch2,\n-\t\t\t\t       index_only ? \" (left unresolved)\": \"\");\n-\t\t\t\tif (index_only) {\n+\t\t\t\t       o->call_depth ? \" (left unresolved)\": \"\");\n+\t\t\t\tif (o->call_depth) {\n \t\t\t\t\tremove_file_from_cache(src);\n-\t\t\t\t\tupdate_file(0, ren1->pair->one->sha1,\n+\t\t\t\t\tupdate_file(o, 0, ren1->pair->one->sha1,\n \t\t\t\t\t\t    ren1->pair->one->mode, src);\n \t\t\t\t}\n \t\t\t\tconflict_rename_rename(o, ren1, branch1, ren2, branch2);\n \t\t\t} else {\n \t\t\t\tstruct merge_file_info mfi;\n-\t\t\t\tremove_file(1, ren1_src, 1);\n-\t\t\t\tmfi = merge_file(ren1->pair->one,\n+\t\t\t\tremove_file(o, 1, ren1_src, 1);\n+\t\t\t\tmfi = merge_file(o,\n+\t\t\t\t\t\t ren1->pair->one,\n \t\t\t\t\t\t ren1->pair->two,\n \t\t\t\t\t\t ren2->pair->two,\n \t\t\t\t\t\t branch1,\n@@ -893,14 +890,14 @@ static int process_renames(struct merge_options *o,\n \t\t\t\t\t       ren1_dst);\n \t\t\t\t\tclean_merge = 0;\n \n-\t\t\t\t\tif (!index_only)\n+\t\t\t\t\tif (!o->call_depth)\n \t\t\t\t\t\tupdate_stages(ren1_dst,\n \t\t\t\t\t\t\t      ren1->pair->one,\n \t\t\t\t\t\t\t      ren1->pair->two,\n \t\t\t\t\t\t\t      ren2->pair->two,\n \t\t\t\t\t\t\t      1 /* clear */);\n \t\t\t\t}\n-\t\t\t\tupdate_file(mfi.clean, mfi.sha, mfi.mode, ren1_dst);\n+\t\t\t\tupdate_file(o, mfi.clean, mfi.sha, mfi.mode, ren1_dst);\n \t\t\t}\n \t\t} else {\n \t\t\t/* Renamed in 1, maybe changed in 2 */\n@@ -909,7 +906,7 @@ static int process_renames(struct merge_options *o,\n \t\t\tstruct diff_filespec src_other, dst_other;\n \t\t\tint try_merge, stage = a_renames == renames1 ? 3: 2;\n \n-\t\t\tremove_file(1, ren1_src, index_only || stage == 3);\n+\t\t\tremove_file(o, 1, ren1_src, o->call_depth || stage == 3);\n \n \t\t\thashcpy(src_other.sha1, ren1->src_entry->stages[stage].sha);\n \t\t\tsrc_other.mode = ren1->src_entry->stages[stage].mode;\n@@ -931,7 +928,7 @@ static int process_renames(struct merge_options *o,\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-\t\t\t\tupdate_file(0, ren1->pair->two->sha1, ren1->pair->two->mode, ren1_dst);\n+\t\t\t\tupdate_file(o, 0, ren1->pair->two->sha1, ren1->pair->two->mode, ren1_dst);\n \t\t\t} else if (!sha_eq(dst_other.sha1, null_sha1)) {\n \t\t\t\tconst char *new_path;\n \t\t\t\tclean_merge = 0;\n@@ -942,7 +939,7 @@ static int process_renames(struct merge_options *o,\n \t\t\t\t       ren1_dst, branch2);\n \t\t\t\tnew_path = unique_path(ren1_dst, branch2);\n \t\t\t\toutput(o, 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\tupdate_file(o, 0, dst_other.sha1, dst_other.mode, new_path);\n \t\t\t} else if ((item = string_list_lookup(ren1_dst, renames2Dst))) {\n \t\t\t\tren2 = item->util;\n \t\t\t\tclean_merge = 0;\n@@ -969,7 +966,7 @@ static int process_renames(struct merge_options *o,\n \t\t\t\t\tb = ren1->pair->two;\n \t\t\t\t\ta = &src_other;\n \t\t\t\t}\n-\t\t\t\tmfi = merge_file(one, a, b,\n+\t\t\t\tmfi = merge_file(o, one, a, b,\n \t\t\t\t\t\to->branch1, o->branch2);\n \n \t\t\t\tif (mfi.clean &&\n@@ -991,11 +988,11 @@ static int process_renames(struct merge_options *o,\n \t\t\t\t\t\t       ren1_dst);\n \t\t\t\t\t\tclean_merge = 0;\n \n-\t\t\t\t\t\tif (!index_only)\n+\t\t\t\t\t\tif (!o->call_depth)\n \t\t\t\t\t\t\tupdate_stages(ren1_dst,\n \t\t\t\t\t\t\t\t      one, a, b, 1);\n \t\t\t\t\t}\n-\t\t\t\t\tupdate_file(mfi.clean, mfi.sha, mfi.mode, ren1_dst);\n+\t\t\t\t\tupdate_file(o, mfi.clean, mfi.sha, mfi.mode, ren1_dst);\n \t\t\t\t}\n \t\t\t}\n \t\t}\n@@ -1037,7 +1034,7 @@ static int process_entry(struct merge_options *o,\n \t\t\tif (a_sha)\n \t\t\t\toutput(o, 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\tremove_file(o, 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@@ -1046,13 +1043,13 @@ static int process_entry(struct merge_options *o,\n \t\t\t\t       \"and modified in %s. Version %s of %s left in tree.\",\n \t\t\t\t       path, o->branch1,\n \t\t\t\t       o->branch2, o->branch2, path);\n-\t\t\t\tupdate_file(0, b_sha, b_mode, path);\n+\t\t\t\tupdate_file(o, 0, b_sha, b_mode, path);\n \t\t\t} else {\n \t\t\t\toutput(o, 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, o->branch2,\n \t\t\t\t       o->branch1, o->branch1, path);\n-\t\t\t\tupdate_file(0, a_sha, a_mode, path);\n+\t\t\t\tupdate_file(o, 0, a_sha, a_mode, path);\n \t\t\t}\n \t\t}\n \n@@ -1084,11 +1081,11 @@ static int process_entry(struct merge_options *o,\n \t\t\toutput(o, 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\tremove_file(o, 0, path, 0);\n+\t\t\tupdate_file(o, 0, sha, mode, new_path);\n \t\t} else {\n \t\t\toutput(o, 2, \"Adding %s\", path);\n-\t\t\tupdate_file(1, sha, mode, path);\n+\t\t\tupdate_file(o, 1, sha, mode, path);\n \t\t}\n \t} else if (a_sha && b_sha) {\n \t\t/* Case C: Added in both (check for same permissions) and */\n@@ -1110,12 +1107,12 @@ static int process_entry(struct merge_options *o,\n \t\thashcpy(b.sha1, b_sha);\n \t\tb.mode = b_mode;\n \n-\t\tmfi = merge_file(&one, &a, &b,\n+\t\tmfi = merge_file(o, &one, &a, &b,\n \t\t\t\t o->branch1, o->branch2);\n \n \t\tclean_merge = mfi.clean;\n \t\tif (mfi.clean)\n-\t\t\tupdate_file(1, mfi.sha, mfi.mode, path);\n+\t\t\tupdate_file(o, 1, mfi.sha, mfi.mode, path);\n \t\telse if (S_ISGITLINK(mfi.mode))\n \t\t\toutput(o, 1, \"CONFLICT (submodule): Merge conflict in %s \"\n \t\t\t       \"- needs %s\", path, sha1_to_hex(b.sha1));\n@@ -1123,10 +1120,10 @@ static int process_entry(struct merge_options *o,\n \t\t\toutput(o, 1, \"CONFLICT (%s): Merge conflict in %s\",\n \t\t\t\t\treason, path);\n \n-\t\t\tif (index_only)\n-\t\t\t\tupdate_file(0, mfi.sha, mfi.mode, path);\n+\t\t\tif (o->call_depth)\n+\t\t\t\tupdate_file(o, 0, mfi.sha, mfi.mode, path);\n \t\t\telse\n-\t\t\t\tupdate_file_flags(mfi.sha, mfi.mode, path,\n+\t\t\t\tupdate_file_flags(o, mfi.sha, mfi.mode, path,\n \t\t\t\t\t      0 /* update_cache */, 1 /* update_working_directory */);\n \t\t}\n \t} else if (!o_sha && !a_sha && !b_sha) {\n@@ -1134,7 +1131,7 @@ static int process_entry(struct merge_options *o,\n \t\t * this entry was deleted altogether. a_mode == 0 means\n \t\t * we had that path and want to actively remove it.\n \t\t */\n-\t\tremove_file(1, path, !a_mode);\n+\t\tremove_file(o, 1, path, !a_mode);\n \t} else\n \t\tdie(\"Fatal merge failure, shouldn't happen.\");\n \n@@ -1160,7 +1157,7 @@ int merge_trees(struct merge_options *o,\n \t\treturn 1;\n \t}\n \n-\tcode = git_merge_trees(index_only, common, head, merge);\n+\tcode = git_merge_trees(o->call_depth, common, head, merge);\n \n \tif (code != 0)\n \t\tdie(\"merging of trees %s and %s failed\",\n@@ -1195,7 +1192,7 @@ int merge_trees(struct merge_options *o,\n \telse\n \t\tclean = 1;\n \n-\tif (index_only)\n+\tif (o->call_depth)\n \t\t*result = write_tree_from_memory(o);\n \n \treturn clean;\n@@ -1281,16 +1278,13 @@ int merge_recursive(struct merge_options *o,\n \t}\n \n \tdiscard_cache();\n-\tif (!o->call_depth) {\n+\tif (!o->call_depth)\n \t\tread_cache();\n-\t\tindex_only = 0;\n-\t} else\n-\t\tindex_only = 1;\n \n \tclean = merge_trees(o, h1->tree, h2->tree, merged_common_ancestors->tree,\n \t\t\t    &mrtree);\n \n-\tif (index_only) {\n+\tif (o->call_depth) {\n \t\t*result = make_virtual_commit(mrtree, \"merged tree\");\n \t\tcommit_list_insert(h1, &(*result)->parents);\n \t\tcommit_list_insert(h2, &(*result)->parents->next);\n-- \n1.6.0.1\n"},{"id":"89583","messageId":"1220402349-7181-1-git-send-email-vmiklos@frugalware.org","threadId":"15340","inReplyTo":"7vk5dui34q.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] merge-recursive: move the global obuf to struct merge_options","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-09-03T00:39:09Z","receivedAt":"2008-09-03T00:39:09Z","isPatch":true,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>\n---\n\nOn Tue, Sep 02, 2008 at 03:39:33PM -0700, Junio C Hamano <gitster@pobox.com> wrote:\n> Shouldn't strbuf obuf be part of the merge_options structure that\n> describes the current call status?\n\nIt can be done, see below. :-)\n\nBTW, there are 3 leftovers: make_virtual_commit()'s virtual_id and the\nglobal current_file_set/current_directory_set. I guess all of them could\nbe moved to merge_options as well. (I don't have more time today to do\nso, but I can do it tomorrow, unless you see some fundamental problem\nwith it.)\n\n merge-recursive.c |   37 ++++++++++++++++++-------------------\n merge-recursive.h |    1 +\n 2 files changed, 19 insertions(+), 19 deletions(-)\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex c426589..d4f12d0 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -80,18 +80,16 @@ struct stage_data\n static struct string_list current_file_set = {NULL, 0, 0, 1};\n static struct string_list current_directory_set = {NULL, 0, 0, 1};\n \n-static struct strbuf obuf = STRBUF_INIT;\n-\n static int show(struct merge_options *o, int v)\n {\n \treturn (!o->call_depth && o->verbosity >= v) || o->verbosity >= 5;\n }\n \n-static void flush_output(void)\n+static void flush_output(struct merge_options *o)\n {\n-\tif (obuf.len) {\n-\t\tfputs(obuf.buf, stdout);\n-\t\tstrbuf_reset(&obuf);\n+\tif (o->obuf.len) {\n+\t\tfputs(o->obuf.buf, stdout);\n+\t\tstrbuf_reset(&o->obuf);\n \t}\n }\n \n@@ -103,35 +101,35 @@ static void output(struct merge_options *o, int v, const char *fmt, ...)\n \tif (!show(o, v))\n \t\treturn;\n \n-\tstrbuf_grow(&obuf, o->call_depth * 2 + 2);\n-\tmemset(obuf.buf + obuf.len, ' ', o->call_depth * 2);\n-\tstrbuf_setlen(&obuf, obuf.len + o->call_depth * 2);\n+\tstrbuf_grow(&o->obuf, o->call_depth * 2 + 2);\n+\tmemset(o->obuf.buf + o->obuf.len, ' ', o->call_depth * 2);\n+\tstrbuf_setlen(&o->obuf, o->obuf.len + o->call_depth * 2);\n \n \tva_start(ap, fmt);\n-\tlen = vsnprintf(obuf.buf + obuf.len, strbuf_avail(&obuf), fmt, ap);\n+\tlen = vsnprintf(o->obuf.buf + o->obuf.len, strbuf_avail(&o->obuf), fmt, ap);\n \tva_end(ap);\n \n \tif (len < 0)\n \t\tlen = 0;\n-\tif (len >= strbuf_avail(&obuf)) {\n-\t\tstrbuf_grow(&obuf, len + 2);\n+\tif (len >= strbuf_avail(&o->obuf)) {\n+\t\tstrbuf_grow(&o->obuf, len + 2);\n \t\tva_start(ap, fmt);\n-\t\tlen = vsnprintf(obuf.buf + obuf.len, strbuf_avail(&obuf), fmt, ap);\n+\t\tlen = vsnprintf(o->obuf.buf + o->obuf.len, strbuf_avail(&o->obuf), fmt, ap);\n \t\tva_end(ap);\n-\t\tif (len >= strbuf_avail(&obuf)) {\n+\t\tif (len >= strbuf_avail(&o->obuf)) {\n \t\t\tdie(\"this should not happen, your snprintf is broken\");\n \t\t}\n \t}\n-\tstrbuf_setlen(&obuf, obuf.len + len);\n-\tstrbuf_add(&obuf, \"\\n\", 1);\n+\tstrbuf_setlen(&o->obuf, o->obuf.len + len);\n+\tstrbuf_add(&o->obuf, \"\\n\", 1);\n \tif (!o->buffer_output)\n-\t\tflush_output();\n+\t\tflush_output(o);\n }\n \n static void output_commit_title(struct merge_options *o, struct commit *commit)\n {\n \tint i;\n-\tflush_output();\n+\tflush_output(o);\n \tfor (i = o->call_depth; i--;)\n \t\tfputs(\"  \", stdout);\n \tif (commit->util)\n@@ -1289,7 +1287,7 @@ int merge_recursive(struct merge_options *o,\n \t\tcommit_list_insert(h1, &(*result)->parents);\n \t\tcommit_list_insert(h2, &(*result)->parents->next);\n \t}\n-\tflush_output();\n+\tflush_output(o);\n \treturn clean;\n }\n \n@@ -1375,4 +1373,5 @@ void init_merge_options(struct merge_options *o)\n \t\t\tstrtol(getenv(\"GIT_MERGE_VERBOSITY\"), NULL, 10);\n \tif (o->verbosity >= 5)\n \t\to->buffer_output = 0;\n+\tstrbuf_init(&o->obuf, 0);\n }\ndiff --git a/merge-recursive.h b/merge-recursive.h\nindex 4f55374..be84d9b 100644\n--- a/merge-recursive.h\n+++ b/merge-recursive.h\n@@ -10,6 +10,7 @@ struct merge_options {\n \tint diff_rename_limit;\n \tint merge_rename_limit;\n \tint call_depth;\n+\tstruct strbuf obuf;\n };\n \n /* merge_trees() but with recursive ancestor consolidation */\n-- \n1.6.0.1\n"},{"id":"89655","messageId":"cover.1220463034.git.vmiklos@frugalware.org","threadId":"15340","inReplyTo":"1220402349-7181-1-git-send-email-vmiklos@frugalware.org","subject":"Re: [PATCH] merge-recursive: move the global obuf to struct merge_options","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-09-03T17:34:36Z","receivedAt":"2008-09-03T17:34:36Z","isPatch":true,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"On Wed, Sep 03, 2008 at 02:39:09AM +0200, Miklos Vajna <vmiklos@frugalware.org> wrote:\n> BTW, there are 3 leftovers: make_virtual_commit()'s virtual_id and the\n> global current_file_set/current_directory_set. I guess all of them\n> could be moved to merge_options as well. (I don't have more time today\n> to do so, but I can do it tomorrow, unless you see some fundamental\n> problem with it.)\n\nHere are the two patches, that do this.\n\nThese, and the 4 other related patches which are not yet in git.git at\nthe moment are also available in the 'merge-recursive' branch of\ngit://repo.or.cz/git/vmiklos.git.\n\nMiklos Vajna (2):\n  merge-recursive: move current_{file,directory}_set to struct\n    merge_options\n  merge-recursive: move make_virtual_commit()'s virtual_id to\n    merge_options\n\n merge-recursive.c |   80 ++++++++++++++++++++++++++++------------------------\n merge-recursive.h |    5 +++\n 2 files changed, 48 insertions(+), 37 deletions(-)\n"},{"id":"89656","messageId":"e3e7f1cbf3746e7d2ef2c77227c9367a361c10b9.1220463034.git.vmiklos@frugalware.org","threadId":"15340","inReplyTo":"cover.1220463034.git.vmiklos@frugalware.org","subject":"[PATCH 1/2] merge-recursive: move current_{file,directory}_set to struct merge_options","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-09-03T17:34:37Z","receivedAt":"2008-09-03T17:34:37Z","isPatch":true,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>\n---\n merge-recursive.c |   56 +++++++++++++++++++++++++++-------------------------\n merge-recursive.h |    4 +++\n 2 files changed, 33 insertions(+), 27 deletions(-)\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex d4f12d0..964b8f3 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -77,9 +77,6 @@ struct stage_data\n \tunsigned processed:1;\n };\n \n-static struct string_list current_file_set = {NULL, 0, 0, 1};\n-static struct string_list current_directory_set = {NULL, 0, 0, 1};\n-\n static int show(struct merge_options *o, int v)\n {\n \treturn (!o->call_depth && o->verbosity >= v) || o->verbosity >= 5;\n@@ -235,22 +232,23 @@ static int save_files_dirs(const unsigned char *sha1,\n \tmemcpy(newpath, base, baselen);\n \tmemcpy(newpath + baselen, path, len);\n \tnewpath[baselen + len] = '\\0';\n+\tstruct merge_options *o = context;\n \n \tif (S_ISDIR(mode))\n-\t\tstring_list_insert(newpath, &current_directory_set);\n+\t\tstring_list_insert(newpath, &o->current_directory_set);\n \telse\n-\t\tstring_list_insert(newpath, &current_file_set);\n+\t\tstring_list_insert(newpath, &o->current_file_set);\n \tfree(newpath);\n \n \treturn READ_TREE_RECURSIVE;\n }\n \n-static int get_files_dirs(struct tree *tree)\n+static int get_files_dirs(struct merge_options *o, struct tree *tree)\n {\n \tint n;\n-\tif (read_tree_recursive(tree, \"\", 0, 0, NULL, save_files_dirs, NULL))\n+\tif (read_tree_recursive(tree, \"\", 0, 0, NULL, save_files_dirs, o))\n \t\treturn 0;\n-\tn = current_file_set.nr + current_directory_set.nr;\n+\tn = o->current_file_set.nr + o->current_directory_set.nr;\n \treturn n;\n }\n \n@@ -434,7 +432,7 @@ static int remove_file(struct merge_options *o, int clean,\n \treturn 0;\n }\n \n-static char *unique_path(const char *path, const char *branch)\n+static char *unique_path(struct merge_options *o, const char *path, const char *branch)\n {\n \tchar *newpath = xmalloc(strlen(path) + 1 + strlen(branch) + 8 + 1);\n \tint suffix = 0;\n@@ -446,12 +444,12 @@ static char *unique_path(const char *path, const char *branch)\n \tfor (; *p; ++p)\n \t\tif ('/' == *p)\n \t\t\t*p = '_';\n-\twhile (string_list_has_string(&current_file_set, newpath) ||\n-\t       string_list_has_string(&current_directory_set, newpath) ||\n+\twhile (string_list_has_string(&o->current_file_set, newpath) ||\n+\t       string_list_has_string(&o->current_directory_set, newpath) ||\n \t       lstat(newpath, &st) == 0)\n \t\tsprintf(p, \"_%d\", suffix++);\n \n-\tstring_list_insert(newpath, &current_file_set);\n+\tstring_list_insert(newpath, &o->current_file_set);\n \treturn newpath;\n }\n \n@@ -716,14 +714,14 @@ static void conflict_rename_rename(struct merge_options *o,\n \tconst char *ren2_dst = ren2->pair->two->path;\n \tconst char *dst_name1 = ren1_dst;\n \tconst char *dst_name2 = ren2_dst;\n-\tif (string_list_has_string(&current_directory_set, ren1_dst)) {\n-\t\tdst_name1 = del[delp++] = unique_path(ren1_dst, branch1);\n+\tif (string_list_has_string(&o->current_directory_set, ren1_dst)) {\n+\t\tdst_name1 = del[delp++] = unique_path(o, ren1_dst, branch1);\n \t\toutput(o, 1, \"%s is a directory in %s adding as %s instead\",\n \t\t       ren1_dst, branch2, dst_name1);\n \t\tremove_file(o, 0, ren1_dst, 0);\n \t}\n-\tif (string_list_has_string(&current_directory_set, ren2_dst)) {\n-\t\tdst_name2 = del[delp++] = unique_path(ren2_dst, branch2);\n+\tif (string_list_has_string(&o->current_directory_set, ren2_dst)) {\n+\t\tdst_name2 = del[delp++] = unique_path(o, ren2_dst, branch2);\n \t\toutput(o, 1, \"%s is a directory in %s adding as %s instead\",\n \t\t       ren2_dst, branch1, dst_name2);\n \t\tremove_file(o, 0, ren2_dst, 0);\n@@ -749,7 +747,7 @@ static void conflict_rename_dir(struct merge_options *o,\n \t\t\t\tstruct rename *ren1,\n \t\t\t\tconst char *branch1)\n {\n-\tchar *new_path = unique_path(ren1->pair->two->path, branch1);\n+\tchar *new_path = unique_path(o, ren1->pair->two->path, branch1);\n \toutput(o, 1, \"Renaming %s to %s instead\", ren1->pair->one->path, new_path);\n \tremove_file(o, 0, ren1->pair->two->path, 0);\n \tupdate_file(o, 0, ren1->pair->two->sha1, ren1->pair->two->mode, new_path);\n@@ -762,8 +760,8 @@ static void conflict_rename_rename_2(struct merge_options *o,\n \t\t\t\t     struct rename *ren2,\n \t\t\t\t     const char *branch2)\n {\n-\tchar *new_path1 = unique_path(ren1->pair->two->path, branch1);\n-\tchar *new_path2 = unique_path(ren2->pair->two->path, branch2);\n+\tchar *new_path1 = unique_path(o, ren1->pair->two->path, branch1);\n+\tchar *new_path2 = unique_path(o, ren2->pair->two->path, branch2);\n \toutput(o, 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@@ -913,7 +911,7 @@ static int process_renames(struct merge_options *o,\n \n \t\t\ttry_merge = 0;\n \n-\t\t\tif (string_list_has_string(&current_directory_set, ren1_dst)) {\n+\t\t\tif (string_list_has_string(&o->current_directory_set, ren1_dst)) {\n \t\t\t\tclean_merge = 0;\n \t\t\t\toutput(o, 1, \"CONFLICT (rename/directory): Rename %s->%s in %s \"\n \t\t\t\t       \" directory %s added in %s\",\n@@ -935,7 +933,7 @@ static int process_renames(struct merge_options *o,\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\tnew_path = unique_path(o, ren1_dst, branch2);\n \t\t\t\toutput(o, 1, \"Adding as %s instead\", new_path);\n \t\t\t\tupdate_file(o, 0, dst_other.sha1, dst_other.mode, new_path);\n \t\t\t} else if ((item = string_list_lookup(ren1_dst, renames2Dst))) {\n@@ -1073,8 +1071,8 @@ static int process_entry(struct merge_options *o,\n \t\t\tsha = b_sha;\n \t\t\tconf = \"directory/file\";\n \t\t}\n-\t\tif (string_list_has_string(&current_directory_set, path)) {\n-\t\t\tconst char *new_path = unique_path(path, add_branch);\n+\t\tif (string_list_has_string(&o->current_directory_set, path)) {\n+\t\t\tconst char *new_path = unique_path(o, path, add_branch);\n \t\t\tclean_merge = 0;\n \t\t\toutput(o, 1, \"CONFLICT (%s): There is a directory with name %s in %s. \"\n \t\t\t       \"Adding %s as %s\",\n@@ -1165,10 +1163,10 @@ int merge_trees(struct merge_options *o,\n \tif (unmerged_cache()) {\n \t\tstruct string_list *entries, *re_head, *re_merge;\n \t\tint i;\n-\t\tstring_list_clear(&current_file_set, 1);\n-\t\tstring_list_clear(&current_directory_set, 1);\n-\t\tget_files_dirs(head);\n-\t\tget_files_dirs(merge);\n+\t\tstring_list_clear(&o->current_file_set, 1);\n+\t\tstring_list_clear(&o->current_directory_set, 1);\n+\t\tget_files_dirs(o, head);\n+\t\tget_files_dirs(o, merge);\n \n \t\tentries = get_unmerged();\n \t\tre_head  = get_renames(o, head, common, head, merge, entries);\n@@ -1374,4 +1372,8 @@ void init_merge_options(struct merge_options *o)\n \tif (o->verbosity >= 5)\n \t\to->buffer_output = 0;\n \tstrbuf_init(&o->obuf, 0);\n+\tmemset(&o->current_file_set, 0, sizeof(struct string_list));\n+\to->current_file_set.strdup_strings = 1;\n+\tmemset(&o->current_directory_set, 0, sizeof(struct string_list));\n+\to->current_directory_set.strdup_strings = 1;\n }\ndiff --git a/merge-recursive.h b/merge-recursive.h\nindex be84d9b..fd138ca 100644\n--- a/merge-recursive.h\n+++ b/merge-recursive.h\n@@ -1,6 +1,8 @@\n #ifndef MERGE_RECURSIVE_H\n #define MERGE_RECURSIVE_H\n \n+#include \"string-list.h\"\n+\n struct merge_options {\n \tconst char *branch1;\n \tconst char *branch2;\n@@ -11,6 +13,8 @@ struct merge_options {\n \tint merge_rename_limit;\n \tint call_depth;\n \tstruct strbuf obuf;\n+\tstruct string_list current_file_set;\n+\tstruct string_list current_directory_set;\n };\n \n /* merge_trees() but with recursive ancestor consolidation */\n-- \n1.6.0.1\n"},{"id":"89657","messageId":"f2a1ff8d2fe354265a80534cd7beaaa95c2ffc54.1220463034.git.vmiklos@frugalware.org","threadId":"15340","inReplyTo":"e3e7f1cbf3746e7d2ef2c77227c9367a361c10b9.1220463034.git.vmiklos@frugalware.org","subject":"[PATCH 2/2] merge-recursive: move make_virtual_commit()'s virtual_id to merge_options","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-09-03T17:34:38Z","receivedAt":"2008-09-03T17:34:38Z","isPatch":true,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"This is the last patch in this series, now all static variables in\nmerge-recursive.c are moved to struct merge_options.\n\nSigned-off-by: Miklos Vajna <vmiklos@frugalware.org>\n---\n merge-recursive.c |   24 ++++++++++++++----------\n merge-recursive.h |    1 +\n 2 files changed, 15 insertions(+), 10 deletions(-)\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 964b8f3..4fa3308 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -40,13 +40,14 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two)\n  * - *(int *)commit->object.sha1 set to the virtual id.\n  */\n \n-struct commit *make_virtual_commit(struct tree *tree, const char *comment)\n+struct commit *make_virtual_commit(struct merge_options *o,\n+\t\t\t\t   struct tree *tree,\n+\t\t\t\t   const char *comment)\n {\n \tstruct commit *commit = xcalloc(1, sizeof(struct commit));\n-\tstatic unsigned virtual_id = 1;\n \tcommit->tree = tree;\n \tcommit->util = (void*)comment;\n-\t*(int*)commit->object.sha1 = virtual_id++;\n+\t*(int*)commit->object.sha1 = o->virtual_id++;\n \t/* avoid warnings */\n \tcommit->object.parsed = 1;\n \treturn commit;\n@@ -1245,7 +1246,7 @@ int merge_recursive(struct merge_options *o,\n \t\ttree->object.parsed = 1;\n \t\ttree->object.type = OBJ_TREE;\n \t\tpretend_sha1_file(NULL, 0, OBJ_TREE, tree->object.sha1);\n-\t\tmerged_common_ancestors = make_virtual_commit(tree, \"ancestor\");\n+\t\tmerged_common_ancestors = make_virtual_commit(o, tree, \"ancestor\");\n \t}\n \n \tfor (iter = ca; iter; iter = iter->next) {\n@@ -1281,7 +1282,7 @@ int merge_recursive(struct merge_options *o,\n \t\t\t    &mrtree);\n \n \tif (o->call_depth) {\n-\t\t*result = make_virtual_commit(mrtree, \"merged tree\");\n+\t\t*result = make_virtual_commit(o, mrtree, \"merged tree\");\n \t\tcommit_list_insert(h1, &(*result)->parents);\n \t\tcommit_list_insert(h2, &(*result)->parents->next);\n \t}\n@@ -1289,7 +1290,9 @@ int merge_recursive(struct merge_options *o,\n \treturn clean;\n }\n \n-static struct commit *get_ref(const unsigned char *sha1, const char *name)\n+static struct commit *get_ref(struct merge_options *o,\n+\t\t\t      const unsigned char *sha1,\n+\t\t\t      const char *name)\n {\n \tstruct object *object;\n \n@@ -1297,7 +1300,7 @@ static struct commit *get_ref(const unsigned char *sha1, const char *name)\n \tif (!object)\n \t\treturn NULL;\n \tif (object->type == OBJ_TREE)\n-\t\treturn make_virtual_commit((struct tree*)object, name);\n+\t\treturn make_virtual_commit(o, (struct tree*)object, name);\n \tif (object->type != OBJ_COMMIT)\n \t\treturn NULL;\n \tif (parse_commit((struct commit *)object))\n@@ -1314,15 +1317,15 @@ int merge_recursive_generic(struct merge_options *o,\n {\n \tint clean, index_fd;\n \tstruct lock_file *lock = xcalloc(1, sizeof(struct lock_file));\n-\tstruct commit *head_commit = get_ref(head, o->branch1);\n-\tstruct commit *next_commit = get_ref(merge, o->branch2);\n+\tstruct commit *head_commit = get_ref(o, head, o->branch1);\n+\tstruct commit *next_commit = get_ref(o, merge, o->branch2);\n \tstruct commit_list *ca = NULL;\n \n \tif (base_list) {\n \t\tint i;\n \t\tfor (i = 0; i < num_base_list; ++i) {\n \t\t\tstruct commit *base;\n-\t\t\tif (!(base = get_ref(base_list[i], sha1_to_hex(base_list[i]))))\n+\t\t\tif (!(base = get_ref(o, base_list[i], sha1_to_hex(base_list[i]))))\n \t\t\t\treturn error(\"Could not parse object '%s'\",\n \t\t\t\t\tsha1_to_hex(base_list[i]));\n \t\t\tcommit_list_insert(base, &ca);\n@@ -1376,4 +1379,5 @@ void init_merge_options(struct merge_options *o)\n \to->current_file_set.strdup_strings = 1;\n \tmemset(&o->current_directory_set, 0, sizeof(struct string_list));\n \to->current_directory_set.strdup_strings = 1;\n+\to->virtual_id = 1;\n }\ndiff --git a/merge-recursive.h b/merge-recursive.h\nindex fd138ca..bc23fe0 100644\n--- a/merge-recursive.h\n+++ b/merge-recursive.h\n@@ -15,6 +15,7 @@ struct merge_options {\n \tstruct strbuf obuf;\n \tstruct string_list current_file_set;\n \tstruct string_list current_directory_set;\n+\tunsigned virtual_id;\n };\n \n /* merge_trees() but with recursive ancestor consolidation */\n-- \n1.6.0.1\n"},{"id":"89779","messageId":"7vy7273f9v.fsf@gitster.siamese.dyndns.org","threadId":"15340","inReplyTo":"f2a1ff8d2fe354265a80534cd7beaaa95c2ffc54.1220463034.git.vmiklos@frugalware.org","subject":"Re: [PATCH 2/2] merge-recursive: move make_virtual_commit()'s virtual_id to merge_options","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-09-04T19:03:08Z","receivedAt":"2008-09-04T19:03:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"I do not think this one is a good idea.\n\nWhat does it mean for a two \"virtual commits\" that are returned from\nseparate calls to make_virtual_commit() to have the same virtual_id?\n\nI do not know offhand if the existing code does something like:\n\n\tcommit = lookup_commit(commit->object.sha1)\n\nor\n\n\tif (hashcmp(commit1->object.sha1, commit2->object.sha1))\n        \t...\n\nbut if there is such a code, I think this change makes the problem\n\"virtual id\" has even worse.  With the current single function local\nstatic \"virtual_id\", at least during a program's lifetime it is guaranteed\nthat there won't be any two instances of virtual commits created for\ndifferent purposes that share the same (fake) sha1 value.  If you call\nmerge_recursive more than once in your process, using a fresh \"struct\nmerge_options\" each time, that guarantee is lost with your change.\n\nThe only purpose of a \"virtual commit\", as I understand it, is to allow\nyou to pass a tree resulting from an internal merge to a function that\nexpects you to call with three commit objects to come up with a new tree\nthat is the result of the merge.  The code stores a \"virtual_id\" as a\nphoney sha1 value in the object, but I do not think the actual value is\nused for anything but debugging purposes (Alex, Dscho, please correct me\nas necessary).\n\nDoes it hurt if we get rid of virtual_id and always leave the\nobject->sha1 field of virtual commits 0{40} as it is initialized?\n\nI further suspect we _could_ fix the API that requires you to pass three\ncommits to accept three trees instead and get rid of virtual commits\naltogether, but then we would lose an easy access to the message of\ncommits that are being merged, and we would need to pass these strings as\nseparate parameters (or part of merge_options) --- which might be a good\nclean-up in a longer run, but I do not think it is absolutely necessary\nduring this round.\n"},{"id":"89780","messageId":"7vr67z3f5d.fsf@gitster.siamese.dyndns.org","threadId":"15340","inReplyTo":"cover.1220463034.git.vmiklos@frugalware.org","subject":"Re: [PATCH] merge-recursive: move the global obuf to struct merge_options","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-09-04T19:05:50Z","receivedAt":"2008-09-04T19:05:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Miklos Vajna <vmiklos@frugalware.org> writes:\n\n> These, and the 4 other related patches which are not yet in git.git at\n> the moment are also available in the 'merge-recursive' branch of\n> git://repo.or.cz/git/vmiklos.git.\n\nThanks.\n\nI already expressed my doubts about \"move make_virtual_commit()\".\n\n\"add merge-recursive to LIB_H\" should go to 'maint' as a build-fix, so it\ndoes not have to be on this topic.  If this is meant to be a pullable\ntopic branch, I'd prefer if you didn't have that commit.\n\nI cherry picked call-depth, index-only removal, obuf and current_{f/d}\nbut haven't pushed the results out.\n"},{"id":"89857","messageId":"1220635602-13796-1-git-send-email-vmiklos@frugalware.org","threadId":"15340","inReplyTo":"7vy7273f9v.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] merge-recursive: get rid of virtual_id","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-09-05T17:26:42Z","receivedAt":"2008-09-05T17:26:42Z","isPatch":true,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"We now just leave the object->sha1 field of virtual commits 0{40} as it\nis initialized, as a unique hash is not necessary in case of virtual\ncommits.\n\nSigned-off-by: Miklos Vajna <vmiklos@frugalware.org>\n---\n\nOn Thu, Sep 04, 2008 at 12:03:08PM -0700, Junio C Hamano <gitster@pobox.com> wrote:\n> Does it hurt if we get rid of virtual_id and always leave the\n> object->sha1 field of virtual commits 0{40} as it is initialized?\n\nI don't think so. Here is a patch that does it.\n\n merge-recursive.c |    6 +-----\n 1 files changed, 1 insertions(+), 5 deletions(-)\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 1c24c31..dbdb9ac 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -35,18 +35,14 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two)\n }\n \n /*\n- * A virtual commit has\n- * - (const char *)commit->util set to the name, and\n- * - *(int *)commit->object.sha1 set to the virtual id.\n+ * A virtual commit has (const char *)commit->util set to the name.\n  */\n \n struct commit *make_virtual_commit(struct tree *tree, const char *comment)\n {\n \tstruct commit *commit = xcalloc(1, sizeof(struct commit));\n-\tstatic unsigned virtual_id = 1;\n \tcommit->tree = tree;\n \tcommit->util = (void*)comment;\n-\t*(int*)commit->object.sha1 = virtual_id++;\n \t/* avoid warnings */\n \tcommit->object.parsed = 1;\n \treturn commit;\n-- \n1.6.0.1\n"}]}