files-backend: replace submodule_allowed check in files_downcast()
files-backend.c is unlearning submodules. Instead of having a specific check for submodules to see what operation is allowed, files backend now takes a set of flags at init. Each operation will check if the required flags is present before performing. For now we have four flags: read, write and odb access. Main ref store has all flags, obviously, while submodule stores are read-only and have access to odb (*). The "main" flag stays because many functions in the backend calls frontend ones without a ref store, so these functions always target the main ref store. Ideally the flag should be gone after ref-store-aware api is in place and used by backends. (*) Submodule code needs for_each_ref. Try take REF_STORE_ODB flag out. At least t3404 would fail. The "have access to odb" in submodule is a bit hacky since we don't know from he whether add_submodule_odb() has been called. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
5d0bc90e5d
commit
9e7ec634a1
15
refs.c
15
refs.c
@ -1416,7 +1416,8 @@ static struct ref_store *lookup_submodule_ref_store(const char *submodule)
|
||||
* Create, record, and return a ref_store instance for the specified
|
||||
* gitdir.
|
||||
*/
|
||||
static struct ref_store *ref_store_init(const char *gitdir)
|
||||
static struct ref_store *ref_store_init(const char *gitdir,
|
||||
unsigned int flags)
|
||||
{
|
||||
const char *be_name = "files";
|
||||
struct ref_storage_be *be = find_ref_storage_backend(be_name);
|
||||
@ -1425,7 +1426,7 @@ static struct ref_store *ref_store_init(const char *gitdir)
|
||||
if (!be)
|
||||
die("BUG: reference backend %s is unknown", be_name);
|
||||
|
||||
refs = be->init(gitdir);
|
||||
refs = be->init(gitdir, flags);
|
||||
return refs;
|
||||
}
|
||||
|
||||
@ -1434,7 +1435,11 @@ struct ref_store *get_main_ref_store(void)
|
||||
if (main_ref_store)
|
||||
return main_ref_store;
|
||||
|
||||
main_ref_store = ref_store_init(get_git_dir());
|
||||
main_ref_store = ref_store_init(get_git_dir(),
|
||||
(REF_STORE_READ |
|
||||
REF_STORE_WRITE |
|
||||
REF_STORE_ODB |
|
||||
REF_STORE_MAIN));
|
||||
return main_ref_store;
|
||||
}
|
||||
|
||||
@ -1481,7 +1486,9 @@ struct ref_store *get_ref_store(const char *submodule)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
refs = ref_store_init(submodule_sb.buf);
|
||||
/* assume that add_submodule_odb() has been called */
|
||||
refs = ref_store_init(submodule_sb.buf,
|
||||
REF_STORE_READ | REF_STORE_ODB);
|
||||
register_submodule_ref_store(refs, submodule);
|
||||
|
||||
strbuf_release(&submodule_sb);
|
||||
|
Reference in New Issue
Block a user