X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=refs.c;h=67d2a502afb60050f0ce750c21ae1a42fa5cb803;hb=55029ae4dac07942437c0c715ea7c8ac60dd3576;hp=c3ffe0393b3c5b884422d3f9389b6c89ab6fd0df;hpb=c3b0dec509fe136c5417422f31898b5a4e2d5e02;p=git.git diff --git a/refs.c b/refs.c index c3ffe0393..67d2a502a 100644 --- a/refs.c +++ b/refs.c @@ -864,7 +864,6 @@ static int repack_without_ref(const char *refname) die("too long a refname '%s'", list->name); write_or_die(fd, line, len); } - close(fd); return commit_lock_file(&packlock); } @@ -1019,14 +1018,27 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg) return 1; } +static int close_ref(struct ref_lock *lock) +{ + if (close_lock_file(lock->lk)) + return -1; + lock->lock_fd = -1; + return 0; +} + +static int commit_ref(struct ref_lock *lock) +{ + if (commit_lock_file(lock->lk)) + return -1; + lock->lock_fd = -1; + return 0; +} + void unlock_ref(struct ref_lock *lock) { - if (lock->lock_fd >= 0) { - close(lock->lock_fd); - /* Do not free lock->lk -- atexit() still looks at them */ - if (lock->lk) - rollback_lock_file(lock->lk); - } + /* Do not free lock->lk -- atexit() still looks at them */ + if (lock->lk) + rollback_lock_file(lock->lk); free(lock->ref_name); free(lock->orig_ref_name); free(lock); @@ -1151,7 +1163,7 @@ int write_ref_sha1(struct ref_lock *lock, } if (write_in_full(lock->lock_fd, sha1_to_hex(sha1), 40) != 40 || write_in_full(lock->lock_fd, &term, 1) != 1 - || close(lock->lock_fd) < 0) { + || close_ref(lock) < 0) { error("Couldn't write %s", lock->lk->filename); unlock_ref(lock); return -1; @@ -1184,12 +1196,11 @@ int write_ref_sha1(struct ref_lock *lock, !strcmp(head_ref, lock->ref_name)) log_ref_write("HEAD", lock->old_sha1, sha1, logmsg); } - if (commit_lock_file(lock->lk)) { + if (commit_ref(lock)) { error("Couldn't set %s", lock->ref_name); unlock_ref(lock); return -1; } - lock->lock_fd = -1; unlock_ref(lock); return 0; }