summaryrefslogtreecommitdiff
path: root/include/git2
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-06-28 06:39:38 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2014-09-30 15:44:32 +0200
commitab8d9242f54e2c570f86a45a509b9420911a4d44 (patch)
tree6070f721e7e93982a0fe37882e5700de5c1186a9 /include/git2
parentbdeb8772fe846eeeea92cb2d9adb85315f3b8417 (diff)
downloadlibgit2-ab8d9242f54e2c570f86a45a509b9420911a4d44.tar.gz
Introduce reference transactions
A transaction allows you to lock multiple references and set up changes for them before applying the changes all at once (or as close as the backend supports). This can be used for replication purposes, or for making sure some operations run when the reference is locked and thus cannot be changed.
Diffstat (limited to 'include/git2')
-rw-r--r--include/git2/sys/refdb_backend.h13
-rw-r--r--include/git2/transaction.h25
-rw-r--r--include/git2/types.h3
3 files changed, 41 insertions, 0 deletions
diff --git a/include/git2/sys/refdb_backend.h b/include/git2/sys/refdb_backend.h
index 3b216a287..d943e550f 100644
--- a/include/git2/sys/refdb_backend.h
+++ b/include/git2/sys/refdb_backend.h
@@ -153,6 +153,19 @@ struct git_refdb_backend {
* Remove a reflog.
*/
int (*reflog_delete)(git_refdb_backend *backend, const char *name);
+
+ /**
+ * Lock a reference. The opaque parameter will be passed to the unlock function
+ */
+ int (*lock)(void **payload_out, git_refdb_backend *backend, const char *refname);
+
+ /**
+ * Unlock a reference. Only one of target or symbolic_target
+ * will be set. success indicates whether to update the
+ * reference or discard the lock (if it's false)
+ */
+ int (*unlock)(git_refdb_backend *backend, void *payload, int success, int update_reflog,
+ const git_reference *ref, const git_signature *sig, const char *message);
};
#define GIT_REFDB_BACKEND_VERSION 1
diff --git a/include/git2/transaction.h b/include/git2/transaction.h
new file mode 100644
index 000000000..46f4cfba0
--- /dev/null
+++ b/include/git2/transaction.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_git_transaction_h__
+#define INCLUDE_git_transaction_h__
+
+#include "common.h"
+GIT_BEGIN_DECL
+
+GIT_EXTERN(int) git_transaction_new(git_transaction **out, git_repository *repo);
+GIT_EXTERN(int) git_transaction_lock(git_transaction *tx, const char *refname);
+GIT_EXTERN(int) git_transaction_set_target(git_transaction *tx, const char *refname, const git_oid *target, const git_signature *sig, const char *msg);
+
+GIT_EXTERN(int) git_transaction_set_symbolic_target(git_transaction *tx, const char *refname, const char *target, const git_signature *sig, const char *msg);
+GIT_EXTERN(int) git_transaction_set_reflog(git_transaction *tx, const char *refname, const git_reflog *reflog);
+GIT_EXTERN(int) git_transaction_commit(git_transaction *tx);
+GIT_EXTERN(void) git_transaction_free(git_transaction *tx);
+GIT_EXTERN(int) git_transaction_remove(git_transaction *tx, const char *refname);
+
+
+GIT_END_DECL
+#endif
diff --git a/include/git2/types.h b/include/git2/types.h
index 7ee7cc344..14b7071d2 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;
+/** Transactional interface to references */
+typedef struct git_transaction git_transaction;
+
/** Merge heads, the input to merge */
typedef struct git_merge_head git_merge_head;