Skip to content

Commit e0d4839

Browse files
mhaggergitster
authored andcommitted
packed_ref_store: move packed_refs_path here
Move `packed_refs_path` from `files_ref_store` to `packed_ref_store`, and rename it to `path` since its meaning is clear from its new context. Inline `files_packed_refs_path()`. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent bdf55fa commit e0d4839

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

refs/files-backend.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,23 @@ struct packed_ref_cache {
5454
struct packed_ref_store {
5555
unsigned int store_flags;
5656

57+
/* The path of the "packed-refs" file: */
58+
char *path;
59+
5760
/*
5861
* A cache of the values read from the `packed-refs` file, if
5962
* it might still be current; otherwise, NULL.
6063
*/
6164
struct packed_ref_cache *cache;
6265
};
6366

64-
static struct packed_ref_store *packed_ref_store_create(unsigned int store_flags)
67+
static struct packed_ref_store *packed_ref_store_create(
68+
const char *path, unsigned int store_flags)
6569
{
6670
struct packed_ref_store *refs = xcalloc(1, sizeof(*refs));
6771

6872
refs->store_flags = store_flags;
73+
refs->path = xstrdup(path);
6974
return refs;
7075
}
7176

@@ -79,7 +84,6 @@ struct files_ref_store {
7984

8085
char *gitdir;
8186
char *gitcommondir;
82-
char *packed_refs_path;
8387

8488
struct ref_cache *loose;
8589

@@ -154,8 +158,8 @@ static struct ref_store *files_ref_store_create(const char *gitdir,
154158
get_common_dir_noenv(&sb, gitdir);
155159
refs->gitcommondir = strbuf_detach(&sb, NULL);
156160
strbuf_addf(&sb, "%s/packed-refs", refs->gitcommondir);
157-
refs->packed_refs_path = strbuf_detach(&sb, NULL);
158-
refs->packed_ref_store = packed_ref_store_create(flags);
161+
refs->packed_ref_store = packed_ref_store_create(sb.buf, flags);
162+
strbuf_release(&sb);
159163

160164
return ref_store;
161165
}
@@ -343,11 +347,6 @@ static struct packed_ref_cache *read_packed_refs(const char *packed_refs_file)
343347
return packed_refs;
344348
}
345349

346-
static const char *files_packed_refs_path(struct files_ref_store *refs)
347-
{
348-
return refs->packed_refs_path;
349-
}
350-
351350
static void files_reflog_path(struct files_ref_store *refs,
352351
struct strbuf *sb,
353352
const char *refname)
@@ -401,7 +400,7 @@ static void validate_packed_ref_cache(struct files_ref_store *refs)
401400
{
402401
if (refs->packed_ref_store->cache &&
403402
!stat_validity_check(&refs->packed_ref_store->cache->validity,
404-
files_packed_refs_path(refs)))
403+
refs->packed_ref_store->path))
405404
clear_packed_ref_cache(refs);
406405
}
407406

@@ -415,7 +414,7 @@ static void validate_packed_ref_cache(struct files_ref_store *refs)
415414
*/
416415
static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *refs)
417416
{
418-
const char *packed_refs_file = files_packed_refs_path(refs);
417+
const char *packed_refs_file = refs->packed_ref_store->path;
419418

420419
if (!is_lock_file_locked(&refs->packed_refs_lock))
421420
validate_packed_ref_cache(refs);
@@ -1352,7 +1351,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
13521351
}
13531352

13541353
if (hold_lock_file_for_update_timeout(
1355-
&refs->packed_refs_lock, files_packed_refs_path(refs),
1354+
&refs->packed_refs_lock, refs->packed_ref_store->path,
13561355
flags, timeout_value) < 0)
13571356
return -1;
13581357

@@ -1633,7 +1632,7 @@ static int repack_without_refs(struct files_ref_store *refs,
16331632
return 0; /* no refname exists in packed refs */
16341633

16351634
if (lock_packed_refs(refs, 0)) {
1636-
unable_to_lock_message(files_packed_refs_path(refs), errno, err);
1635+
unable_to_lock_message(refs->packed_ref_store->path, errno, err);
16371636
return -1;
16381637
}
16391638
packed = get_packed_refs(refs);

0 commit comments

Comments
 (0)