summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-06-01 20:02:23 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2015-08-12 04:09:38 +0200
commit36f784b538c4b27f7b52427d2cfce06c535abba0 (patch)
treecea0d9dd8e9807e30583ba54c5aa2e58c6c14fe2 /src
parentb1667039640ba3464ea0e2d13ad28c9244d80b4d (diff)
downloadlibgit2-36f784b538c4b27f7b52427d2cfce06c535abba0.tar.gz
config: expose locking via the main API
This lock/unlock pair allows for the cller to lock a configuration file to avoid concurrent operations. It also allows for a transactional approach to updating a configuration file. If multiple updates must be made atomically, they can be done while the config is locked.
Diffstat (limited to 'src')
-rw-r--r--src/config.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c
index 77cf573e6..937d00dcb 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1144,6 +1144,37 @@ int git_config_open_default(git_config **out)
return error;
}
+int git_config_lock(git_config *cfg)
+{
+ git_config_backend *file;
+ file_internal *internal;
+
+ internal = git_vector_get(&cfg->files, 0);
+ if (!internal || !internal->file) {
+ giterr_set(GITERR_CONFIG, "cannot lock; the config has no backends/files");
+ return -1;
+ }
+ file = internal->file;
+
+ return file->lock(file);
+}
+
+int git_config_unlock(git_config *cfg, int commit)
+{
+ git_config_backend *file;
+ file_internal *internal;
+
+ internal = git_vector_get(&cfg->files, 0);
+ if (!internal || !internal->file) {
+ giterr_set(GITERR_CONFIG, "cannot lock; the config has no backends/files");
+ return -1;
+ }
+
+ file = internal->file;
+
+ return file->unlock(file, commit);
+}
+
/***********
* Parsers
***********/