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>
maint
Han-Wen Nienhuys 2020-08-19 14:27:57 +00:00 committed by Junio C Hamano
parent 4877c6c738
commit 5085aef4c8
3 changed files with 10 additions and 9 deletions

View File

@ -67,7 +67,6 @@ struct files_ref_store {
struct ref_store base; struct ref_store base;
unsigned int store_flags; unsigned int store_flags;


char *gitdir;
char *gitcommondir; char *gitcommondir;


struct ref_cache *loose; struct ref_cache *loose;
@ -94,18 +93,17 @@ static struct ref_store *files_ref_store_create(const char *gitdir,
struct ref_store *ref_store = (struct ref_store *)refs; struct ref_store *ref_store = (struct ref_store *)refs;
struct strbuf sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT;


ref_store->gitdir = xstrdup(gitdir);
base_ref_store_init(ref_store, &refs_be_files); base_ref_store_init(ref_store, &refs_be_files);
refs->store_flags = flags; refs->store_flags = flags;


refs->gitdir = xstrdup(gitdir);
get_common_dir_noenv(&sb, gitdir); get_common_dir_noenv(&sb, gitdir);
refs->gitcommondir = strbuf_detach(&sb, NULL); refs->gitcommondir = strbuf_detach(&sb, NULL);
strbuf_addf(&sb, "%s/packed-refs", refs->gitcommondir); strbuf_addf(&sb, "%s/packed-refs", refs->gitcommondir);
refs->packed_ref_store = packed_ref_store_create(sb.buf, flags); refs->packed_ref_store = packed_ref_store_create(sb.buf, flags);
strbuf_release(&sb); strbuf_release(&sb);


chdir_notify_reparent("files-backend $GIT_DIR", chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir);
&refs->gitdir);
chdir_notify_reparent("files-backend $GIT_COMMONDIR", chdir_notify_reparent("files-backend $GIT_COMMONDIR",
&refs->gitcommondir); &refs->gitcommondir);


@ -176,7 +174,7 @@ static void files_reflog_path(struct files_ref_store *refs,
switch (ref_type(refname)) { switch (ref_type(refname)) {
case REF_TYPE_PER_WORKTREE: case REF_TYPE_PER_WORKTREE:
case REF_TYPE_PSEUDOREF: case REF_TYPE_PSEUDOREF:
strbuf_addf(sb, "%s/logs/%s", refs->gitdir, refname); strbuf_addf(sb, "%s/logs/%s", refs->base.gitdir, refname);
break; break;
case REF_TYPE_OTHER_PSEUDOREF: case REF_TYPE_OTHER_PSEUDOREF:
case REF_TYPE_MAIN_PSEUDOREF: case REF_TYPE_MAIN_PSEUDOREF:
@ -198,7 +196,7 @@ static void files_ref_path(struct files_ref_store *refs,
switch (ref_type(refname)) { switch (ref_type(refname)) {
case REF_TYPE_PER_WORKTREE: case REF_TYPE_PER_WORKTREE:
case REF_TYPE_PSEUDOREF: case REF_TYPE_PSEUDOREF:
strbuf_addf(sb, "%s/%s", refs->gitdir, refname); strbuf_addf(sb, "%s/%s", refs->base.gitdir, refname);
break; break;
case REF_TYPE_MAIN_PSEUDOREF: case REF_TYPE_MAIN_PSEUDOREF:
if (!skip_prefix(refname, "main-worktree/", &refname)) if (!skip_prefix(refname, "main-worktree/", &refname))
@ -2203,12 +2201,11 @@ static struct ref_iterator *files_reflog_iterator_begin(struct ref_store *ref_st
files_downcast(ref_store, REF_STORE_READ, files_downcast(ref_store, REF_STORE_READ,
"reflog_iterator_begin"); "reflog_iterator_begin");


if (!strcmp(refs->gitdir, refs->gitcommondir)) { if (!strcmp(refs->base.gitdir, refs->gitcommondir)) {
return reflog_iterator_begin(ref_store, refs->gitcommondir); return reflog_iterator_begin(ref_store, refs->gitcommondir);
} else { } else {
return merge_ref_iterator_begin( return merge_ref_iterator_begin(
0, 0, reflog_iterator_begin(ref_store, refs->base.gitdir),
reflog_iterator_begin(ref_store, refs->gitdir),
reflog_iterator_begin(ref_store, refs->gitcommondir), reflog_iterator_begin(ref_store, refs->gitcommondir),
reflog_iterator_select, refs); reflog_iterator_select, refs);
} }

View File

@ -200,6 +200,7 @@ struct ref_store *packed_ref_store_create(const char *path,
struct ref_store *ref_store = (struct ref_store *)refs; struct ref_store *ref_store = (struct ref_store *)refs;


base_ref_store_init(ref_store, &refs_be_packed); base_ref_store_init(ref_store, &refs_be_packed);
ref_store->gitdir = xstrdup(path);
refs->store_flags = store_flags; refs->store_flags = store_flags;


refs->path = xstrdup(path); refs->path = xstrdup(path);

View File

@ -672,6 +672,9 @@ extern struct ref_storage_be refs_be_packed;
struct ref_store { struct ref_store {
/* The backend describing this ref_store's storage scheme: */ /* The backend describing this ref_store's storage scheme: */
const struct ref_storage_be *be; const struct ref_storage_be *be;

/* The gitdir that this ref_store applies to: */
char *gitdir;
}; };


/* /*