Re: [PATCH v2 18/43] refs-be-files.c: add a backend method structure with transaction functions
- From
Michael Haggerty <mhagger@alum.mit.edu>
- Date
- Oct 5, 2015, 08:03 UTC
- Message-ID
- <56122EB6.2020501@alum.mit.edu>
- In-Reply-To
- <1443477738-32023-19-git-send-email-dturner@twopensource.com>
On 09/29/2015 12:01 AM, David Turner wrote:
Show 27 quoted lines
> From: Ronnie Sahlberg <sahlberg@google.com> > > Add a ref structure for backend methods. Start by adding method pointers > for the transaction functions. > > Add a function set_refs_backend to switch between backends. The files > based backend is the default. > > Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> > Signed-off-by: David Turner <dturner@twopensource.com> > --- > refs-be-files.c | 62 +++++++++++++++++++++++++++------------------- > refs.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > refs.h | 36 +++++++++++++++++++++++++++ > 3 files changed, 150 insertions(+), 25 deletions(-) > > [...] > diff --git a/refs.h b/refs.h > index 729bc3c..a1db3ef 100644 > --- a/refs.h > +++ b/refs.h > @@ -530,4 +530,40 @@ extern int reflog_expire(const char *refname, const unsigned char *sha1, > reflog_expiry_cleanup_fn cleanup_fn, > void *policy_cb_data); > > +/* refs backends */ > +typedef struct ref_transaction *(*ref_transaction_begin_fn)(struct strbuf *err);
Hmmm, I thought our convention was to define typedefs for functions themselves, not for the pointer-to-function; e.g.,
typedef struct ref_transaction *ref_transaction_begin_fn(struct strbuf *err);
(which would require `struct ref_be` to be changed to
ref_transaction_begin_fn *transaction_begin;
etc.) But now as I grep through the code it looks like both conventions are used. So never mind :-)
Show 36 quoted lines
> +typedef int (*ref_transaction_update_fn)(struct ref_transaction *transaction,
> + const char *refname, const unsigned char *new_sha1,
> + const unsigned char *old_sha1, unsigned int flags,
> + const char *msg, struct strbuf *err);
> +typedef int (*ref_transaction_create_fn)(
> + struct ref_transaction *transaction,
> + const char *refname, const unsigned char *new_sha1,
> + unsigned int flags, const char *msg, struct strbuf *err);
> +typedef int (*ref_transaction_delete_fn)(struct ref_transaction *transaction,
> + const char *refname, const unsigned char *old_sha1,
> + unsigned int flags, const char *msg, struct strbuf *err);
> +typedef int (*ref_transaction_verify_fn)(struct ref_transaction *transaction,
> + const char *refname, const unsigned char *old_sha1,
> + unsigned int flags, struct strbuf *err);
> +typedef int (*ref_transaction_commit_fn)(struct ref_transaction *transaction,
> + struct strbuf *err);
> +typedef void (*ref_transaction_free_fn)(struct ref_transaction *transaction);
> +
> +struct ref_be {
> + struct ref_be *next;
> + const char *name;
> + ref_transaction_begin_fn transaction_begin;
> + ref_transaction_update_fn transaction_update;
> + ref_transaction_create_fn transaction_create;
> + ref_transaction_delete_fn transaction_delete;
> + ref_transaction_verify_fn transaction_verify;
> + ref_transaction_commit_fn transaction_commit;
> + ref_transaction_free_fn transaction_free;
> +};
> +
> +
> +extern struct ref_be refs_be_files;
> +int set_refs_backend(const char *name);
> +
> #endif /* REFS_H */
> Michael
-- Michael Haggerty mhagger@alum.mit.edu