From b1bacdd8d58923859eb5b3f015a8f142c9420436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sun, 18 May 2014 11:03:30 +0200 Subject: [PATCH] Wrap config snapshot functions These allow complex reads to come from the same version of the config. --- pygit2/config.py | 13 +++++++++++++ pygit2/decl.h | 2 ++ pygit2/repository.py | 13 +++++++++++++ 3 files changed, 28 insertions(+) diff --git a/pygit2/config.py b/pygit2/config.py index 6bbe6d2..a757b97 100644 --- a/pygit2/config.py +++ b/pygit2/config.py @@ -223,6 +223,19 @@ class Config(object): err = C.git_config_add_file_ondisk(self._config, to_str(path), level, force) check_error(err) + def snapshot(self): + """Create a snapshot from this Config object + + This means that looking up multiple values will use the same version + of the configuration files + """ + + ccfg = ffi.new('git_config **') + err = C.git_config_snapshot(cfg, self._config) + check_error(err) + + return Config.from_c(self._repo, ccfg[0]) + # # Methods to parse a string according to the git-config rules # diff --git a/pygit2/decl.h b/pygit2/decl.h index a628f3b..b261472 100644 --- a/pygit2/decl.h +++ b/pygit2/decl.h @@ -255,6 +255,7 @@ typedef struct { } git_config_entry; int git_repository_config(git_config **out, git_repository *repo); +int git_repository_config_snapshot(git_config **out, git_repository *repo); void git_config_free(git_config *cfg); int git_config_get_string(const char **out, const git_config *cfg, const char *name); @@ -279,6 +280,7 @@ int git_config_multivar_iterator_new(git_config_iterator **out, const git_config int git_config_set_multivar(git_config *cfg, const char *name, const char *regexp, const char *value); int git_config_new(git_config **out); +int git_config_snapshot(git_config **out, git_config *config); int git_config_open_ondisk(git_config **out, const char *path); int git_config_find_system(git_buf *out); int git_config_find_global(git_buf *out); diff --git a/pygit2/repository.py b/pygit2/repository.py index 3f18c2c..db047f5 100644 --- a/pygit2/repository.py +++ b/pygit2/repository.py @@ -128,6 +128,19 @@ class Repository(_Repository): return Config.from_c(self, cconfig[0]) + @property + def config_snapshot(self): + """A snapshot for this repositiory's configuration + + This allows reads over multiple values to use the same version + of the configuration files""" + + cconfig = ffi.new('git_config **') + err = C.git_repository_config_snapshot(cconfig, self._repo) + check_error(err) + + return Config.from_c(self, cconfig[0]) + # # References #