{"thread":{"id":"5181","subject":"[PATCH 1/2] merge-recur: do not call git-write-tree","startedAt":"2006-08-09T13:04:16Z","lastAt":"2006-08-09T13:04:16Z","messageCount":1,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"25026","messageId":"Pine.LNX.4.63.0608091503170.1800@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"5181","inReplyTo":null,"subject":"[PATCH 1/2] merge-recur: do not call git-write-tree","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-08-09T13:04:16Z","receivedAt":"2006-08-09T13:04:16Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nSince merge-recur is in C, and uses libgit, it can call the relevant\nfunctions directly, without writing the index file.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n merge-recursive.c |   44 ++++++++++++++++++++------------------------\n 1 files changed, 20 insertions(+), 24 deletions(-)\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex f5c0080..b8b0951 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -248,38 +248,34 @@ static int git_merge_trees(int index_onl\n \treturn rc;\n }\n \n-/*\n- * TODO: this can be streamlined by refactoring builtin-write-tree.c\n- */\n static struct tree *git_write_tree(void)\n {\n-\tFILE *fp;\n-\tint rc;\n-\tchar buf[41];\n-\tunsigned char sha1[20];\n-\tint ch;\n-\tunsigned i = 0;\n+\tstruct tree *result = NULL;\n+\n \tif (cache_dirty) {\n+\t\tunsigned i;\n \t\tfor (i = 0; i < active_nr; i++) {\n \t\t\tstruct cache_entry *ce = active_cache[i];\n \t\t\tif (ce_stage(ce))\n \t\t\t\treturn NULL;\n \t\t}\n-\t\tflush_cache();\n-\t}\n-\tfp = popen(\"git-write-tree 2>/dev/null\", \"r\");\n-\twhile ((ch = fgetc(fp)) != EOF)\n-\t\tif (i < sizeof(buf)-1 && ch >= '0' && ch <= 'f')\n-\t\t\tbuf[i++] = ch;\n-\t\telse\n-\t\t\tbreak;\n-\trc = pclose(fp);\n-\tif (rc == -1 || WEXITSTATUS(rc))\n-\t\treturn NULL;\n-\tbuf[i] = '\\0';\n-\tif (get_sha1(buf, sha1) != 0)\n-\t\treturn NULL;\n-\treturn lookup_tree(sha1);\n+\t} else\n+\t\tread_cache_from(getenv(\"GIT_INDEX_FILE\"));\n+\n+\tif (!active_cache_tree)\n+\t\tactive_cache_tree = cache_tree();\n+\n+\tif (!cache_tree_fully_valid(active_cache_tree) &&\n+\t\t\tcache_tree_update(active_cache_tree,\n+\t\t\t\tactive_cache, active_nr, 0, 0) < 0)\n+\t\tdie(\"error building trees\");\n+\n+\tresult = lookup_tree(active_cache_tree->sha1);\n+\n+\tflush_cache();\n+\tcache_dirty = 0;\n+\n+\treturn result;\n }\n \n static int save_files_dirs(const unsigned char *sha1,\n-- \n1.4.2.rc3.g55597-dirty\n"}]}