refs: make read_raw_ref() virtual
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>
Michael Haggerty committed
Sep 4, 2016 at 18:08 UTC
e1e33b722c50c26546335fd5a709f89726c2ea2a
3 files changed
+29
-25
refs.c
+2
-2
@@ -1251,8 +1251,8 @@ static const char *resolve_ref_recursively(struct ref_store *refs,
1251
for (symref_count = 0; symref_count < SYMREF_MAXDEPTH; symref_count++) {
1252
unsigned int read_flags = 0;
1253
1254
- if (read_raw_ref(refs, refname,
1255
- sha1, &sb_refname, &read_flags)) {
1254
+ if (refs->be->read_raw_ref(refs, refname,
1255
+ sha1, &sb_refname, &read_flags)) {
1256
*flags |= read_flags;
1257
if (errno != ENOENT || (resolve_flags & RESOLVE_REF_READING))
1258
return NULL;
refs/files-backend.c
+8
-6
@@ -1349,9 +1349,9 @@ static int resolve_packed_ref(struct files_ref_store *refs,
1349
return -1;
1350
}
1351
1352
-int read_raw_ref(struct ref_store *ref_store,
1353
- const char *refname, unsigned char *sha1,
1354
- struct strbuf *referent, unsigned int *type)
1352
+static int files_read_raw_ref(struct ref_store *ref_store,
1353
+ const char *refname, unsigned char *sha1,
1354
+ struct strbuf *referent, unsigned int *type)
1355
{
1356
struct files_ref_store *refs =
1357
files_downcast(ref_store, 1, "read_raw_ref");
@@ -1623,8 +1623,8 @@ retry:
1623
* fear that its value will change.
1624
*/
1625
1626
- if (read_raw_ref(ref_store, refname,
1627
- lock->old_oid.hash, referent, type)) {
1626
+ if (files_read_raw_ref(ref_store, refname,
1627
+ lock->old_oid.hash, referent, type)) {
1628
if (errno == ENOENT) {
1629
if (mustexist) {
1630
/* Garden variety missing reference. */
@@ -4019,5 +4019,7 @@ struct ref_storage_be refs_be_files = {
4019
NULL,
4020
"files",
4021
files_ref_store_create,
4022
- files_transaction_commit
4022
+ files_transaction_commit,
4023
+
4024
+ files_read_raw_ref
4025
};
refs/refs-internal.h
+19
-17
@@ -486,6 +486,20 @@ int do_for_each_ref_iterator(struct ref_iterator *iter,
486
487
struct ref_store;
488
489
+/* refs backends */
490
+
491
+/*
492
+ * Initialize the ref_store for the specified submodule, or for the
493
+ * main repository if submodule == NULL. These functions should call
494
+ * base_ref_store_init() to initialize the shared part of the
495
+ * ref_store and to record the ref_store for later lookup.
496
+ */
497
+typedef struct ref_store *ref_store_init_fn(const char *submodule);
498
+
499
+typedef int ref_transaction_commit_fn(struct ref_store *refs,
500
+ struct ref_transaction *transaction,
501
+ struct strbuf *err);
502
+
503
/*
504
* Read a reference from the specified reference store, non-recursively.
505
* Set type to describe the reference, and:
@@ -524,29 +538,17 @@ struct ref_store;
538
* - in all other cases, referent will be untouched, and therefore
539
* refname will still be valid and unchanged.
540
*/
527
-int read_raw_ref(struct ref_store *ref_store,
528
- const char *refname, unsigned char *sha1,
529
- struct strbuf *referent, unsigned int *type);
530
-
531
-/* refs backends */
532
-
533
-/*
534
- * Initialize the ref_store for the specified submodule, or for the
535
- * main repository if submodule == NULL. These functions should call
536
- * base_ref_store_init() to initialize the shared part of the
537
- * ref_store and to record the ref_store for later lookup.
538
- */
539
-typedef struct ref_store *ref_store_init_fn(const char *submodule);
540
-
541
-typedef int ref_transaction_commit_fn(struct ref_store *refs,
542
- struct ref_transaction *transaction,
543
- struct strbuf *err);
541
+typedef int read_raw_ref_fn(struct ref_store *ref_store,
542
+ const char *refname, unsigned char *sha1,
543
+ struct strbuf *referent, unsigned int *type);
544
545
struct ref_storage_be {
546
struct ref_storage_be *next;
547
const char *name;
548
ref_store_init_fn *init;
549
ref_transaction_commit_fn *transaction_commit;
550
+
551
+ read_raw_ref_fn *read_raw_ref;
552
};
553
554
extern struct ref_storage_be refs_be_files;