Skip to content

Commit 55f5704

Browse files
dschogitster
authored andcommitted
sequencer: lib'ify checkout_fast_forward()
Instead of dying there, let the caller high up in the callchain notice the error and handle it (by dying, still). The only callers of checkout_fast_forward(), cmd_merge(), pull_into_void(), cmd_pull() and sequencer's fast_forward_to(), already check the return value and handle it appropriately. With this step, we make it notice an error return from this function. So this is a safe conversion to make checkout_fast_forward() callable from new callers that want it not to die, without changing the external behaviour of anything existing. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 0e408fc commit 55f5704

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

merge.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ int checkout_fast_forward(const unsigned char *head,
5757

5858
refresh_cache(REFRESH_QUIET);
5959

60-
hold_locked_index(lock_file, 1);
60+
if (hold_locked_index(lock_file, 0) < 0)
61+
return -1;
6162

6263
memset(&trees, 0, sizeof(trees));
6364
memset(&opts, 0, sizeof(opts));
@@ -90,7 +91,9 @@ int checkout_fast_forward(const unsigned char *head,
9091
}
9192
if (unpack_trees(nr_trees, t, &opts))
9293
return -1;
93-
if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
94-
die(_("unable to write new index file"));
94+
if (write_locked_index(&the_index, lock_file, COMMIT_LOCK)) {
95+
rollback_lock_file(lock_file);
96+
return error(_("unable to write new index file"));
97+
}
9598
return 0;
9699
}

0 commit comments

Comments
 (0)