refs: add a backend method structure

Add a `struct ref_storage_be` to represent types of reference stores. In OO notation, this is the class, and will soon hold some class methods (e.g., a factory to create new ref_store instances) and will also serve as the vtable for ref_store instances of that type. As yet, the backends cannot do anything. Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ronnie Sahlberg committed Sep 4, 2016 at 18:08 UTC 3dce444f178503bf3da13ade6f79c80d6964d175
4 files changed +34
refs.c
+19
@@ -9,6 +9,25 @@
9 #include "object.h"
10 #include "tag.h"
11
12 +/*
13 + * List of all available backends
14 + */
15 +static struct ref_storage_be *refs_backends = &refs_be_files;
16 +
17 +static struct ref_storage_be *find_ref_storage_backend(const char *name)
18 +{
19 + struct ref_storage_be *be;
20 + for (be = refs_backends; be; be = be->next)
21 + if (!strcmp(be->name, name))
22 + return be;
23 + return NULL;
24 +}
25 +
26 +int ref_storage_backend_exists(const char *name)
27 +{
28 + return find_ref_storage_backend(name) != NULL;
29 +}
30 +
31 /*
32 * How to handle various characters in refnames:
33 * 0: An acceptable character for refs
refs.h
+2
@@ -544,4 +544,6 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
544 reflog_expiry_cleanup_fn cleanup_fn,
545 void *policy_cb_data);
546
547 +int ref_storage_backend_exists(const char *name);
548 +
549 #endif /* REFS_H */
refs/files-backend.c
+5
@@ -4066,3 +4066,8 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
4066 unlock_ref(lock);
4067 return -1;
4068 }
4069 +
4070 +struct ref_storage_be refs_be_files = {
4071 + NULL,
4072 + "files"
4073 +};
refs/refs-internal.h
+8
@@ -525,4 +525,12 @@ int do_for_each_ref_iterator(struct ref_iterator *iter,
525 int read_raw_ref(const char *refname, unsigned char *sha1,
526 struct strbuf *referent, unsigned int *type);
527
528 +/* refs backends */
529 +struct ref_storage_be {
530 + struct ref_storage_be *next;
531 + const char *name;
532 +};
533 +
534 +extern struct ref_storage_be refs_be_files;
535 +
536 #endif /* REFS_REFS_INTERNAL_H */