From 9e7ec634a130535982e9bc63d65c2fe8c076a662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sun, 26 Mar 2017 09:42:32 +0700 Subject: files-backend: replace submodule_allowed check in files_downcast() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- refs.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'refs.c') diff --git a/refs.c b/refs.c index d72b48a43..c7bffac06 100644 --- a/refs.c +++ b/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); -- cgit v1.2.1