summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-05-12 10:04:52 -0700
committerRussell Belfer <rb@github.com>2014-05-12 10:04:52 -0700
commitd2c4d1c63d9d5456fcf2cdcd578073d9e7dadc2a (patch)
tree70b0341e6e5d4898e8b332b658cc0fb2b29a6271 /include
parente18d5e52e385c0cc2ad8d9d4fdd545517f170a11 (diff)
parentac99d86ba5e2a9d2332b7f82737e1231c621dc43 (diff)
downloadlibgit2-d2c4d1c63d9d5456fcf2cdcd578073d9e7dadc2a.tar.gz
Merge pull request #2188 from libgit2/cmn/config-snapshot
Configuration snapshotting
Diffstat (limited to 'include')
-rw-r--r--include/git2/config.h28
-rw-r--r--include/git2/repository.h14
-rw-r--r--include/git2/sys/config.h4
3 files changed, 43 insertions, 3 deletions
diff --git a/include/git2/config.h b/include/git2/config.h
index 663b4f6ba..21a5825a5 100644
--- a/include/git2/config.h
+++ b/include/git2/config.h
@@ -226,6 +226,22 @@ GIT_EXTERN(int) git_config_open_level(
*/
GIT_EXTERN(int) git_config_open_global(git_config **out, git_config *config);
+/**
+ * Create a snapshot of the configuration
+ *
+ * Create a snapshot of the current state of a configuration, which
+ * allows you to look into a consistent view of the configuration for
+ * looking up complex values (e.g. a remote, submodule).
+ *
+ * The string returned when querying such a config object is valid
+ * until it is freed.
+ *
+ * @param out pointer in which to store the snapshot config object
+ * @param config configuration to snapshot
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_config_snapshot(git_config **out, git_config *config);
+
/**
* Reload changed config files
@@ -312,7 +328,8 @@ GIT_EXTERN(int) git_config_get_bool(int *out, const git_config *cfg, const char
* Get the value of a string config variable.
*
* The string is owned by the variable and should not be freed by the
- * user.
+ * user. The pointer will be valid until the next operation on this
+ * config object.
*
* All config files will be looked into, in the order of their
* defined level. A higher level means a higher priority. The
@@ -353,6 +370,9 @@ GIT_EXTERN(int) git_config_multivar_iterator_new(git_config_iterator **out, cons
/**
* Return the current entry and advance the iterator
*
+ * The pointers returned by this function are valid until the iterator
+ * is freed.
+ *
* @param entry pointer to store the entry
* @param iter the iterator
* @return 0 or an error code. GIT_ITEROVER if the iteration has completed
@@ -451,6 +471,9 @@ GIT_EXTERN(int) git_config_delete_multivar(git_config *cfg, const char *name, co
* If the callback returns a non-zero value, the function stops iterating
* and returns that value to the caller.
*
+ * The pointers passed to the callback are only valid as long as the
+ * iteration is ongoing.
+ *
* @param cfg where to get the variables from
* @param callback the function to call on each variable
* @param payload the data to pass to the callback
@@ -491,6 +514,9 @@ GIT_EXTERN(int) git_config_iterator_glob_new(git_config_iterator **out, const gi
* regular expression that filters which config keys are passed to the
* callback.
*
+ * The pointers passed to the callback are only valid as long as the
+ * iteration is ongoing.
+ *
* @param cfg where to get the variables from
* @param regexp regular expression to match against config names
* @param callback the function to call on each variable
diff --git a/include/git2/repository.h b/include/git2/repository.h
index 04df25fd3..0f7119b76 100644
--- a/include/git2/repository.h
+++ b/include/git2/repository.h
@@ -408,13 +408,25 @@ GIT_EXTERN(int) git_repository_is_bare(git_repository *repo);
* The configuration file must be freed once it's no longer
* being used by the user.
*
- * @param out Pointer to store the loaded config file
+ * @param out Pointer to store the loaded configuration
* @param repo A repository object
* @return 0, or an error code
*/
GIT_EXTERN(int) git_repository_config(git_config **out, git_repository *repo);
/**
+ * Get a snapshot of the repository's configuration
+ *
+ * Convenience function to take a snapshot from the repository's
+ * configuration.
+ *
+ * @param out Pointer to store the loaded configuration
+ * @param repo the repository
+ * @return 0, or an error code
+ */
+GIT_EXTERN(int) git_repository_config_snapshot(git_config **out, git_repository *repo);
+
+/**
* Get the Object Database for this repository.
*
* If a custom ODB has not been set, the default
diff --git a/include/git2/sys/config.h b/include/git2/sys/config.h
index 46bb65293..85e0d6417 100644
--- a/include/git2/sys/config.h
+++ b/include/git2/sys/config.h
@@ -57,13 +57,15 @@ struct git_config_backend {
/* Open means open the file/database and parse if necessary */
int (*open)(struct git_config_backend *, git_config_level_t level);
- int (*get)(const struct git_config_backend *, const char *key, const git_config_entry **entry);
+ int (*get)(struct git_config_backend *, const char *key, const git_config_entry **entry);
int (*set)(struct git_config_backend *, const char *key, const char *value);
int (*set_multivar)(git_config_backend *cfg, const char *name, const char *regexp, const char *value);
int (*del)(struct git_config_backend *, const char *key);
int (*del_multivar)(struct git_config_backend *, const char *key, const char *regexp);
int (*iterator)(git_config_iterator **, struct git_config_backend *);
int (*refresh)(struct git_config_backend *);
+ /** Produce a read-only version of this backend */
+ int (*snapshot)(struct git_config_backend **, struct git_config_backend *);
void (*free)(struct git_config_backend *);
};
#define GIT_CONFIG_BACKEND_VERSION 1