Since submodule or not is irrelevant to files-backend after the last patch, remove the parameter from files_downcast() and kill files_assert_main_repository(). PS. This implies that all ref operations are allowed for submodules. But we may need to look more closely to see if that's really true... Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- refs/files-backend.c | 70 ++++++++++++++++------------------------------------ 1 file changed, 21 insertions(+), 49 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 529c80af1..b8ccf4e47 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1030,24 +1030,13 @@ static struct ref_store *files_ref_store_create(const char *gitdir) } /* - * Die if refs is for a submodule (i.e., not for the main repository). - * caller is used in any necessary error messages. - */ -static void files_assert_main_repository(struct files_ref_store *refs, - const char *caller) -{ - /* This function is to be deleted in the next patch */ -} - -/* * Downcast ref_store to files_ref_store. Die if ref_store is not a * files_ref_store. If submodule_allowed is not true, then also die if * files_ref_store is for a submodule (i.e., not for the main * repository). caller is used in any necessary error messages. */ -static struct files_ref_store *files_downcast( - struct ref_store *ref_store, int submodule_allowed, - const char *caller) +static struct files_ref_store *files_downcast(struct ref_store *ref_store, + const char *caller) { struct files_ref_store *refs; @@ -1057,9 +1046,6 @@ static struct files_ref_store *files_downcast( refs = (struct files_ref_store *)ref_store; - if (!submodule_allowed) - files_assert_main_repository(refs, caller); - return refs; } @@ -1395,7 +1381,7 @@ static int files_read_raw_ref(struct ref_store *ref_store, struct strbuf *referent, unsigned int *type) { struct files_ref_store *refs = - files_downcast(ref_store, 1, "read_raw_ref"); + files_downcast(ref_store, "read_raw_ref"); struct strbuf sb_contents = STRBUF_INIT; struct strbuf sb_path = STRBUF_INIT; const char *path; @@ -1588,7 +1574,6 @@ static int lock_raw_ref(struct files_ref_store *refs, int ret = TRANSACTION_GENERIC_ERROR; assert(err); - files_assert_main_repository(refs, "lock_raw_ref"); *type = 0; @@ -1812,7 +1797,7 @@ static enum peel_status peel_entry(struct ref_entry *entry, int repeel) static int files_peel_ref(struct ref_store *ref_store, const char *refname, unsigned char *sha1) { - struct files_ref_store *refs = files_downcast(ref_store, 0, "peel_ref"); + struct files_ref_store *refs = files_downcast(ref_store, "peel_ref"); int flag; unsigned char base[20]; @@ -1921,7 +1906,7 @@ static struct ref_iterator *files_ref_iterator_begin( const char *prefix, unsigned int flags) { struct files_ref_store *refs = - files_downcast(ref_store, 1, "ref_iterator_begin"); + files_downcast(ref_store, "ref_iterator_begin"); struct ref_dir *loose_dir, *packed_dir; struct ref_iterator *loose_iter, *packed_iter; struct files_ref_iterator *iter; @@ -2059,7 +2044,6 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs, int resolve_flags = RESOLVE_REF_NO_RECURSE; int resolved; - files_assert_main_repository(refs, "lock_ref_sha1_basic"); assert(err); lock = xcalloc(1, sizeof(struct ref_lock)); @@ -2184,8 +2168,6 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags) struct strbuf sb = STRBUF_INIT; int ret; - files_assert_main_repository(refs, "lock_packed_refs"); - if (!timeout_configured) { git_config_get_int("core.packedrefstimeout", &timeout_value); timeout_configured = 1; @@ -2225,8 +2207,6 @@ static int commit_packed_refs(struct files_ref_store *refs) int save_errno = 0; FILE *out; - files_assert_main_repository(refs, "commit_packed_refs"); - if (!packed_ref_cache->lock) die("internal error: packed-refs not locked"); @@ -2258,8 +2238,6 @@ static void rollback_packed_refs(struct files_ref_store *refs) struct packed_ref_cache *packed_ref_cache = get_packed_ref_cache(refs); - files_assert_main_repository(refs, "rollback_packed_refs"); - if (!packed_ref_cache->lock) die("internal error: packed-refs not locked"); rollback_lock_file(packed_ref_cache->lock); @@ -2420,7 +2398,7 @@ static void prune_refs(struct files_ref_store *refs, struct ref_to_prune *r) static int files_pack_refs(struct ref_store *ref_store, unsigned int flags) { struct files_ref_store *refs = - files_downcast(ref_store, 0, "pack_refs"); + files_downcast(ref_store, "pack_refs"); struct pack_refs_cb_data cbdata; memset(&cbdata, 0, sizeof(cbdata)); @@ -2453,7 +2431,6 @@ static int repack_without_refs(struct files_ref_store *refs, struct string_list_item *refname; int ret, needs_repacking = 0, removed = 0; - files_assert_main_repository(refs, "repack_without_refs"); assert(err); /* Look for a packed ref */ @@ -2503,7 +2480,7 @@ static int files_delete_refs(struct ref_store *ref_store, struct string_list *refnames, unsigned int flags) { struct files_ref_store *refs = - files_downcast(ref_store, 0, "delete_refs"); + files_downcast(ref_store, "delete_refs"); struct strbuf err = STRBUF_INIT; int i, result = 0; @@ -2615,7 +2592,7 @@ static int files_verify_refname_available(struct ref_store *ref_store, struct strbuf *err) { struct files_ref_store *refs = - files_downcast(ref_store, 1, "verify_refname_available"); + files_downcast(ref_store, "verify_refname_available"); struct ref_dir *packed_refs = get_packed_refs(refs); struct ref_dir *loose_refs = get_loose_refs(refs); @@ -2640,7 +2617,7 @@ static int files_rename_ref(struct ref_store *ref_store, const char *logmsg) { struct files_ref_store *refs = - files_downcast(ref_store, 0, "rename_ref"); + files_downcast(ref_store, "rename_ref"); unsigned char sha1[20], orig_sha1[20]; int flag = 0, logmoved = 0; struct ref_lock *lock; @@ -2883,7 +2860,7 @@ static int files_create_reflog(struct ref_store *ref_store, struct strbuf *err) { struct files_ref_store *refs = - files_downcast(ref_store, 0, "create_reflog"); + files_downcast(ref_store, "create_reflog"); int fd; if (log_ref_setup(refs, refname, force_create, &fd, err)) @@ -3014,8 +2991,6 @@ static int commit_ref_update(struct files_ref_store *refs, const unsigned char *sha1, const char *logmsg, struct strbuf *err) { - files_assert_main_repository(refs, "commit_ref_update"); - clear_loose_ref_cache(refs); if (files_log_ref_write(refs, lock->ref_name, lock->old_oid.hash, sha1, logmsg, 0, err)) { @@ -3124,7 +3099,7 @@ static int files_create_symref(struct ref_store *ref_store, const char *logmsg) { struct files_ref_store *refs = - files_downcast(ref_store, 0, "create_symref"); + files_downcast(ref_store, "create_symref"); struct strbuf err = STRBUF_INIT; struct ref_lock *lock; int ret; @@ -3150,7 +3125,7 @@ int set_worktree_head_symref(const char *gitdir, const char *target) * backends. This function needs to die. */ struct files_ref_store *refs = - files_downcast(get_ref_store(NULL), 0, "set_head_symref"); + files_downcast(get_ref_store(NULL), "set_head_symref"); static struct lock_file head_lock; struct ref_lock *lock; struct strbuf head_path = STRBUF_INIT; @@ -3188,7 +3163,7 @@ static int files_reflog_exists(struct ref_store *ref_store, const char *refname) { struct files_ref_store *refs = - files_downcast(ref_store, 0, "reflog_exists"); + files_downcast(ref_store, "reflog_exists"); struct strbuf sb = STRBUF_INIT; struct stat st; int ret; @@ -3203,7 +3178,7 @@ static int files_delete_reflog(struct ref_store *ref_store, const char *refname) { struct files_ref_store *refs = - files_downcast(ref_store, 0, "delete_reflog"); + files_downcast(ref_store, "delete_reflog"); struct strbuf sb = STRBUF_INIT; int ret; @@ -3258,7 +3233,7 @@ static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store, void *cb_data) { struct files_ref_store *refs = - files_downcast(ref_store, 0, "for_each_reflog_ent_reverse"); + files_downcast(ref_store, "for_each_reflog_ent_reverse"); struct strbuf sb = STRBUF_INIT; FILE *logfp; long pos; @@ -3366,7 +3341,7 @@ static int files_for_each_reflog_ent(struct ref_store *ref_store, each_reflog_ent_fn fn, void *cb_data) { struct files_ref_store *refs = - files_downcast(ref_store, 0, "for_each_reflog_ent"); + files_downcast(ref_store, "for_each_reflog_ent"); FILE *logfp; struct strbuf sb = STRBUF_INIT; int ret = 0; @@ -3454,7 +3429,7 @@ static struct ref_iterator_vtable files_reflog_iterator_vtable = { static struct ref_iterator *files_reflog_iterator_begin(struct ref_store *ref_store) { struct files_ref_store *refs = - files_downcast(ref_store, 0, "reflog_iterator_begin"); + files_downcast(ref_store, "reflog_iterator_begin"); struct files_reflog_iterator *iter = xcalloc(1, sizeof(*iter)); struct ref_iterator *ref_iterator = &iter->base; struct strbuf sb = STRBUF_INIT; @@ -3666,8 +3641,6 @@ static int lock_ref_for_update(struct files_ref_store *refs, int ret; struct ref_lock *lock; - files_assert_main_repository(refs, "lock_ref_for_update"); - if ((update->flags & REF_HAVE_NEW) && is_null_sha1(update->new_sha1)) update->flags |= REF_DELETING; @@ -3792,7 +3765,7 @@ static int files_transaction_commit(struct ref_store *ref_store, struct strbuf *err) { struct files_ref_store *refs = - files_downcast(ref_store, 0, "ref_transaction_commit"); + files_downcast(ref_store, "ref_transaction_commit"); int ret = 0, i; struct string_list refs_to_delete = STRING_LIST_INIT_NODUP; struct string_list_item *ref_to_delete; @@ -4000,7 +3973,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store, struct strbuf *err) { struct files_ref_store *refs = - files_downcast(ref_store, 0, "initial_ref_transaction_commit"); + files_downcast(ref_store, "initial_ref_transaction_commit"); int ret = 0, i; struct string_list affected_refnames = STRING_LIST_INIT_NODUP; @@ -4122,7 +4095,7 @@ static int files_reflog_expire(struct ref_store *ref_store, void *policy_cb_data) { struct files_ref_store *refs = - files_downcast(ref_store, 0, "reflog_expire"); + files_downcast(ref_store, "reflog_expire"); static struct lock_file reflog_lock; struct expire_reflog_cb cb; struct ref_lock *lock; @@ -4227,8 +4200,7 @@ static int files_reflog_expire(struct ref_store *ref_store, static int files_init_db(struct ref_store *ref_store, struct strbuf *err) { - struct files_ref_store *refs = - files_downcast(ref_store, 0, "init_db"); + struct files_ref_store *refs = files_downcast(ref_store, "init_db"); struct strbuf sb = STRBUF_INIT; /* -- 2.11.0.157.gd943d85