Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/transaction.c')
-rw-r--r--src/transaction.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/transaction.c b/src/transaction.c
index e8331891c..e9639bf97 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -12,6 +12,7 @@
#include "pool.h"
#include "reflog.h"
#include "signature.h"
+#include "config.h"
#include "git2/transaction.h"
#include "git2/signature.h"
@@ -20,6 +21,12 @@
GIT__USE_STRMAP
+typedef enum {
+ TRANSACTION_NONE,
+ TRANSACTION_REFS,
+ TRANSACTION_CONFIG,
+} transaction_t;
+
typedef struct {
const char *name;
void *payload;
@@ -39,13 +46,29 @@ typedef struct {
} transaction_node;
struct git_transaction {
+ transaction_t type;
git_repository *repo;
git_refdb *db;
+ git_config *cfg;
git_strmap *locks;
git_pool pool;
};
+int git_transaction_config_new(git_transaction **out, git_config *cfg)
+{
+ git_transaction *tx;
+ assert(out && cfg);
+
+ tx = git__calloc(1, sizeof(git_transaction));
+ GITERR_CHECK_ALLOC(tx);
+
+ tx->type = TRANSACTION_CONFIG;
+ tx->cfg = cfg;
+ *out = tx;
+ return 0;
+}
+
int git_transaction_new(git_transaction **out, git_repository *repo)
{
int error;
@@ -71,6 +94,7 @@ int git_transaction_new(git_transaction **out, git_repository *repo)
if ((error = git_repository_refdb(&tx->db, repo)) < 0)
goto on_error;
+ tx->type = TRANSACTION_REFS;
memcpy(&tx->pool, &pool, sizeof(git_pool));
tx->repo = repo;
*out = tx;
@@ -305,6 +329,14 @@ int git_transaction_commit(git_transaction *tx)
assert(tx);
+ if (tx->type == TRANSACTION_CONFIG) {
+ error = git_config_unlock(tx->cfg, true);
+ git_config_free(tx->cfg);
+ tx->cfg = NULL;
+
+ return error;
+ }
+
for (pos = kh_begin(tx->locks); pos < kh_end(tx->locks); pos++) {
if (!git_strmap_has_data(tx->locks, pos))
continue;
@@ -332,6 +364,16 @@ void git_transaction_free(git_transaction *tx)
assert(tx);
+ if (tx->type == TRANSACTION_CONFIG) {
+ if (tx->cfg) {
+ git_config_unlock(tx->cfg, false);
+ git_config_free(tx->cfg);
+ }
+
+ git__free(tx);
+ return;
+ }
+
/* start by unlocking the ones we've left hanging, if any */
for (pos = kh_begin(tx->locks); pos < kh_end(tx->locks); pos++) {
if (!git_strmap_has_data(tx->locks, pos))