Skip to content

Commit 9c7d772

Browse files
mhaggergitster
authored andcommitted
files_ref_store::submodule: use NULL for the main repository
The old practice of storing the empty string in this member for the main repository was a holdover from before 00eebe3 (refs: create a base class "ref_store" for files_ref_store, 2016-09-04), when the submodule was stored in a flex array at the end of `struct files_ref_store`. Storing NULL for this case is more idiomatic and a tiny bit less code. Signed-off-by: Michael Haggerty <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fbfd0a2 commit 9c7d772

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

refs/files-backend.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -915,8 +915,8 @@ struct files_ref_store {
915915

916916
/*
917917
* The name of the submodule represented by this object, or
918-
* the empty string if it represents the main repository's
919-
* reference store:
918+
* NULL if it represents the main repository's reference
919+
* store:
920920
*/
921921
const char *submodule;
922922

@@ -982,7 +982,7 @@ static struct ref_store *files_ref_store_create(const char *submodule)
982982

983983
base_ref_store_init(ref_store, &refs_be_files);
984984

985-
refs->submodule = submodule ? xstrdup(submodule) : "";
985+
refs->submodule = xstrdup_or_null(submodule);
986986

987987
return ref_store;
988988
}
@@ -994,7 +994,7 @@ static struct ref_store *files_ref_store_create(const char *submodule)
994994
static void files_assert_main_repository(struct files_ref_store *refs,
995995
const char *caller)
996996
{
997-
if (*refs->submodule)
997+
if (refs->submodule)
998998
die("BUG: %s called for a submodule", caller);
999999
}
10001000

@@ -1158,7 +1158,7 @@ static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *ref
11581158
{
11591159
char *packed_refs_file;
11601160

1161-
if (*refs->submodule)
1161+
if (refs->submodule)
11621162
packed_refs_file = git_pathdup_submodule(refs->submodule,
11631163
"packed-refs");
11641164
else
@@ -1228,7 +1228,7 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
12281228
size_t path_baselen;
12291229
int err = 0;
12301230

1231-
if (*refs->submodule)
1231+
if (refs->submodule)
12321232
err = strbuf_git_path_submodule(&path, refs->submodule, "%s", dirname);
12331233
else
12341234
strbuf_git_path(&path, "%s", dirname);
@@ -1269,7 +1269,7 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
12691269
} else {
12701270
int read_ok;
12711271

1272-
if (*refs->submodule) {
1272+
if (refs->submodule) {
12731273
hashclr(sha1);
12741274
flag = 0;
12751275
read_ok = !resolve_gitlink_ref(refs->submodule,
@@ -1383,7 +1383,7 @@ static int files_read_raw_ref(struct ref_store *ref_store,
13831383
*type = 0;
13841384
strbuf_reset(&sb_path);
13851385

1386-
if (*refs->submodule)
1386+
if (refs->submodule)
13871387
strbuf_git_path_submodule(&sb_path, refs->submodule, "%s", refname);
13881388
else
13891389
strbuf_git_path(&sb_path, "%s", refname);

0 commit comments

Comments
 (0)