Skip to content

Commit b531394

Browse files
drafnelgitster
authored andcommitted
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>
1 parent 4ed7cd3 commit b531394

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

refs.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,22 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
10181018
return 1;
10191019
}
10201020

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+
10211037
void unlock_ref(struct ref_lock *lock)
10221038
{
10231039
/* Do not free lock->lk -- atexit() still looks at them */
@@ -1147,7 +1163,7 @@ int write_ref_sha1(struct ref_lock *lock,
11471163
}
11481164
if (write_in_full(lock->lock_fd, sha1_to_hex(sha1), 40) != 40 ||
11491165
write_in_full(lock->lock_fd, &term, 1) != 1
1150-
|| close_lock_file(lock->lk) < 0) {
1166+
|| close_ref(lock) < 0) {
11511167
error("Couldn't write %s", lock->lk->filename);
11521168
unlock_ref(lock);
11531169
return -1;
@@ -1180,12 +1196,11 @@ int write_ref_sha1(struct ref_lock *lock,
11801196
!strcmp(head_ref, lock->ref_name))
11811197
log_ref_write("HEAD", lock->old_sha1, sha1, logmsg);
11821198
}
1183-
if (commit_lock_file(lock->lk)) {
1199+
if (commit_ref(lock)) {
11841200
error("Couldn't set %s", lock->ref_name);
11851201
unlock_ref(lock);
11861202
return -1;
11871203
}
1188-
lock->lock_fd = -1;
11891204
unlock_ref(lock);
11901205
return 0;
11911206
}

0 commit comments

Comments
 (0)