Subject: Re: [PATCH v2 18/43] refs-be-files.c: add a backend method structure with transaction functions

From: Michael Haggerty <[email-masked]>
Date: Mon, 05 Oct 2015 10:03:02 +0200

On 09/29/2015 12:01 AM, David Turner wrote:
> From: Ronnie Sahlberg <[email-masked]>
> 
> 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 <[email-masked]>
> Signed-off-by: David Turner <[email-masked]>
> ---
>  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 :-)

> +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
[email-masked]