@matheusbsbs / matheus-bagliano / commits / 5085aef4c8
Fork 0

refs: move gitdir into base ref_store

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Han-Wen Nienhuys committed Aug 19, 2020 at 14:27 UTC 5085aef4c8e569e5d688d9f35790a2ca2c2f4c11
3 files changed +10 -9
refs/files-backend.c
+6 -9
@@ -67,7 +67,6 @@ struct files_ref_store {
67 struct ref_store base;
68 unsigned int store_flags;
69
70 - char *gitdir;
70 char *gitcommondir;
71
72 struct ref_cache *loose;
@@ -94,18 +93,17 @@ static struct ref_store *files_ref_store_create(const char *gitdir,
93 struct ref_store *ref_store = (struct ref_store *)refs;
94 struct strbuf sb = STRBUF_INIT;
95
96 + ref_store->gitdir = xstrdup(gitdir);
97 base_ref_store_init(ref_store, &refs_be_files);
98 refs->store_flags = flags;
99
100 - refs->gitdir = xstrdup(gitdir);
100 get_common_dir_noenv(&sb, gitdir);
101 refs->gitcommondir = strbuf_detach(&sb, NULL);
102 strbuf_addf(&sb, "%s/packed-refs", refs->gitcommondir);
103 refs->packed_ref_store = packed_ref_store_create(sb.buf, flags);
104 strbuf_release(&sb);
105
107 - chdir_notify_reparent("files-backend $GIT_DIR",
108 - &refs->gitdir);
106 + chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir);
107 chdir_notify_reparent("files-backend $GIT_COMMONDIR",
108 &refs->gitcommondir);
109
@@ -176,7 +174,7 @@ static void files_reflog_path(struct files_ref_store *refs,
174 switch (ref_type(refname)) {
175 case REF_TYPE_PER_WORKTREE:
176 case REF_TYPE_PSEUDOREF:
179 - strbuf_addf(sb, "%s/logs/%s", refs->gitdir, refname);
177 + strbuf_addf(sb, "%s/logs/%s", refs->base.gitdir, refname);
178 break;
179 case REF_TYPE_OTHER_PSEUDOREF:
180 case REF_TYPE_MAIN_PSEUDOREF:
@@ -198,7 +196,7 @@ static void files_ref_path(struct files_ref_store *refs,
196 switch (ref_type(refname)) {
197 case REF_TYPE_PER_WORKTREE:
198 case REF_TYPE_PSEUDOREF:
201 - strbuf_addf(sb, "%s/%s", refs->gitdir, refname);
199 + strbuf_addf(sb, "%s/%s", refs->base.gitdir, refname);
200 break;
201 case REF_TYPE_MAIN_PSEUDOREF:
202 if (!skip_prefix(refname, "main-worktree/", &refname))
@@ -2203,12 +2201,11 @@ static struct ref_iterator *files_reflog_iterator_begin(struct ref_store *ref_st
2201 files_downcast(ref_store, REF_STORE_READ,
2202 "reflog_iterator_begin");
2203
2206 - if (!strcmp(refs->gitdir, refs->gitcommondir)) {
2204 + if (!strcmp(refs->base.gitdir, refs->gitcommondir)) {
2205 return reflog_iterator_begin(ref_store, refs->gitcommondir);
2206 } else {
2207 return merge_ref_iterator_begin(
2210 - 0,
2211 - reflog_iterator_begin(ref_store, refs->gitdir),
2208 + 0, reflog_iterator_begin(ref_store, refs->base.gitdir),
2209 reflog_iterator_begin(ref_store, refs->gitcommondir),
2210 reflog_iterator_select, refs);
2211 }
refs/packed-backend.c
+1
@@ -200,6 +200,7 @@ struct ref_store *packed_ref_store_create(const char *path,
200 struct ref_store *ref_store = (struct ref_store *)refs;
201
202 base_ref_store_init(ref_store, &refs_be_packed);
203 + ref_store->gitdir = xstrdup(path);
204 refs->store_flags = store_flags;
205
206 refs->path = xstrdup(path);
refs/refs-internal.h
+3
@@ -672,6 +672,9 @@ extern struct ref_storage_be refs_be_packed;
672 struct ref_store {
673 /* The backend describing this ref_store's storage scheme: */
674 const struct ref_storage_be *be;
675 +
676 + /* The gitdir that this ref_store applies to: */
677 + char *gitdir;
678 };
679
680 /*