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 <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Aug 10, 2015 at 11:47 UTC
c99a4c2db3053e4fb6a43870f5c747f858b0f58f
5 files changed
+26
-7
credential-store.c
+1
-1
@@ -52,7 +52,7 @@ static void print_entry(struct credential *c)
52
static void print_line(struct strbuf *buf)
53
{
54
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);
56
}
57
58
static void rewrite_credential_file(const char *fn, struct credential *c,
lockfile.c
+14
@@ -364,6 +364,20 @@ FILE *fdopen_lock_file(struct lock_file *lk, const char *mode)
364
return lk->fp;
365
}
366
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
+
381
char *get_locked_file_path(struct lock_file *lk)
382
{
383
if (!lk->active)
lockfile.h
+3
@@ -203,6 +203,9 @@ extern NORETURN void unable_to_lock_die(const char *path, int err);
203
*/
204
extern FILE *fdopen_lock_file(struct lock_file *lk, const char *mode);
205
206
+extern int get_lock_file_fd(struct lock_file *lk);
207
+extern FILE *get_lock_file_fp(struct lock_file *lk);
208
+
209
/*
210
* Return the path of the file that is locked by the specified
211
* lock_file object. The caller must free the memory.
read-cache.c
+1
-1
@@ -2112,7 +2112,7 @@ static int commit_locked_index(struct lock_file *lk)
2112
static int do_write_locked_index(struct index_state *istate, struct lock_file *lock,
2113
unsigned flags)
2114
{
2115
- int ret = do_write_index(istate, lock->fd, 0);
2115
+ int ret = do_write_index(istate, get_lock_file_fd(lock), 0);
2116
if (ret)
2117
return ret;
2118
assert((flags & (COMMIT_LOCK | CLOSE_LOCK)) !=
refs.c
+7
-5
@@ -3162,6 +3162,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
3162
{
3163
static char term = '\n';
3164
struct object *o;
3165
+ int fd;
3166
3167
o = parse_object(sha1);
3168
if (!o) {
@@ -3178,8 +3179,9 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
3179
errno = EINVAL;
3180
return -1;
3181
}
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 ||
3185
close_ref(lock) < 0) {
3186
int save_errno = errno;
3187
error("Couldn't write %s", lock->lk->filename.buf);
@@ -4264,10 +4266,10 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
4266
status |= error("couldn't write %s: %s", log_file,
4267
strerror(errno));
4268
} else if (update &&
4267
- (write_in_full(lock->lk->fd,
4269
+ (write_in_full(get_lock_file_fd(lock->lk),
4270
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)) {
4273
status |= error("couldn't write %s",
4274
lock->lk->filename.buf);
4275
rollback_lock_file(&reflog_lock);