Skip to content

Commit 33dfb9f

Browse files
pcloudsgitster
authored andcommitted
files-backend: add and use files_packed_refs_path()
Keep repo-related path handling in one place. This will make it easier to add submodule/multiworktree support later. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 1eab194 commit 33dfb9f

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

refs/files-backend.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,8 @@ struct files_ref_store {
923923
*/
924924
const char *submodule;
925925

926+
char *packed_refs_path;
927+
926928
struct ref_entry *loose;
927929
struct packed_ref_cache *packed;
928930
};
@@ -985,7 +987,14 @@ static struct ref_store *files_ref_store_create(const char *submodule)
985987

986988
base_ref_store_init(ref_store, &refs_be_files);
987989

988-
refs->submodule = xstrdup_or_null(submodule);
990+
if (submodule) {
991+
refs->submodule = xstrdup(submodule);
992+
refs->packed_refs_path = git_pathdup_submodule(
993+
refs->submodule, "packed-refs");
994+
return ref_store;
995+
}
996+
997+
refs->packed_refs_path = git_pathdup("packed-refs");
989998

990999
return ref_store;
9911000
}
@@ -1153,19 +1162,18 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
11531162
strbuf_release(&line);
11541163
}
11551164

1165+
static const char *files_packed_refs_path(struct files_ref_store *refs)
1166+
{
1167+
return refs->packed_refs_path;
1168+
}
1169+
11561170
/*
11571171
* Get the packed_ref_cache for the specified files_ref_store,
11581172
* creating it if necessary.
11591173
*/
11601174
static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *refs)
11611175
{
1162-
char *packed_refs_file;
1163-
1164-
if (refs->submodule)
1165-
packed_refs_file = git_pathdup_submodule(refs->submodule,
1166-
"packed-refs");
1167-
else
1168-
packed_refs_file = git_pathdup("packed-refs");
1176+
const char *packed_refs_file = files_packed_refs_path(refs);
11691177

11701178
if (refs->packed &&
11711179
!stat_validity_check(&refs->packed->validity, packed_refs_file))
@@ -1184,7 +1192,6 @@ static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *ref
11841192
fclose(f);
11851193
}
11861194
}
1187-
free(packed_refs_file);
11881195
return refs->packed;
11891196
}
11901197

@@ -2157,7 +2164,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
21572164
}
21582165

21592166
if (hold_lock_file_for_update_timeout(
2160-
&packlock, git_path("packed-refs"),
2167+
&packlock, files_packed_refs_path(refs),
21612168
flags, timeout_value) < 0)
21622169
return -1;
21632170
/*
@@ -2423,7 +2430,7 @@ static int repack_without_refs(struct files_ref_store *refs,
24232430
return 0; /* no refname exists in packed refs */
24242431

24252432
if (lock_packed_refs(refs, 0)) {
2426-
unable_to_lock_message(git_path("packed-refs"), errno, err);
2433+
unable_to_lock_message(files_packed_refs_path(refs), errno, err);
24272434
return -1;
24282435
}
24292436
packed = get_packed_refs(refs);

0 commit comments

Comments
 (0)