@matheusbsbs / matheus-bagliano / commits / b531394d58
Fork 0

refs.c: rework ref_locks by abstracting from underlying struct lock_file

Instead of calling close_lock_file() and commit_lock_file() directly, which take a struct lock_file argument, add two new functions: close_ref() and commit_ref(), which handle calling the previous lock_file functions and modifying the ref_lock structure. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Casey committed Jan 16, 2008 at 13:14 UTC b531394d5829b22fd40e38e1d3aa6e97cb5b84ef
1 file changed +18 -3
refs.c
+18 -3
@@ -1018,6 +1018,22 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
1018 return 1;
1019 }
1020
1021 +static int close_ref(struct ref_lock *lock)
1022 +{
1023 + if (close_lock_file(lock->lk))
1024 + return -1;
1025 + lock->lock_fd = -1;
1026 + return 0;
1027 +}
1028 +
1029 +static int commit_ref(struct ref_lock *lock)
1030 +{
1031 + if (commit_lock_file(lock->lk))
1032 + return -1;
1033 + lock->lock_fd = -1;
1034 + return 0;
1035 +}
1036 +
1037 void unlock_ref(struct ref_lock *lock)
1038 {
1039 /* Do not free lock->lk -- atexit() still looks at them */
@@ -1147,7 +1163,7 @@ int write_ref_sha1(struct ref_lock *lock,
1163 }
1164 if (write_in_full(lock->lock_fd, sha1_to_hex(sha1), 40) != 40 ||
1165 write_in_full(lock->lock_fd, &term, 1) != 1
1150 - || close_lock_file(lock->lk) < 0) {
1166 + || close_ref(lock) < 0) {
1167 error("Couldn't write %s", lock->lk->filename);
1168 unlock_ref(lock);
1169 return -1;
@@ -1180,12 +1196,11 @@ int write_ref_sha1(struct ref_lock *lock,
1196 !strcmp(head_ref, lock->ref_name))
1197 log_ref_write("HEAD", lock->old_sha1, sha1, logmsg);
1198 }
1183 - if (commit_lock_file(lock->lk)) {
1199 + if (commit_ref(lock)) {
1200 error("Couldn't set %s", lock->ref_name);
1201 unlock_ref(lock);
1202 return -1;
1203 }
1188 - lock->lock_fd = -1;
1204 unlock_ref(lock);
1205 return 0;
1206 }