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>

Michael Haggerty committed Jun 23, 2017 at 09:01 UTC e0d483970b0d666be7bbb74ee0bbf6d8baf7a0ea
1 file changed +12 -13
refs/files-backend.c
+12 -13
@@ -54,6 +54,9 @@ struct packed_ref_cache {
54 struct packed_ref_store {
55 unsigned int store_flags;
56
57 + /* The path of the "packed-refs" file: */
58 + char *path;
59 +
60 /*
61 * A cache of the values read from the `packed-refs` file, if
62 * it might still be current; otherwise, NULL.
@@ -61,11 +64,13 @@ struct packed_ref_store {
64 struct packed_ref_cache *cache;
65 };
66
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)
69 {
70 struct packed_ref_store *refs = xcalloc(1, sizeof(*refs));
71
72 refs->store_flags = store_flags;
73 + refs->path = xstrdup(path);
74 return refs;
75 }
76
@@ -79,7 +84,6 @@ struct files_ref_store {
84
85 char *gitdir;
86 char *gitcommondir;
82 - char *packed_refs_path;
87
88 struct ref_cache *loose;
89
@@ -154,8 +158,8 @@ static struct ref_store *files_ref_store_create(const char *gitdir,
158 get_common_dir_noenv(&sb, gitdir);
159 refs->gitcommondir = strbuf_detach(&sb, NULL);
160 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);
163
164 return ref_store;
165 }
@@ -343,11 +347,6 @@ static struct packed_ref_cache *read_packed_refs(const char *packed_refs_file)
347 return packed_refs;
348 }
349
346 -static const char *files_packed_refs_path(struct files_ref_store *refs)
347 -{
348 - return refs->packed_refs_path;
349 -}
350 -
350 static void files_reflog_path(struct files_ref_store *refs,
351 struct strbuf *sb,
352 const char *refname)
@@ -401,7 +400,7 @@ static void validate_packed_ref_cache(struct files_ref_store *refs)
400 {
401 if (refs->packed_ref_store->cache &&
402 !stat_validity_check(&refs->packed_ref_store->cache->validity,
404 - files_packed_refs_path(refs)))
403 + refs->packed_ref_store->path))
404 clear_packed_ref_cache(refs);
405 }
406
@@ -415,7 +414,7 @@ static void validate_packed_ref_cache(struct files_ref_store *refs)
414 */
415 static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *refs)
416 {
418 - const char *packed_refs_file = files_packed_refs_path(refs);
417 + const char *packed_refs_file = refs->packed_ref_store->path;
418
419 if (!is_lock_file_locked(&refs->packed_refs_lock))
420 validate_packed_ref_cache(refs);
@@ -1352,7 +1351,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
1351 }
1352
1353 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,
1355 flags, timeout_value) < 0)
1356 return -1;
1357
@@ -1633,7 +1632,7 @@ static int repack_without_refs(struct files_ref_store *refs,
1632 return 0; /* no refname exists in packed refs */
1633
1634 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);
1636 return -1;
1637 }
1638 packed = get_packed_refs(refs);