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 <newren@gmail.com> Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
89e653da5b
commit
3f1c1c3600
@ -337,7 +337,7 @@ static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree)
|
|||||||
init_tree_desc(desc, tree->buffer, tree->size);
|
init_tree_desc(desc, tree->buffer, tree->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int git_merge_trees(struct merge_options *o,
|
static int unpack_trees_start(struct merge_options *o,
|
||||||
struct tree *common,
|
struct tree *common,
|
||||||
struct tree *head,
|
struct tree *head,
|
||||||
struct tree *merge)
|
struct tree *merge)
|
||||||
@ -379,6 +379,11 @@ static int git_merge_trees(struct merge_options *o,
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void unpack_trees_finish(struct merge_options *o)
|
||||||
|
{
|
||||||
|
discard_index(&o->orig_index);
|
||||||
|
}
|
||||||
|
|
||||||
struct tree *write_tree_from_memory(struct merge_options *o)
|
struct tree *write_tree_from_memory(struct merge_options *o)
|
||||||
{
|
{
|
||||||
struct tree *result = NULL;
|
struct tree *result = NULL;
|
||||||
@ -3088,13 +3093,14 @@ int merge_trees(struct merge_options *o,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = git_merge_trees(o, common, head, merge);
|
code = unpack_trees_start(o, common, head, merge);
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
if (show(o, 4) || o->call_depth)
|
if (show(o, 4) || o->call_depth)
|
||||||
err(o, _("merging of trees %s and %s failed"),
|
err(o, _("merging of trees %s and %s failed"),
|
||||||
oid_to_hex(&head->object.oid),
|
oid_to_hex(&head->object.oid),
|
||||||
oid_to_hex(&merge->object.oid));
|
oid_to_hex(&merge->object.oid));
|
||||||
|
unpack_trees_finish(o);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3147,20 +3153,15 @@ cleanup:
|
|||||||
|
|
||||||
hashmap_free(&o->current_file_dir_set, 1);
|
hashmap_free(&o->current_file_dir_set, 1);
|
||||||
|
|
||||||
if (clean < 0)
|
if (clean < 0) {
|
||||||
|
unpack_trees_finish(o);
|
||||||
return clean;
|
return clean;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
clean = 1;
|
clean = 1;
|
||||||
|
|
||||||
/* Free the extra index left from git_merge_trees() */
|
unpack_trees_finish(o);
|
||||||
/*
|
|
||||||
* FIXME: Need to also free data allocated by
|
|
||||||
* setup_unpack_trees_porcelain() tucked away in o->unpack_opts.msgs,
|
|
||||||
* but the problem is that only half of it refers to dynamically
|
|
||||||
* allocated data, while the other half points at static strings.
|
|
||||||
*/
|
|
||||||
discard_index(&o->orig_index);
|
|
||||||
|
|
||||||
if (o->call_depth && !(*result = write_tree_from_memory(o)))
|
if (o->call_depth && !(*result = write_tree_from_memory(o)))
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user