flags, NULL, err);
}
+int update_ref_oid(const char *msg, const char *refname,
+ const struct object_id *new_oid, const struct object_id *old_oid,
+ unsigned int flags, enum action_on_err onerr)
+{
+ return update_ref(msg, refname, new_oid ? new_oid->hash : NULL,
+ old_oid ? old_oid->hash : NULL, flags, onerr);
+}
+
int update_ref(const char *msg, const char *refname,
const unsigned char *new_sha1, const unsigned char *old_sha1,
unsigned int flags, enum action_on_err onerr)
/* -2 for strlen("%.*s") - strlen("%s"); +1 for NUL */
total_len += strlen(ref_rev_parse_rules[nr_rules]) - 2 + 1;
- scanf_fmts = xmalloc(st_add(st_mult(nr_rules, sizeof(char *)), total_len));
+ scanf_fmts = xmalloc(st_add(st_mult(sizeof(char *), nr_rules), total_len));
offset = 0;
for (i = 0; i < nr_rules; i++) {
if (!refs)
return 0;
- iter = files_ref_iterator_begin(submodule, prefix, flags);
+ iter = refs->be->iterator_begin(refs, prefix, flags);
iter = prefix_ref_iterator_begin(iter, prefix, trim);
return do_for_each_ref_iterator(iter, fn, cb_data);
}
/* This function needs to return a meaningful errno on failure */
-const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
- unsigned char *sha1, int *flags)
+static const char *resolve_ref_recursively(struct ref_store *refs,
+ const char *refname,
+ int resolve_flags,
+ unsigned char *sha1, int *flags)
{
static struct strbuf sb_refname = STRBUF_INIT;
int unused_flags;
int symref_count;
- struct ref_store *refs = get_ref_store(NULL);
if (!flags)
flags = &unused_flags;
for (symref_count = 0; symref_count < SYMREF_MAXDEPTH; symref_count++) {
unsigned int read_flags = 0;
- if (read_raw_ref(refs, refname,
- sha1, &sb_refname, &read_flags)) {
+ if (refs->be->read_raw_ref(refs, refname,
+ sha1, &sb_refname, &read_flags)) {
*flags |= read_flags;
if (errno != ENOENT || (resolve_flags & RESOLVE_REF_READING))
return NULL;
return NULL;
}
+/* backend functions */
+int refs_init_db(struct strbuf *err)
+{
+ struct ref_store *refs = get_ref_store(NULL);
+
+ return refs->be->init_db(refs, 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,
+ resolve_flags, sha1, flags);
+}
+
+int resolve_gitlink_ref(const char *submodule, const char *refname,
+ unsigned char *sha1)
+{
+ size_t len = strlen(submodule);
+ struct ref_store *refs;
+ int flags;
+
+ while (len && submodule[len - 1] == '/')
+ len--;
+
+ if (!len)
+ return -1;
+
+ if (submodule[len]) {
+ /* We need to strip off one or more trailing slashes */
+ char *stripped = xmemdupz(submodule, len);
+
+ refs = get_ref_store(stripped);
+ free(stripped);
+ } else {
+ refs = get_ref_store(submodule);
+ }
+
+ if (!refs)
+ return -1;
+
+ if (!resolve_ref_recursively(refs, refname, 0, sha1, &flags) ||
+ is_null_sha1(sha1))
+ return -1;
+ return 0;
+}
+
/* A pointer to the ref_store for the main repository: */
static struct ref_store *main_ref_store;
}
/* backend functions */
+int pack_refs(unsigned int flags)
+{
+ struct ref_store *refs = get_ref_store(NULL);
+
+ return refs->be->pack_refs(refs, flags);
+}
+
+int peel_ref(const char *refname, unsigned char *sha1)
+{
+ struct ref_store *refs = get_ref_store(NULL);
+
+ return refs->be->peel_ref(refs, refname, sha1);
+}
+
+int create_symref(const char *ref_target, const char *refs_heads_master,
+ const char *logmsg)
+{
+ struct ref_store *refs = get_ref_store(NULL);
+
+ return refs->be->create_symref(refs, ref_target, refs_heads_master,
+ logmsg);
+}
+
int ref_transaction_commit(struct ref_transaction *transaction,
struct strbuf *err)
{
return refs->be->transaction_commit(refs, transaction, err);
}
+
+int verify_refname_available(const char *refname,
+ const struct string_list *extra,
+ const struct string_list *skip,
+ struct strbuf *err)
+{
+ struct ref_store *refs = get_ref_store(NULL);
+
+ 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_iterator *iter;
+
+ iter = refs->be->reflog_iterator_begin(refs);
+
+ return do_for_each_ref_iterator(iter, fn, 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);
+
+ return refs->be->for_each_reflog_ent_reverse(refs, refname,
+ fn, cb_data);
+}
+
+int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn,
+ void *cb_data)
+{
+ struct ref_store *refs = get_ref_store(NULL);
+
+ 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);
+
+ return refs->be->reflog_exists(refs, refname);
+}
+
+int safe_create_reflog(const char *refname, int force_create,
+ struct strbuf *err)
+{
+ struct ref_store *refs = get_ref_store(NULL);
+
+ return refs->be->create_reflog(refs, refname, force_create, err);
+}
+
+int delete_reflog(const char *refname)
+{
+ struct ref_store *refs = get_ref_store(NULL);
+
+ return refs->be->delete_reflog(refs, refname);
+}
+
+int reflog_expire(const char *refname, const unsigned char *sha1,
+ unsigned int flags,
+ reflog_expiry_prepare_fn prepare_fn,
+ reflog_expiry_should_prune_fn should_prune_fn,
+ reflog_expiry_cleanup_fn cleanup_fn,
+ void *policy_cb_data)
+{
+ struct ref_store *refs = get_ref_store(NULL);
+
+ return refs->be->reflog_expire(refs, refname, sha1, flags,
+ prepare_fn, should_prune_fn,
+ cleanup_fn, policy_cb_data);
+}
+
+int initial_ref_transaction_commit(struct ref_transaction *transaction,
+ struct strbuf *err)
+{
+ struct ref_store *refs = get_ref_store(NULL);
+
+ 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);
+
+ 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);
+
+ return refs->be->rename_ref(refs, oldref, newref, logmsg);
+}