summaryrefslogtreecommitdiff
path: root/cache.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-03-20 06:16:07 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-03-20 06:16:07 (GMT)
commit6b5688b760a11430586122173d96b15fd3204308 (patch)
treeddb27de68f656862e068bb51b97967c3afea6b31 /cache.h
parent83b13e284ce3e349aedfc48fc0fb885c390bb18b (diff)
parente8805af1c33d79750a979014c021cd63d780c720 (diff)
downloadgit-6b5688b760a11430586122173d96b15fd3204308.zip
git-6b5688b760a11430586122173d96b15fd3204308.tar.gz
git-6b5688b760a11430586122173d96b15fd3204308.tar.bz2
Merge branch 'ma/clear-repository-format'
The setup code has been cleaned up to avoid leaks around the repository_format structure. * ma/clear-repository-format: setup: fix memory leaks with `struct repository_format` setup: free old value before setting `work_tree`
Diffstat (limited to 'cache.h')
-rw-r--r--cache.h31
1 files changed, 28 insertions, 3 deletions
diff --git a/cache.h b/cache.h
index abd518a..ac92421 100644
--- a/cache.h
+++ b/cache.h
@@ -962,6 +962,10 @@ extern char *repository_format_partial_clone;
extern const char *core_partial_clone_filter_default;
extern int repository_format_worktree_config;
+/*
+ * You _have_ to initialize a `struct repository_format` using
+ * `= REPOSITORY_FORMAT_INIT` before calling `read_repository_format()`.
+ */
struct repository_format {
int version;
int precious_objects;
@@ -974,14 +978,35 @@ struct repository_format {
};
/*
+ * Always use this to initialize a `struct repository_format`
+ * to a well-defined, default state before calling
+ * `read_repository()`.
+ */
+#define REPOSITORY_FORMAT_INIT \
+{ \
+ .version = -1, \
+ .is_bare = -1, \
+ .hash_algo = GIT_HASH_SHA1, \
+ .unknown_extensions = STRING_LIST_INIT_DUP, \
+}
+
+/*
* Read the repository format characteristics from the config file "path" into
- * "format" struct. Returns the numeric version. On error, -1 is returned,
- * format->version is set to -1, and all other fields in the struct are
- * undefined.
+ * "format" struct. Returns the numeric version. On error, or if no version is
+ * found in the configuration, -1 is returned, format->version is set to -1,
+ * and all other fields in the struct are set to the default configuration
+ * (REPOSITORY_FORMAT_INIT). Always initialize the struct using
+ * REPOSITORY_FORMAT_INIT before calling this function.
*/
int read_repository_format(struct repository_format *format, const char *path);
/*
+ * Free the memory held onto by `format`, but not the struct itself.
+ * (No need to use this after `read_repository_format()` fails.)
+ */
+void clear_repository_format(struct repository_format *format);
+
+/*
* Verify that the repository described by repository_format is something we
* can read. If it is, return 0. Otherwise, return -1, and "err" will describe
* any errors encountered.