Skip to content

Commit 55a5c8d

Browse files
rsahlberggitster
authored andcommitted
commit.c: check for lock error and return early
Move the check for the lock failure to happen immediately after lock_any_ref_for_update(). Previously the lock and the check-if-lock-failed was separated by a handful of string manipulation statements. Moving the check to occur immediately after the failed lock makes the code slightly easier to read and makes it follow the pattern of try-to-take-a-lock(); if (check-if-lock-failed) { error(); } Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 651ab9f commit 55a5c8d

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

builtin/commit.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16721672
? NULL
16731673
: current_head->object.sha1,
16741674
0, NULL);
1675+
if (!ref_lock) {
1676+
rollback_index_files();
1677+
die(_("cannot lock HEAD ref"));
1678+
}
16751679

16761680
nl = strchr(sb.buf, '\n');
16771681
if (nl)
@@ -1681,10 +1685,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16811685
strbuf_insert(&sb, 0, reflog_msg, strlen(reflog_msg));
16821686
strbuf_insert(&sb, strlen(reflog_msg), ": ", 2);
16831687

1684-
if (!ref_lock) {
1685-
rollback_index_files();
1686-
die(_("cannot lock HEAD ref"));
1687-
}
16881688
if (write_ref_sha1(ref_lock, sha1, sb.buf) < 0) {
16891689
rollback_index_files();
16901690
die(_("cannot update HEAD ref"));

0 commit comments

Comments
 (0)