refs: make read_raw_ref() virtual
authorMichael Haggerty <mhagger@alum.mit.edu>
Sun, 4 Sep 2016 16:08:25 +0000 (18:08 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 9 Sep 2016 22:28:13 +0000 (15:28 -0700)
Reference backends will be able to customize this function to implement
reference reading.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c
refs/files-backend.c
refs/refs-internal.h
diff --git a/refs.c b/refs.c
index 1a2a2bbbe775618a77919c93eb304f1445e09eee..775c54eb476ec31ac8857c5704a8d072daf94b75 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1251,8 +1251,8 @@ static const char *resolve_ref_recursively(struct ref_store *refs,
        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;
index 979cee884a5b233a0a4168f1133c0b9e3cc765d4..9cf2f82f748a416d0a0bca9d5a39c28b4ec3e2f7 100644 (file)
@@ -1349,9 +1349,9 @@ static int resolve_packed_ref(struct files_ref_store *refs,
        return -1;
 }
 
-int read_raw_ref(struct ref_store *ref_store,
-                const char *refname, unsigned char *sha1,
-                struct strbuf *referent, unsigned int *type)
+static int files_read_raw_ref(struct ref_store *ref_store,
+                             const char *refname, unsigned char *sha1,
+                             struct strbuf *referent, unsigned int *type)
 {
        struct files_ref_store *refs =
                files_downcast(ref_store, 1, "read_raw_ref");
@@ -1623,8 +1623,8 @@ static int lock_raw_ref(const char *refname, int mustexist,
         * fear that its value will change.
         */
 
-       if (read_raw_ref(ref_store, refname,
-                        lock->old_oid.hash, referent, type)) {
+       if (files_read_raw_ref(ref_store, refname,
+                              lock->old_oid.hash, referent, type)) {
                if (errno == ENOENT) {
                        if (mustexist) {
                                /* Garden variety missing reference. */
@@ -4019,5 +4019,7 @@ struct ref_storage_be refs_be_files = {
        NULL,
        "files",
        files_ref_store_create,
-       files_transaction_commit
+       files_transaction_commit,
+
+       files_read_raw_ref
 };
index fa41d510c209a093178f12a35cc86a2bcbde6ea8..19cb6e11ad231560400a448838c60ff8ad1669a4 100644 (file)
@@ -486,6 +486,20 @@ int do_for_each_ref_iterator(struct ref_iterator *iter,
 
 struct ref_store;
 
+/* refs backends */
+
+/*
+ * Initialize the ref_store for the specified submodule, or for the
+ * main repository if submodule == NULL. These functions should call
+ * base_ref_store_init() to initialize the shared part of the
+ * ref_store and to record the ref_store for later lookup.
+ */
+typedef struct ref_store *ref_store_init_fn(const char *submodule);
+
+typedef int ref_transaction_commit_fn(struct ref_store *refs,
+                                     struct ref_transaction *transaction,
+                                     struct strbuf *err);
+
 /*
  * Read a reference from the specified reference store, non-recursively.
  * Set type to describe the reference, and:
@@ -524,29 +538,17 @@ struct ref_store;
  * - in all other cases, referent will be untouched, and therefore
  *   refname will still be valid and unchanged.
  */
-int read_raw_ref(struct ref_store *ref_store,
-                const char *refname, unsigned char *sha1,
-                struct strbuf *referent, unsigned int *type);
-
-/* refs backends */
-
-/*
- * Initialize the ref_store for the specified submodule, or for the
- * main repository if submodule == NULL. These functions should call
- * base_ref_store_init() to initialize the shared part of the
- * ref_store and to record the ref_store for later lookup.
- */
-typedef struct ref_store *ref_store_init_fn(const char *submodule);
-
-typedef int ref_transaction_commit_fn(struct ref_store *refs,
-                                     struct ref_transaction *transaction,
-                                     struct strbuf *err);
+typedef int read_raw_ref_fn(struct ref_store *ref_store,
+                           const char *refname, unsigned char *sha1,
+                           struct strbuf *referent, unsigned int *type);
 
 struct ref_storage_be {
        struct ref_storage_be *next;
        const char *name;
        ref_store_init_fn *init;
        ref_transaction_commit_fn *transaction_commit;
+
+       read_raw_ref_fn *read_raw_ref;
 };
 
 extern struct ref_storage_be refs_be_files;