merge-recur: do not call git-write-tree
Since merge-recur is in C, and uses libgit, it can call the relevant functions directly, without writing the index file. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Aug 9, 2006 at 15:04 UTC
5b982f84ee6eb3027e5bdf2e917a0efa48aded6a
1 file changed
+20
-24
merge-recursive.c
+20
-24
@@ -248,38 +248,34 @@ static int git_merge_trees(int index_only,
248
return rc;
249
}
250
251
-/*
252
- * TODO: this can be streamlined by refactoring builtin-write-tree.c
253
- */
251
static struct tree *git_write_tree(void)
252
{
256
- FILE *fp;
257
- int rc;
258
- char buf[41];
259
- unsigned char sha1[20];
260
- int ch;
261
- unsigned i = 0;
253
+ struct tree *result = NULL;
254
+
255
if (cache_dirty) {
256
+ unsigned i;
257
for (i = 0; i < active_nr; i++) {
258
struct cache_entry *ce = active_cache[i];
259
if (ce_stage(ce))
260
return NULL;
261
}
268
- flush_cache();
269
- }
270
- fp = popen("git-write-tree 2>/dev/null", "r");
271
- while ((ch = fgetc(fp)) != EOF)
272
- if (i < sizeof(buf)-1 && ch >= '0' && ch <= 'f')
273
- buf[i++] = ch;
274
- else
275
- break;
276
- rc = pclose(fp);
277
- if (rc == -1 || WEXITSTATUS(rc))
278
- return NULL;
279
- buf[i] = '\0';
280
- if (get_sha1(buf, sha1) != 0)
281
- return NULL;
282
- return lookup_tree(sha1);
262
+ } else
263
+ read_cache_from(getenv("GIT_INDEX_FILE"));
264
+
265
+ if (!active_cache_tree)
266
+ active_cache_tree = cache_tree();
267
+
268
+ if (!cache_tree_fully_valid(active_cache_tree) &&
269
+ cache_tree_update(active_cache_tree,
270
+ active_cache, active_nr, 0, 0) < 0)
271
+ die("error building trees");
272
+
273
+ result = lookup_tree(active_cache_tree->sha1);
274
+
275
+ flush_cache();
276
+ cache_dirty = 0;
277
+
278
+ return result;
279
}
280
281
static int save_files_dirs(const unsigned char *sha1,