From cc098a7994a56a515311255ea7e4d0412b514879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 18 Dec 2013 19:41:01 +0100 Subject: wip --- include/git2/refs.h | 10 ++++++++++ include/git2/sys/refdb_backend.h | 38 ++++++++++++++++++++++++++++++++++++++ include/git2/types.h | 3 +++ 3 files changed, 51 insertions(+) diff --git a/include/git2/refs.h b/include/git2/refs.h index e2bfa9615..79cfcb3e3 100644 --- a/include/git2/refs.h +++ b/include/git2/refs.h @@ -569,6 +569,16 @@ GIT_EXTERN(int) git_reference_is_valid_name(const char *refname); */ GIT_EXTERN(const char *) git_reference_shorthand(git_reference *ref); +/** + * Start a new transaction for the specified reference + * + * Lock the reference and return a transaction that can be used to + * modify the reference under lock. You must either commit or rollback + * the transaction, or it will remain locked. + */ +GIT_EXTERN(int) git_reference_transaction_new(git_reference_transaction **out, git_repository *repo, const char *name); + +GIT_EXTERN(int) git_reference_transaction_set_reference((git_reference_transaction *txn, git_reference *ref); /** @} */ GIT_END_DECL diff --git a/include/git2/sys/refdb_backend.h b/include/git2/sys/refdb_backend.h index 9cf5073fb..c61b9d642 100644 --- a/include/git2/sys/refdb_backend.h +++ b/include/git2/sys/refdb_backend.h @@ -56,6 +56,34 @@ struct git_reference_iterator { git_reference_iterator *iter); }; +/** + * A transaction for a single reference + * + * Any function returning a transaction must set the ref and (if + * available) reflog pointers. + */ +struct git_reference_transaction { + git_refdb *db; + + git_reference *ref; + git_reflog *reflog; + + /** + * Apply the changes to the backend + */ + int (*commit)(git_reference_transaction *txn); + + /** + * Ignore any changes made in the transaction. + */ + int (*rollback)(git_reference_transaction *txn); + + /** + * Free the transaction + */ + void (*free)(git_reference_transaction *txn); +} + /** An instance for a custom backend */ struct git_refdb_backend { unsigned int version; @@ -139,6 +167,16 @@ struct git_refdb_backend { * Remove a reflog. */ int (*reflog_delete)(git_refdb_backend *backend, const char *name); + + /** + * Create a new transaction + */ + int (*transaction_new)(git_reference_transaction *out, git_refdb_backend *backend, const char *name); + + /** + * Commit the changes made in a transaction + */ + int (*transaction_commit)(git_refdb_backend *backend, git_reference_transaction *txn); }; #define GIT_REFDB_BACKEND_VERSION 1 diff --git a/include/git2/types.h b/include/git2/types.h index 55505b110..e35b3f64d 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -171,6 +171,9 @@ typedef struct git_reference git_reference; /** Iterator for references */ typedef struct git_reference_iterator git_reference_iterator; +/** Transaction on a single reference */ +typedef struct git_reference_transaction git_reference_transaction; + /** Merge heads, the input to merge */ typedef struct git_merge_head git_merge_head; -- cgit v1.2.1