Skip to content

Commit

Permalink
commit.c: check for lock error and return early
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ronnie Sahlberg authored and Junio C Hamano committed Apr 17, 2014
1 parent 651ab9f commit 55a5c8d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
? NULL
: current_head->object.sha1,
0, NULL);
if (!ref_lock) {
rollback_index_files();
die(_("cannot lock HEAD ref"));
}

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

if (!ref_lock) {
rollback_index_files();
die(_("cannot lock HEAD ref"));
}
if (write_ref_sha1(ref_lock, sha1, sb.buf) < 0) {
rollback_index_files();
die(_("cannot update HEAD ref"));
Expand Down

0 comments on commit 55a5c8d

Please sign in to comment.