Skip to content

Commit 58e2ce9

Browse files
committed
Merge branch 'ma/more-opaque-lock-file'
Code clean-up. * ma/more-opaque-lock-file: read-cache: try not to peek into `struct {lock_,temp}file` refs/files-backend: don't peek into `struct lock_file` midx: don't peek into `struct lock_file` commit-graph: don't peek into `struct lock_file` builtin/gc: don't peek into `struct lock_file`
2 parents 2856089 + 6a8c89d commit 58e2ce9

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

builtin/gc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static void process_log_file(void)
9292
*/
9393
int saved_errno = errno;
9494
fprintf(stderr, _("Failed to fstat %s: %s"),
95-
get_tempfile_path(log_lock.tempfile),
95+
get_lock_file_path(&log_lock),
9696
strerror(saved_errno));
9797
fflush(stderr);
9898
commit_lock_file(&log_lock);
@@ -1953,11 +1953,11 @@ static int update_background_schedule(int enable)
19531953
return error(_("another process is scheduling background maintenance"));
19541954

19551955
if (!strcmp(scheduler, "launchctl"))
1956-
result = launchctl_update_schedule(enable, lk.tempfile->fd, cmd);
1956+
result = launchctl_update_schedule(enable, get_lock_file_fd(&lk), cmd);
19571957
else if (!strcmp(scheduler, "schtasks"))
1958-
result = schtasks_update_schedule(enable, lk.tempfile->fd, cmd);
1958+
result = schtasks_update_schedule(enable, get_lock_file_fd(&lk), cmd);
19591959
else if (!strcmp(scheduler, "crontab"))
1960-
result = crontab_update_schedule(enable, lk.tempfile->fd, cmd);
1960+
result = crontab_update_schedule(enable, get_lock_file_fd(&lk), cmd);
19611961
else
19621962
die("unknown background scheduler: %s", scheduler);
19631963

commit-graph.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,8 +1694,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
16941694
} else {
16951695
hold_lock_file_for_update_mode(&lk, ctx->graph_name,
16961696
LOCK_DIE_ON_ERROR, 0444);
1697-
fd = lk.tempfile->fd;
1698-
f = hashfd(lk.tempfile->fd, lk.tempfile->filename.buf);
1697+
fd = get_lock_file_fd(&lk);
1698+
f = hashfd(fd, get_lock_file_path(&lk));
16991699
}
17001700

17011701
chunks[0].id = GRAPH_CHUNKID_OIDFANOUT;
@@ -1833,7 +1833,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
18331833
result = rename(ctx->graph_name, final_graph_name);
18341834

18351835
for (i = 0; i < ctx->num_commit_graphs_after; i++)
1836-
fprintf(lk.tempfile->fp, "%s\n", ctx->commit_graph_hash_after[i]);
1836+
fprintf(get_lock_file_fp(&lk), "%s\n", ctx->commit_graph_hash_after[i]);
18371837

18381838
if (result) {
18391839
error(_("failed to rename temporary commit-graph file"));

midx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
918918
(pack_name_concat_len % MIDX_CHUNK_ALIGNMENT);
919919

920920
hold_lock_file_for_update(&lk, midx_name, LOCK_DIE_ON_ERROR);
921-
f = hashfd(lk.tempfile->fd, lk.tempfile->filename.buf);
921+
f = hashfd(get_lock_file_fd(&lk), get_lock_file_path(&lk));
922922
FREE_AND_NULL(midx_name);
923923

924924
if (packs.m)

read-cache.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3014,10 +3014,10 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
30143014
if (ce_flush(&c, newfd, istate->oid.hash))
30153015
return -1;
30163016
if (close_tempfile_gently(tempfile)) {
3017-
error(_("could not close '%s'"), tempfile->filename.buf);
3017+
error(_("could not close '%s'"), get_tempfile_path(tempfile));
30183018
return -1;
30193019
}
3020-
if (stat(tempfile->filename.buf, &st))
3020+
if (stat(get_tempfile_path(tempfile), &st))
30213021
return -1;
30223022
istate->timestamp.sec = (unsigned int)st.st_mtime;
30233023
istate->timestamp.nsec = ST_MTIME_NSEC(st);
@@ -3058,10 +3058,10 @@ static int do_write_locked_index(struct index_state *istate, struct lock_file *l
30583058
* that is associated with the given "istate".
30593059
*/
30603060
trace2_region_enter_printf("index", "do_write_index", the_repository,
3061-
"%s", lock->tempfile->filename.buf);
3061+
"%s", get_lock_file_path(lock));
30623062
ret = do_write_index(istate, lock->tempfile, 0);
30633063
trace2_region_leave_printf("index", "do_write_index", the_repository,
3064-
"%s", lock->tempfile->filename.buf);
3064+
"%s", get_lock_file_path(lock));
30653065

30663066
if (ret)
30673067
return ret;
@@ -3158,10 +3158,10 @@ static int write_shared_index(struct index_state *istate,
31583158
move_cache_to_base_index(istate);
31593159

31603160
trace2_region_enter_printf("index", "shared/do_write_index",
3161-
the_repository, "%s", (*temp)->filename.buf);
3161+
the_repository, "%s", get_tempfile_path(*temp));
31623162
ret = do_write_index(si->base, *temp, 1);
31633163
trace2_region_leave_printf("index", "shared/do_write_index",
3164-
the_repository, "%s", (*temp)->filename.buf);
3164+
the_repository, "%s", get_tempfile_path(*temp));
31653165

31663166
if (ret)
31673167
return ret;

refs/files-backend.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,12 +1824,12 @@ static int create_symref_locked(struct files_ref_store *refs,
18241824

18251825
if (!fdopen_lock_file(&lock->lk, "w"))
18261826
return error("unable to fdopen %s: %s",
1827-
lock->lk.tempfile->filename.buf, strerror(errno));
1827+
get_lock_file_path(&lock->lk), strerror(errno));
18281828

18291829
update_symref_reflog(refs, lock, refname, target, logmsg);
18301830

18311831
/* no error check; commit_ref will check ferror */
1832-
fprintf(lock->lk.tempfile->fp, "ref: %s\n", target);
1832+
fprintf(get_lock_file_fp(&lock->lk), "ref: %s\n", target);
18331833
if (commit_ref(lock) < 0)
18341834
return error("unable to write symref for %s: %s", refname,
18351835
strerror(errno));

0 commit comments

Comments
 (0)