diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2013-12-18 19:41:01 +0100 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2013-12-18 19:41:01 +0100 |
commit | cc098a7994a56a515311255ea7e4d0412b514879 (patch) | |
tree | 77760f362e42c07a32e06bb7ea3e7dea10d54890 | |
parent | a7ecd1a9e36df5d6843c1863542c02d777e9e8b5 (diff) | |
download | libgit2-cmn/ref-txn.tar.gz |
wipcmn/ref-txn
-rw-r--r-- | include/git2/refs.h | 10 | ||||
-rw-r--r-- | include/git2/sys/refdb_backend.h | 38 | ||||
-rw-r--r-- | include/git2/types.h | 3 |
3 files changed, 51 insertions, 0 deletions
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; |