get_ref_store() will soon be renamed to get_submodule_ref_store(). Together with future get_worktree_ref_store(), the three functions provide an appropriate ref store for different operation modes. New APIs will be added to operate directly on ref stores. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- refs.c | 36 ++++++++++++++++++------------------ refs.h | 2 ++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/refs.c b/refs.c index 8b640bd05..1b60e6180 100644 --- a/refs.c +++ b/refs.c @@ -1308,7 +1308,7 @@ const char *resolve_ref_recursively(struct ref_store *refs, /* backend functions */ int refs_init_db(struct strbuf *err) { - struct ref_store *refs = get_ref_store(NULL); + struct ref_store *refs = get_main_ref_store(); return refs->be->init_db(refs, err); } @@ -1316,7 +1316,7 @@ int refs_init_db(struct strbuf *err) const char *resolve_ref_unsafe(const char *refname, int resolve_flags, unsigned char *sha1, int *flags) { - return resolve_ref_recursively(get_ref_store(NULL), refname, + return resolve_ref_recursively(get_main_ref_store(), refname, resolve_flags, sha1, flags); } @@ -1439,7 +1439,7 @@ static struct ref_store *ref_store_init(const char *submodule) return refs; } -static struct ref_store *get_main_ref_store(void) +struct ref_store *get_main_ref_store(void) { struct ref_store *refs; @@ -1488,14 +1488,14 @@ void base_ref_store_init(struct ref_store *refs, /* backend functions */ int pack_refs(unsigned int flags) { - struct ref_store *refs = get_ref_store(NULL); + struct ref_store *refs = get_main_ref_store(); return refs->be->pack_refs(refs, flags); } int peel_ref(const char *refname, unsigned char *sha1) { - struct ref_store *refs = get_ref_store(NULL); + struct ref_store *refs = get_main_ref_store(); return refs->be->peel_ref(refs, refname, sha1); } @@ -1503,7 +1503,7 @@ int peel_ref(const char *refname, unsigned char *sha1) int create_symref(const char *ref_target, const char *refs_heads_master, const char *logmsg) { - struct ref_store *refs = get_ref_store(NULL); + struct ref_store *refs = get_main_ref_store(); return refs->be->create_symref(refs, ref_target, refs_heads_master, logmsg); @@ -1512,7 +1512,7 @@ int create_symref(const char *ref_target, const char *refs_heads_master, int ref_transaction_commit(struct ref_transaction *transaction, struct strbuf *err) { - struct ref_store *refs = get_ref_store(NULL); + struct ref_store *refs = get_main_ref_store(); return refs->be->transaction_commit(refs, transaction, err); } @@ -1522,14 +1522,14 @@ int verify_refname_available(const char *refname, const struct string_list *skip, struct strbuf *err) { - struct ref_store *refs = get_ref_store(NULL); + struct ref_store *refs = get_main_ref_store(); return refs->be->verify_refname_available(refs, refname, extra, skip, err); } int for_each_reflog(each_ref_fn fn, void *cb_data) { - struct ref_store *refs = get_ref_store(NULL); + struct ref_store *refs = get_main_ref_store(); struct ref_iterator *iter; iter = refs->be->reflog_iterator_begin(refs); @@ -1540,7 +1540,7 @@ int for_each_reflog(each_ref_fn fn, void *cb_data) int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn, void *cb_data) { - struct ref_store *refs = get_ref_store(NULL); + struct ref_store *refs = get_main_ref_store(); return refs->be->for_each_reflog_ent_reverse(refs, refname, fn, cb_data); @@ -1549,14 +1549,14 @@ int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn, int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn, void *cb_data) { - struct ref_store *refs = get_ref_store(NULL); + struct ref_store *refs = get_main_ref_store(); return refs->be->for_each_reflog_ent(refs, refname, fn, cb_data); } int reflog_exists(const char *refname) { - struct ref_store *refs = get_ref_store(NULL); + struct ref_store *refs = get_main_ref_store(); return refs->be->reflog_exists(refs, refname); } @@ -1564,14 +1564,14 @@ int reflog_exists(const char *refname) int safe_create_reflog(const char *refname, int force_create, struct strbuf *err) { - struct ref_store *refs = get_ref_store(NULL); + struct ref_store *refs = get_main_ref_store(); return refs->be->create_reflog(refs, refname, force_create, err); } int delete_reflog(const char *refname) { - struct ref_store *refs = get_ref_store(NULL); + struct ref_store *refs = get_main_ref_store(); return refs->be->delete_reflog(refs, refname); } @@ -1583,7 +1583,7 @@ int reflog_expire(const char *refname, const unsigned char *sha1, reflog_expiry_cleanup_fn cleanup_fn, void *policy_cb_data) { - struct ref_store *refs = get_ref_store(NULL); + struct ref_store *refs = get_main_ref_store(); return refs->be->reflog_expire(refs, refname, sha1, flags, prepare_fn, should_prune_fn, @@ -1593,21 +1593,21 @@ int reflog_expire(const char *refname, const unsigned char *sha1, int initial_ref_transaction_commit(struct ref_transaction *transaction, struct strbuf *err) { - struct ref_store *refs = get_ref_store(NULL); + struct ref_store *refs = get_main_ref_store(); return refs->be->initial_transaction_commit(refs, transaction, err); } int delete_refs(struct string_list *refnames, unsigned int flags) { - struct ref_store *refs = get_ref_store(NULL); + struct ref_store *refs = get_main_ref_store(); return refs->be->delete_refs(refs, refnames, flags); } int rename_ref(const char *oldref, const char *newref, const char *logmsg) { - struct ref_store *refs = get_ref_store(NULL); + struct ref_store *refs = get_main_ref_store(); return refs->be->rename_ref(refs, oldref, newref, logmsg); } diff --git a/refs.h b/refs.h index 9fbff90e7..a35b687d7 100644 --- a/refs.h +++ b/refs.h @@ -555,4 +555,6 @@ int reflog_expire(const char *refname, const unsigned char *sha1, int ref_storage_backend_exists(const char *name); +struct ref_store *get_main_ref_store(void); + #endif /* REFS_H */ -- 2.11.0.157.gd943d85