Skip to content

Commit 3f1c1c3

Browse files
newrengitster
authored andcommitted
merge-recursive: provide pair of unpack_trees_{start,finish}()
Rename `git_merge_trees()` to `unpack_trees_start()` and extract the call to `discard_index()` into a new function `unpack_trees_finish()`. As a result, these are called early resp. late in `merge_trees()`, making the resource handling clearer. A later commit will expand on that, teaching `..._finish()` to free more memory. (So rather than moving the FIXME-comment, just drop it, since it will be addressed soon enough.) Also call `..._finish()` when `merge_trees()` returns early. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Martin Ågren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 89e653d commit 3f1c1c3

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

merge-recursive.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,10 @@ static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree)
337337
init_tree_desc(desc, tree->buffer, tree->size);
338338
}
339339

340-
static int git_merge_trees(struct merge_options *o,
341-
struct tree *common,
342-
struct tree *head,
343-
struct tree *merge)
340+
static int unpack_trees_start(struct merge_options *o,
341+
struct tree *common,
342+
struct tree *head,
343+
struct tree *merge)
344344
{
345345
int rc;
346346
struct tree_desc t[3];
@@ -379,6 +379,11 @@ static int git_merge_trees(struct merge_options *o,
379379
return rc;
380380
}
381381

382+
static void unpack_trees_finish(struct merge_options *o)
383+
{
384+
discard_index(&o->orig_index);
385+
}
386+
382387
struct tree *write_tree_from_memory(struct merge_options *o)
383388
{
384389
struct tree *result = NULL;
@@ -3088,13 +3093,14 @@ int merge_trees(struct merge_options *o,
30883093
return 1;
30893094
}
30903095

3091-
code = git_merge_trees(o, common, head, merge);
3096+
code = unpack_trees_start(o, common, head, merge);
30923097

30933098
if (code != 0) {
30943099
if (show(o, 4) || o->call_depth)
30953100
err(o, _("merging of trees %s and %s failed"),
30963101
oid_to_hex(&head->object.oid),
30973102
oid_to_hex(&merge->object.oid));
3103+
unpack_trees_finish(o);
30983104
return -1;
30993105
}
31003106

@@ -3147,20 +3153,15 @@ int merge_trees(struct merge_options *o,
31473153

31483154
hashmap_free(&o->current_file_dir_set, 1);
31493155

3150-
if (clean < 0)
3156+
if (clean < 0) {
3157+
unpack_trees_finish(o);
31513158
return clean;
3159+
}
31523160
}
31533161
else
31543162
clean = 1;
31553163

3156-
/* Free the extra index left from git_merge_trees() */
3157-
/*
3158-
* FIXME: Need to also free data allocated by
3159-
* setup_unpack_trees_porcelain() tucked away in o->unpack_opts.msgs,
3160-
* but the problem is that only half of it refers to dynamically
3161-
* allocated data, while the other half points at static strings.
3162-
*/
3163-
discard_index(&o->orig_index);
3164+
unpack_trees_finish(o);
31643165

31653166
if (o->call_depth && !(*result = write_tree_from_memory(o)))
31663167
return -1;

0 commit comments

Comments
 (0)