Re: [PATCH v3 19/44] refs-be-files.c: add a backend method structure with transaction functions
On 10/12/2015 11:51 PM, David Turner wrote: > From: Ronnie Sahlberg> > Add a ref structure for backend methods. Start by adding a method pointer > for the transaction commit function. > > Add a function set_refs_backend to switch between backends. The files > based backend is the default. > > Signed-off-by: Ronnie Sahlberg > Signed-off-by: David Turner > --- > refs-be-files.c | 10 -- > refs.c | 30 ++ > refs.h | 15 +++ > 3 files changed, 53 insertions(+), 2 deletions(-) > > [...] > diff --git a/refs.h b/refs.h > index 4940ae9..419abf4 100644 > --- a/refs.h > +++ b/refs.h > @@ -619,4 +619,19 @@ extern int reflog_expire(const char *refname, const > unsigned char *sha1, >reflog_expiry_cleanup_fn cleanup_fn, >void *policy_cb_data); > > +/* refs backends */ > +typedef int ref_transaction_commit_fn(struct ref_transaction *transaction, > + struct strbuf *err); > +typedef void ref_transaction_free_fn(struct ref_transaction *transaction); The ref_transaction_free_fn typedef isn't used anywhere. > +struct ref_be { > + struct ref_be *next; > + const char *name; > + ref_transaction_commit_fn *transaction_commit; > +}; > + > + > +extern struct ref_be refs_be_files; I don't think that refs_be_files is needed in the public interface. > +int set_refs_backend(const char *name); > + > #endif /* REFS_H */ Michael -- Michael Haggerty mhag...@alum.mit.edu -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 19/44] refs-be-files.c: add a backend method structure with transaction functions
On Tue, 2015-10-13 at 09:56 +0200, Michael Haggerty wrote: > On 10/12/2015 11:51 PM, David Turner wrote: > > From: Ronnie Sahlberg> > > > Add a ref structure for backend methods. Start by adding a method pointer > > for the transaction commit function. > > > > Add a function set_refs_backend to switch between backends. The files > > based backend is the default. > > > > Signed-off-by: Ronnie Sahlberg > > Signed-off-by: David Turner > > --- > > refs-be-files.c | 10 -- > > refs.c | 30 ++ > > refs.h | 15 +++ > > 3 files changed, 53 insertions(+), 2 deletions(-) > > > > [...] > > diff --git a/refs.h b/refs.h > > index 4940ae9..419abf4 100644 > > --- a/refs.h > > +++ b/refs.h > > @@ -619,4 +619,19 @@ extern int reflog_expire(const char *refname, const > > unsigned char *sha1, > > reflog_expiry_cleanup_fn cleanup_fn, > > void *policy_cb_data); > > > > +/* refs backends */ > > +typedef int ref_transaction_commit_fn(struct ref_transaction *transaction, > > + struct strbuf *err); > > +typedef void ref_transaction_free_fn(struct ref_transaction *transaction); > > The ref_transaction_free_fn typedef isn't used anywhere. Will fix, thanks. > > +struct ref_be { > > + struct ref_be *next; > > + const char *name; > > + ref_transaction_commit_fn *transaction_commit; > > +}; > > + > > + > > +extern struct ref_be refs_be_files; > > I don't think that refs_be_files is needed in the public interface. We use refs_be_lmdb in a few other places to set up the lmdb backend, so I thought I would put refs_be_files in refs.h too. But I can remove refs_be_files and just stick it in the places it's needed. -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 19/44] refs-be-files.c: add a backend method structure with transaction functions
On 10/13/2015 08:28 PM, David Turner wrote: > On Tue, 2015-10-13 at 09:56 +0200, Michael Haggerty wrote: >> On 10/12/2015 11:51 PM, David Turner wrote: >>> [...] >>> +extern struct ref_be refs_be_files; >> >> I don't think that refs_be_files is needed in the public interface. > > We use refs_be_lmdb in a few other places to set up the lmdb backend, so > I thought I would put refs_be_files in refs.h too. But I can remove > refs_be_files and just stick it in the places it's needed. It's OK then. It doesn't hurt to leave it for consistency's sake. Michael -- Michael Haggerty mhag...@alum.mit.edu -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3 19/44] refs-be-files.c: add a backend method structure with transaction functions
From: Ronnie SahlbergAdd a ref structure for backend methods. Start by adding a method pointer for the transaction commit function. Add a function set_refs_backend to switch between backends. The files based backend is the default. Signed-off-by: Ronnie Sahlberg Signed-off-by: David Turner --- refs-be-files.c | 10 -- refs.c | 30 ++ refs.h | 15 +++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/refs-be-files.c b/refs-be-files.c index 1308955..3050f1d 100644 --- a/refs-be-files.c +++ b/refs-be-files.c @@ -3225,8 +3225,8 @@ static int ref_update_reject_duplicates(struct string_list *refnames, return 0; } -int ref_transaction_commit(struct ref_transaction *transaction, - struct strbuf *err) +static int files_transaction_commit(struct ref_transaction *transaction, + struct strbuf *err) { int ret = 0, i; int n = transaction->nr; @@ -3612,3 +3612,9 @@ int reflog_expire(const char *refname, const unsigned char *sha1, unlock_ref(lock); return -1; } + +struct ref_be refs_be_files = { + NULL, + "files", + files_transaction_commit, +}; diff --git a/refs.c b/refs.c index 25ad3b5..f930fe0 100644 --- a/refs.c +++ b/refs.c @@ -4,6 +4,29 @@ #include "cache.h" #include "refs.h" #include "lockfile.h" +/* + * We always have a files backend and it is the default. + */ +struct ref_be *the_refs_backend = _be_files; +/* + * List of all available backends + */ +struct ref_be *refs_backends = _be_files; + +/* + * This function is used to switch to an alternate backend. + */ +int set_refs_backend(const char *name) +{ + struct ref_be *be; + + for (be = refs_backends; be; be = be->next) + if (!strcmp(be->name, name)) { + the_refs_backend = be; + return 0; + } + return 1; +} static int is_per_worktree_ref(const char *refname) { @@ -985,3 +1008,10 @@ int ref_transaction_verify(struct ref_transaction *transaction, NULL, old_sha1, flags, NULL, err); } + +/* backend functions */ +int ref_transaction_commit(struct ref_transaction *transaction, + struct strbuf *err) +{ + return the_refs_backend->transaction_commit(transaction, err); +} diff --git a/refs.h b/refs.h index 4940ae9..419abf4 100644 --- a/refs.h +++ b/refs.h @@ -619,4 +619,19 @@ extern int reflog_expire(const char *refname, const unsigned char *sha1, reflog_expiry_cleanup_fn cleanup_fn, void *policy_cb_data); +/* refs backends */ +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_commit_fn *transaction_commit; +}; + + +extern struct ref_be refs_be_files; +int set_refs_backend(const char *name); + #endif /* REFS_H */ -- 2.4.2.644.g97b850b-twtrsrc -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 19/44] refs-be-files.c: add a backend method structure with transaction functions
Please disregard this one; I rewrorded the commit message and forgot to delete this patch. On Mon, 2015-10-12 at 17:51 -0400, David Turner wrote: > From: Ronnie Sahlberg> > Add a ref structure for backend methods. Start by adding a method pointer > for the transaction commit function. > > Add a function set_refs_backend to switch between backends. The files > based backend is the default. > > Signed-off-by: Ronnie Sahlberg > Signed-off-by: David Turner > --- > refs-be-files.c | 10 -- > refs.c | 30 ++ > refs.h | 15 +++ > 3 files changed, 53 insertions(+), 2 deletions(-) > > diff --git a/refs-be-files.c b/refs-be-files.c > index 1308955..3050f1d 100644 > --- a/refs-be-files.c > +++ b/refs-be-files.c > @@ -3225,8 +3225,8 @@ static int ref_update_reject_duplicates(struct > string_list *refnames, > return 0; > } > > -int ref_transaction_commit(struct ref_transaction *transaction, > -struct strbuf *err) > +static int files_transaction_commit(struct ref_transaction *transaction, > + struct strbuf *err) > { > int ret = 0, i; > int n = transaction->nr; > @@ -3612,3 +3612,9 @@ int reflog_expire(const char *refname, const unsigned > char *sha1, > unlock_ref(lock); > return -1; > } > + > +struct ref_be refs_be_files = { > + NULL, > + "files", > + files_transaction_commit, > +}; > diff --git a/refs.c b/refs.c > index 25ad3b5..f930fe0 100644 > --- a/refs.c > +++ b/refs.c > @@ -4,6 +4,29 @@ > #include "cache.h" > #include "refs.h" > #include "lockfile.h" > +/* > + * We always have a files backend and it is the default. > + */ > +struct ref_be *the_refs_backend = _be_files; > +/* > + * List of all available backends > + */ > +struct ref_be *refs_backends = _be_files; > + > +/* > + * This function is used to switch to an alternate backend. > + */ > +int set_refs_backend(const char *name) > +{ > + struct ref_be *be; > + > + for (be = refs_backends; be; be = be->next) > + if (!strcmp(be->name, name)) { > + the_refs_backend = be; > + return 0; > + } > + return 1; > +} > > static int is_per_worktree_ref(const char *refname) > { > @@ -985,3 +1008,10 @@ int ref_transaction_verify(struct ref_transaction > *transaction, > NULL, old_sha1, > flags, NULL, err); > } > + > +/* backend functions */ > +int ref_transaction_commit(struct ref_transaction *transaction, > +struct strbuf *err) > +{ > + return the_refs_backend->transaction_commit(transaction, err); > +} > diff --git a/refs.h b/refs.h > index 4940ae9..419abf4 100644 > --- a/refs.h > +++ b/refs.h > @@ -619,4 +619,19 @@ extern int reflog_expire(const char *refname, const > unsigned char *sha1, >reflog_expiry_cleanup_fn cleanup_fn, >void *policy_cb_data); > > +/* refs backends */ > +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_commit_fn *transaction_commit; > +}; > + > + > +extern struct ref_be refs_be_files; > +int set_refs_backend(const char *name); > + > #endif /* REFS_H */ -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html