From 4b0d1eebe95b8ed187ff06ae46d69d517c2b759f Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 11 Mar 2016 17:36:45 -0500 Subject: setup: document check_repository_format() This function's interface is rather enigmatic, so let's document it further. While we're here, let's also drop the return value. It will always either be "0" or the function will die (consequently, neither of its two callers bothered to check the return). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index b829410f6d..02e38d1a91 100644 --- a/cache.h +++ b/cache.h @@ -747,7 +747,14 @@ extern int grafts_replace_parents; #define GIT_REPO_VERSION_READ 1 extern int repository_format_version; extern int repository_format_precious_objects; -extern int check_repository_format(void); + +/* + * Check the repository format version in the path found in get_git_dir(), + * and die if it is a version we don't understand. Generally one would + * set_git_dir() before calling this, and use it only for "are we in a valid + * repo?". + */ +extern void check_repository_format(void); #define MTIME_CHANGED 0x0001 #define CTIME_CHANGED 0x0002 -- cgit v1.2.3 From 7875acb6ecf85a7dc29554d193955ce5e265764f Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 11 Mar 2016 17:36:49 -0500 Subject: wrap shared_repository global in get/set accessors It would be useful to control access to the global shared_repository, so that we can lazily load its config. The first step to doing so is to make sure all access goes through a set of functions. This step is purely mechanical, and should result in no change of behavior. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 02e38d1a91..fdb9583cf5 100644 --- a/cache.h +++ b/cache.h @@ -651,7 +651,6 @@ extern int prefer_symlink_refs; extern int log_all_ref_updates; extern int warn_ambiguous_refs; extern int warn_on_object_refname_ambiguity; -extern int shared_repository; extern const char *apply_default_whitespace; extern const char *apply_default_ignorewhitespace; extern const char *git_attributes_file; @@ -664,6 +663,9 @@ extern size_t delta_base_cache_limit; extern unsigned long big_file_threshold; extern unsigned long pack_size_limit_cfg; +void set_shared_repository(int value); +int get_shared_repository(void); + /* * Do replace refs need to be checked this run? This variable is * initialized to true unless --no-replace-object is used or -- cgit v1.2.3 From 801818680ab907abf347fbdc48623f43a49beee9 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 11 Mar 2016 17:37:03 -0500 Subject: config: drop git_config_early There are no more callers, and it's a rather confusing interface. This could just be folded into git_config_with_options(), but for the sake of readability, we'll leave it as a separate (static) helper function. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index fdb9583cf5..867e73eb54 100644 --- a/cache.h +++ b/cache.h @@ -1535,7 +1535,6 @@ extern void git_config(config_fn_t fn, void *); extern int git_config_with_options(config_fn_t fn, void *, struct git_config_source *config_source, int respect_includes); -extern int git_config_early(config_fn_t fn, void *, const char *repo_config); extern int git_parse_ulong(const char *, unsigned long *); extern int git_parse_maybe_bool(const char *); extern int git_config_int(const char *, const char *); -- cgit v1.2.3 From 2cc7c2c737f2af16915b3d6cb6245111e1349609 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 11 Mar 2016 17:37:07 -0500 Subject: setup: refactor repo format reading and verification When we want to know if we're in a git repository of reasonable vintage, we can call check_repository_format_gently(), which does three things: 1. Reads the config from the .git/config file. 2. Verifies that the version info we read is sane. 3. Writes some global variables based on this. There are a few things we could improve here. One is that steps 1 and 3 happen together. So if the verification in step 2 fails, we still clobber the global variables. This is especially bad if we go on to try another repository directory; we may end up with a state of mixed config variables. The second is there's no way to ask about the repository version for anything besides the main repository we're in. git-init wants to do this, and it's possible that we would want to start doing so for submodules (e.g., to find out which ref backend they're using). We can improve both by splitting the first two steps into separate functions. Now check_repository_format_gently() calls out to steps 1 and 2, and does 3 only if step 2 succeeds. Note that the public interface for read_repository_format() and what check_repository_format_gently() needs from it are not quite the same, leading us to have an extra read_repository_format_1() helper. The extra needs from check_repository_format_gently() will go away in a future patch, and we can simplify this then to just the public interface. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 867e73eb54..4fc42b5ec7 100644 --- a/cache.h +++ b/cache.h @@ -750,6 +750,30 @@ extern int grafts_replace_parents; extern int repository_format_version; extern int repository_format_precious_objects; +struct repository_format { + int version; + int precious_objects; + int is_bare; + char *work_tree; + struct string_list unknown_extensions; +}; + +/* + * 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. + */ +int read_repository_format(struct repository_format *format, const char *path); + +/* + * 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. + */ +int verify_repository_format(const struct repository_format *format, + struct strbuf *err); + /* * Check the repository format version in the path found in get_git_dir(), * and die if it is a version we don't understand. Generally one would -- cgit v1.2.3 From 652f18ee8734ffb4a98271e5020dfa550db0f37b Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 11 Mar 2016 17:37:14 -0500 Subject: setup: unify repository version callbacks Once upon a time, check_repository_format_gently would parse the config with a single callback, and that callback would set up a bunch of global variables. But now that we have separate workdirs, we have to be more careful. Commit 31e26eb (setup.c: support multi-checkout repo setup, 2014-11-30) introduced a reduced callback which omits some values like core.worktree. In the "main" callback we call the reduced one, and then add back in the missing variables. Now that we have split the config-parsing from the munging of the global variables, we can do it all with a single callback, and keep all of the "are we in a separate workdir" logic together. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 4fc42b5ec7..7704bc6c89 100644 --- a/cache.h +++ b/cache.h @@ -1582,7 +1582,6 @@ extern void git_config_set_multivar_in_file(const char *, const char *, const ch extern int git_config_rename_section(const char *, const char *); extern int git_config_rename_section_in_file(const char *, const char *, const char *); extern const char *git_etc_gitconfig(void); -extern int check_repository_format_version(const char *var, const char *value, void *cb); extern int git_env_bool(const char *, int); extern unsigned long git_env_ulong(const char *, unsigned long); extern int git_config_system(void); -- cgit v1.2.3 From c90e5293d11bc2c671312778aea33922a4ee1725 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 11 Mar 2016 17:37:18 -0500 Subject: setup: drop repository_format_version global Nobody reads this anymore, and they're not likely to; the interesting thing is whether or not we passed check_repository_format(), and possibly the individual "extension" variables. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 7704bc6c89..bec6db5e2e 100644 --- a/cache.h +++ b/cache.h @@ -747,7 +747,6 @@ extern int grafts_replace_parents; */ #define GIT_REPO_VERSION 0 #define GIT_REPO_VERSION_READ 1 -extern int repository_format_version; extern int repository_format_precious_objects; struct repository_format { -- cgit v1.2.3