Skip to content

Commit daccee3

Browse files
mhaggergitster
authored andcommitted
try_merge_strategy(): use a statically-allocated lock_file object
Even the one lockfile object needn't be allocated each time the function is called. Instead, define one statically-allocated lock_file object and reuse it for every call. Suggested-by: Jeff King <[email protected]> Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1fef4b5 commit daccee3

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

builtin/merge.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -656,14 +656,14 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
656656
struct commit_list *remoteheads,
657657
struct commit *head, const char *head_arg)
658658
{
659-
struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
659+
static struct lock_file lock;
660660

661-
hold_locked_index(lock, 1);
661+
hold_locked_index(&lock, 1);
662662
refresh_cache(REFRESH_QUIET);
663663
if (active_cache_changed &&
664-
write_locked_index(&the_index, lock, COMMIT_LOCK))
664+
write_locked_index(&the_index, &lock, COMMIT_LOCK))
665665
return error(_("Unable to write index."));
666-
rollback_lock_file(lock);
666+
rollback_lock_file(&lock);
667667

668668
if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree")) {
669669
int clean, x;
@@ -695,13 +695,13 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
695695
for (j = common; j; j = j->next)
696696
commit_list_insert(j->item, &reversed);
697697

698-
hold_locked_index(lock, 1);
698+
hold_locked_index(&lock, 1);
699699
clean = merge_recursive(&o, head,
700700
remoteheads->item, reversed, &result);
701701
if (active_cache_changed &&
702-
write_locked_index(&the_index, lock, COMMIT_LOCK))
702+
write_locked_index(&the_index, &lock, COMMIT_LOCK))
703703
die (_("unable to write %s"), get_index_file());
704-
rollback_lock_file(lock);
704+
rollback_lock_file(&lock);
705705
return clean ? 0 : 1;
706706
} else {
707707
return try_merge_command(strategy, xopts_nr, xopts,

0 commit comments

Comments
 (0)