refs: push the submodule attribute down
Push the submodule attribute down from ref_store to files_ref_store. This is another step towards loosening the 1:1 connection between ref_stores and submodules. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
7d4558c462
commit
32c597e7b2
11
refs.c
11
refs.c
@ -1481,17 +1481,6 @@ void base_ref_store_init(struct ref_store *refs,
|
|||||||
const char *submodule)
|
const char *submodule)
|
||||||
{
|
{
|
||||||
refs->be = be;
|
refs->be = be;
|
||||||
|
|
||||||
if (!submodule)
|
|
||||||
refs->submodule = "";
|
|
||||||
else
|
|
||||||
refs->submodule = xstrdup(submodule);
|
|
||||||
}
|
|
||||||
|
|
||||||
void assert_main_repository(struct ref_store *refs, const char *caller)
|
|
||||||
{
|
|
||||||
if (*refs->submodule)
|
|
||||||
die("BUG: %s called for a submodule", caller);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* backend functions */
|
/* backend functions */
|
||||||
|
@ -912,6 +912,14 @@ struct packed_ref_cache {
|
|||||||
*/
|
*/
|
||||||
struct files_ref_store {
|
struct files_ref_store {
|
||||||
struct ref_store base;
|
struct ref_store base;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The name of the submodule represented by this object, or
|
||||||
|
* the empty string if it represents the main repository's
|
||||||
|
* reference store:
|
||||||
|
*/
|
||||||
|
const char *submodule;
|
||||||
|
|
||||||
struct ref_entry *loose;
|
struct ref_entry *loose;
|
||||||
struct packed_ref_cache *packed;
|
struct packed_ref_cache *packed;
|
||||||
};
|
};
|
||||||
@ -974,9 +982,22 @@ static struct ref_store *files_ref_store_create(const char *submodule)
|
|||||||
|
|
||||||
base_ref_store_init(ref_store, &refs_be_files, submodule);
|
base_ref_store_init(ref_store, &refs_be_files, submodule);
|
||||||
|
|
||||||
|
refs->submodule = submodule ? xstrdup(submodule) : "";
|
||||||
|
|
||||||
return ref_store;
|
return ref_store;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
if (*refs->submodule)
|
||||||
|
die("BUG: %s called for a submodule", caller);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Downcast ref_store to files_ref_store. Die if ref_store is not a
|
* 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. If submodule_allowed is not true, then also die if
|
||||||
@ -987,14 +1008,18 @@ static struct files_ref_store *files_downcast(
|
|||||||
struct ref_store *ref_store, int submodule_allowed,
|
struct ref_store *ref_store, int submodule_allowed,
|
||||||
const char *caller)
|
const char *caller)
|
||||||
{
|
{
|
||||||
|
struct files_ref_store *refs;
|
||||||
|
|
||||||
if (ref_store->be != &refs_be_files)
|
if (ref_store->be != &refs_be_files)
|
||||||
die("BUG: ref_store is type \"%s\" not \"files\" in %s",
|
die("BUG: ref_store is type \"%s\" not \"files\" in %s",
|
||||||
ref_store->be->name, caller);
|
ref_store->be->name, caller);
|
||||||
|
|
||||||
if (!submodule_allowed)
|
refs = (struct files_ref_store *)ref_store;
|
||||||
assert_main_repository(ref_store, caller);
|
|
||||||
|
|
||||||
return (struct files_ref_store *)ref_store;
|
if (!submodule_allowed)
|
||||||
|
files_assert_main_repository(refs, caller);
|
||||||
|
|
||||||
|
return refs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The length of a peeled reference line in packed-refs, including EOL: */
|
/* The length of a peeled reference line in packed-refs, including EOL: */
|
||||||
@ -1133,8 +1158,8 @@ static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *ref
|
|||||||
{
|
{
|
||||||
char *packed_refs_file;
|
char *packed_refs_file;
|
||||||
|
|
||||||
if (*refs->base.submodule)
|
if (*refs->submodule)
|
||||||
packed_refs_file = git_pathdup_submodule(refs->base.submodule,
|
packed_refs_file = git_pathdup_submodule(refs->submodule,
|
||||||
"packed-refs");
|
"packed-refs");
|
||||||
else
|
else
|
||||||
packed_refs_file = git_pathdup("packed-refs");
|
packed_refs_file = git_pathdup("packed-refs");
|
||||||
@ -1203,8 +1228,8 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
|
|||||||
size_t path_baselen;
|
size_t path_baselen;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
if (*refs->base.submodule)
|
if (*refs->submodule)
|
||||||
err = strbuf_git_path_submodule(&path, refs->base.submodule, "%s", dirname);
|
err = strbuf_git_path_submodule(&path, refs->submodule, "%s", dirname);
|
||||||
else
|
else
|
||||||
strbuf_git_path(&path, "%s", dirname);
|
strbuf_git_path(&path, "%s", dirname);
|
||||||
path_baselen = path.len;
|
path_baselen = path.len;
|
||||||
@ -1244,10 +1269,10 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
|
|||||||
} else {
|
} else {
|
||||||
int read_ok;
|
int read_ok;
|
||||||
|
|
||||||
if (*refs->base.submodule) {
|
if (*refs->submodule) {
|
||||||
hashclr(sha1);
|
hashclr(sha1);
|
||||||
flag = 0;
|
flag = 0;
|
||||||
read_ok = !resolve_gitlink_ref(refs->base.submodule,
|
read_ok = !resolve_gitlink_ref(refs->submodule,
|
||||||
refname.buf, sha1);
|
refname.buf, sha1);
|
||||||
} else {
|
} else {
|
||||||
read_ok = !read_ref_full(refname.buf,
|
read_ok = !read_ref_full(refname.buf,
|
||||||
@ -1358,8 +1383,8 @@ static int files_read_raw_ref(struct ref_store *ref_store,
|
|||||||
*type = 0;
|
*type = 0;
|
||||||
strbuf_reset(&sb_path);
|
strbuf_reset(&sb_path);
|
||||||
|
|
||||||
if (*refs->base.submodule)
|
if (*refs->submodule)
|
||||||
strbuf_git_path_submodule(&sb_path, refs->base.submodule, "%s", refname);
|
strbuf_git_path_submodule(&sb_path, refs->submodule, "%s", refname);
|
||||||
else
|
else
|
||||||
strbuf_git_path(&sb_path, "%s", refname);
|
strbuf_git_path(&sb_path, "%s", refname);
|
||||||
|
|
||||||
@ -1540,7 +1565,7 @@ static int lock_raw_ref(struct files_ref_store *refs,
|
|||||||
int ret = TRANSACTION_GENERIC_ERROR;
|
int ret = TRANSACTION_GENERIC_ERROR;
|
||||||
|
|
||||||
assert(err);
|
assert(err);
|
||||||
assert_main_repository(&refs->base, "lock_raw_ref");
|
files_assert_main_repository(refs, "lock_raw_ref");
|
||||||
|
|
||||||
*type = 0;
|
*type = 0;
|
||||||
|
|
||||||
@ -2006,7 +2031,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
|
|||||||
int attempts_remaining = 3;
|
int attempts_remaining = 3;
|
||||||
int resolved;
|
int resolved;
|
||||||
|
|
||||||
assert_main_repository(&refs->base, "lock_ref_sha1_basic");
|
files_assert_main_repository(refs, "lock_ref_sha1_basic");
|
||||||
assert(err);
|
assert(err);
|
||||||
|
|
||||||
lock = xcalloc(1, sizeof(struct ref_lock));
|
lock = xcalloc(1, sizeof(struct ref_lock));
|
||||||
@ -2152,7 +2177,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
|
|||||||
static int timeout_value = 1000;
|
static int timeout_value = 1000;
|
||||||
struct packed_ref_cache *packed_ref_cache;
|
struct packed_ref_cache *packed_ref_cache;
|
||||||
|
|
||||||
assert_main_repository(&refs->base, "lock_packed_refs");
|
files_assert_main_repository(refs, "lock_packed_refs");
|
||||||
|
|
||||||
if (!timeout_configured) {
|
if (!timeout_configured) {
|
||||||
git_config_get_int("core.packedrefstimeout", &timeout_value);
|
git_config_get_int("core.packedrefstimeout", &timeout_value);
|
||||||
@ -2190,7 +2215,7 @@ static int commit_packed_refs(struct files_ref_store *refs)
|
|||||||
int save_errno = 0;
|
int save_errno = 0;
|
||||||
FILE *out;
|
FILE *out;
|
||||||
|
|
||||||
assert_main_repository(&refs->base, "commit_packed_refs");
|
files_assert_main_repository(refs, "commit_packed_refs");
|
||||||
|
|
||||||
if (!packed_ref_cache->lock)
|
if (!packed_ref_cache->lock)
|
||||||
die("internal error: packed-refs not locked");
|
die("internal error: packed-refs not locked");
|
||||||
@ -2223,7 +2248,7 @@ static void rollback_packed_refs(struct files_ref_store *refs)
|
|||||||
struct packed_ref_cache *packed_ref_cache =
|
struct packed_ref_cache *packed_ref_cache =
|
||||||
get_packed_ref_cache(refs);
|
get_packed_ref_cache(refs);
|
||||||
|
|
||||||
assert_main_repository(&refs->base, "rollback_packed_refs");
|
files_assert_main_repository(refs, "rollback_packed_refs");
|
||||||
|
|
||||||
if (!packed_ref_cache->lock)
|
if (!packed_ref_cache->lock)
|
||||||
die("internal error: packed-refs not locked");
|
die("internal error: packed-refs not locked");
|
||||||
@ -2397,7 +2422,7 @@ static int repack_without_refs(struct files_ref_store *refs,
|
|||||||
struct string_list_item *refname;
|
struct string_list_item *refname;
|
||||||
int ret, needs_repacking = 0, removed = 0;
|
int ret, needs_repacking = 0, removed = 0;
|
||||||
|
|
||||||
assert_main_repository(&refs->base, "repack_without_refs");
|
files_assert_main_repository(refs, "repack_without_refs");
|
||||||
assert(err);
|
assert(err);
|
||||||
|
|
||||||
/* Look for a packed ref */
|
/* Look for a packed ref */
|
||||||
@ -2930,7 +2955,7 @@ static int commit_ref_update(struct files_ref_store *refs,
|
|||||||
const unsigned char *sha1, const char *logmsg,
|
const unsigned char *sha1, const char *logmsg,
|
||||||
struct strbuf *err)
|
struct strbuf *err)
|
||||||
{
|
{
|
||||||
assert_main_repository(&refs->base, "commit_ref_update");
|
files_assert_main_repository(refs, "commit_ref_update");
|
||||||
|
|
||||||
clear_loose_ref_cache(refs);
|
clear_loose_ref_cache(refs);
|
||||||
if (log_ref_write(lock->ref_name, lock->old_oid.hash, sha1, logmsg, 0, err)) {
|
if (log_ref_write(lock->ref_name, lock->old_oid.hash, sha1, logmsg, 0, err)) {
|
||||||
@ -3560,7 +3585,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
|
|||||||
int ret;
|
int ret;
|
||||||
struct ref_lock *lock;
|
struct ref_lock *lock;
|
||||||
|
|
||||||
assert_main_repository(&refs->base, "lock_ref_for_update");
|
files_assert_main_repository(refs, "lock_ref_for_update");
|
||||||
|
|
||||||
if ((update->flags & REF_HAVE_NEW) && is_null_sha1(update->new_sha1))
|
if ((update->flags & REF_HAVE_NEW) && is_null_sha1(update->new_sha1))
|
||||||
update->flags |= REF_DELETING;
|
update->flags |= REF_DELETING;
|
||||||
|
@ -629,13 +629,6 @@ extern struct ref_storage_be refs_be_files;
|
|||||||
struct ref_store {
|
struct ref_store {
|
||||||
/* The backend describing this ref_store's storage scheme: */
|
/* The backend describing this ref_store's storage scheme: */
|
||||||
const struct ref_storage_be *be;
|
const struct ref_storage_be *be;
|
||||||
|
|
||||||
/*
|
|
||||||
* The name of the submodule represented by this object, or
|
|
||||||
* the empty string if it represents the main repository's
|
|
||||||
* reference store:
|
|
||||||
*/
|
|
||||||
const char *submodule;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -658,10 +651,4 @@ void base_ref_store_init(struct ref_store *refs,
|
|||||||
*/
|
*/
|
||||||
struct ref_store *get_ref_store(const char *submodule);
|
struct ref_store *get_ref_store(const char *submodule);
|
||||||
|
|
||||||
/*
|
|
||||||
* Die if refs is for a submodule (i.e., not for the main repository).
|
|
||||||
* caller is used in any necessary error messages.
|
|
||||||
*/
|
|
||||||
void assert_main_repository(struct ref_store *refs, const char *caller);
|
|
||||||
|
|
||||||
#endif /* REFS_REFS_INTERNAL_H */
|
#endif /* REFS_REFS_INTERNAL_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user