summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2017-03-26 09:42:32 +0700
committerJunio C Hamano <gitster@pobox.com>2017-04-14 03:53:18 -0700
commit9e7ec634a130535982e9bc63d65c2fe8c076a662 (patch)
treeba46cac1a5efa78d3c0fb809f4d3396e25830ea9 /refs.c
parent5d0bc90e5de37c708f0856aef2c7b353a9d5030b (diff)
downloadgit-9e7ec634a130535982e9bc63d65c2fe8c076a662.tar.gz
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>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/refs.c b/refs.c
index d72b48a430..c7bffac06d 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);