Skip to content

Commit c99a4c2

Browse files
mhaggergitster
authored andcommitted
lockfile: add accessors get_lock_file_fd() and get_lock_file_fp()
We are about to move those members, so change client code to read them through accessor functions. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e54c347 commit c99a4c2

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

credential-store.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void print_entry(struct credential *c)
5252
static void print_line(struct strbuf *buf)
5353
{
5454
strbuf_addch(buf, '\n');
55-
write_or_die(credential_lock.fd, buf->buf, buf->len);
55+
write_or_die(get_lock_file_fd(&credential_lock), buf->buf, buf->len);
5656
}
5757

5858
static void rewrite_credential_file(const char *fn, struct credential *c,

lockfile.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,20 @@ FILE *fdopen_lock_file(struct lock_file *lk, const char *mode)
364364
return lk->fp;
365365
}
366366

367+
int get_lock_file_fd(struct lock_file *lk)
368+
{
369+
if (!lk->active)
370+
die("BUG: get_lock_file_fd() called for unlocked object");
371+
return lk->fd;
372+
}
373+
374+
FILE *get_lock_file_fp(struct lock_file *lk)
375+
{
376+
if (!lk->active)
377+
die("BUG: get_lock_file_fp() called for unlocked object");
378+
return lk->fp;
379+
}
380+
367381
char *get_locked_file_path(struct lock_file *lk)
368382
{
369383
if (!lk->active)

lockfile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ extern NORETURN void unable_to_lock_die(const char *path, int err);
203203
*/
204204
extern FILE *fdopen_lock_file(struct lock_file *lk, const char *mode);
205205

206+
extern int get_lock_file_fd(struct lock_file *lk);
207+
extern FILE *get_lock_file_fp(struct lock_file *lk);
208+
206209
/*
207210
* Return the path of the file that is locked by the specified
208211
* lock_file object. The caller must free the memory.

read-cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,7 @@ static int commit_locked_index(struct lock_file *lk)
21122112
static int do_write_locked_index(struct index_state *istate, struct lock_file *lock,
21132113
unsigned flags)
21142114
{
2115-
int ret = do_write_index(istate, lock->fd, 0);
2115+
int ret = do_write_index(istate, get_lock_file_fd(lock), 0);
21162116
if (ret)
21172117
return ret;
21182118
assert((flags & (COMMIT_LOCK | CLOSE_LOCK)) !=

refs.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3162,6 +3162,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
31623162
{
31633163
static char term = '\n';
31643164
struct object *o;
3165+
int fd;
31653166

31663167
o = parse_object(sha1);
31673168
if (!o) {
@@ -3178,8 +3179,9 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
31783179
errno = EINVAL;
31793180
return -1;
31803181
}
3181-
if (write_in_full(lock->lk->fd, sha1_to_hex(sha1), 40) != 40 ||
3182-
write_in_full(lock->lk->fd, &term, 1) != 1 ||
3182+
fd = get_lock_file_fd(lock->lk);
3183+
if (write_in_full(fd, sha1_to_hex(sha1), 40) != 40 ||
3184+
write_in_full(fd, &term, 1) != 1 ||
31833185
close_ref(lock) < 0) {
31843186
int save_errno = errno;
31853187
error("Couldn't write %s", lock->lk->filename.buf);
@@ -4264,10 +4266,10 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
42644266
status |= error("couldn't write %s: %s", log_file,
42654267
strerror(errno));
42664268
} else if (update &&
4267-
(write_in_full(lock->lk->fd,
4269+
(write_in_full(get_lock_file_fd(lock->lk),
42684270
sha1_to_hex(cb.last_kept_sha1), 40) != 40 ||
4269-
write_str_in_full(lock->lk->fd, "\n") != 1 ||
4270-
close_ref(lock) < 0)) {
4271+
write_str_in_full(get_lock_file_fd(lock->lk), "\n") != 1 ||
4272+
close_ref(lock) < 0)) {
42714273
status |= error("couldn't write %s",
42724274
lock->lk->filename.buf);
42734275
rollback_lock_file(&reflog_lock);

0 commit comments

Comments
 (0)