11
#include "date.h"
12
#include "branch.h"
13
#include "config.h"
14
+#include "dir.h"
15
#include "parse.h"
16
#include "convert.h"
17
#include "environment.h"
1952
return 1;
1953
}
1954
1955
+struct comment_char_config {
1956
+ unsigned last_key_id;
1957
+ bool auto_set;
1958
+};
1959
+
1960
+#define COMMENT_CHAR_CFG_INIT { 0 }
1961
+
1962
+static const char *comment_key_name(unsigned id)
1963
+{
1964
+ static const char *name[] = {
1965
+ "core.commentChar",
1966
+ "core.commentString",
1967
+ };
1968
+
1969
+ if (id >= ARRAY_SIZE(name))
1970
+ BUG("invalid comment key id");
1971
+
1972
+ return name[id];
1973
+}
1974
+
1975
+static void comment_char_callback(const char *key, const char *value,
1976
+ const struct config_context *ctx UNUSED,
1977
+ void *data)
1978
+{
1979
+ struct comment_char_config *config = data;
1980
+ unsigned key_id;
1981
+
1982
+ if (!strcmp(key, "core.commentchar"))
1983
+ key_id = 0;
1984
+ else if (!strcmp(key, "core.commentstring"))
1985
+ key_id = 1;
1986
+ else
1987
+ return;
1988
+
1989
+ config->last_key_id = key_id;
1990
+ config->auto_set = value && !strcmp(value, "auto");
1991
+}
1992
+
1993
+struct repo_config {
1994
+ struct repository *repo;
1995
+ struct comment_char_config comment_char_config;
1996
+};
1997
+
1998
+#define REPO_CONFIG_INIT(repo_) { \
1999
+ .comment_char_config = COMMENT_CHAR_CFG_INIT, \
2000
+ .repo = repo_, \
2001
+ };
2002
+
2003
+#ifdef WITH_BREAKING_CHANGES
2004
+static void check_auto_comment_char_config(struct comment_char_config *config)
2005
+{
2006
+ if (!config->auto_set)
2007
+ return;
2008
+
2009
+ die_message(_("Support for '%s=auto' has been removed in Git 3.0"),
2010
+ comment_key_name(config->last_key_id));
2011
+ die(NULL);
2012
+}
2013
+#else
2014
+static void check_auto_comment_char_config(struct comment_char_config *config)
2015
+{
2016
+ extern bool warn_on_auto_comment_char;
2017
+ const char *DEPRECATED_CONFIG_ENV =
2018
+ "GIT_AUTO_COMMENT_CHAR_CONFIG_WARNING_GIVEN";
2019
+
2020
+ if (!config->auto_set || !warn_on_auto_comment_char)
2021
+ return;
2022
+
2023
+ /*
2024
+ * Use an environment variable to ensure that subprocesses do not repeat
2025
+ * the warning.
2026
+ */
2027
+ if (git_env_bool(DEPRECATED_CONFIG_ENV, false))
2028
+ return;
2029
+
2030
+ setenv(DEPRECATED_CONFIG_ENV, "true", true);
2031
+
2032
+ warning(_("Support for '%s=auto' is deprecated and will be removed in "
2033
+ "Git 3.0"), comment_key_name(config->last_key_id));
2034
+}
2035
+#endif /* WITH_BREAKING_CHANGES */
2036
+
2037
+static void check_deprecated_config(struct repo_config *config)
2038
+{
2039
+ if (!config->repo->check_deprecated_config)
2040
+ return;
2041
+
2042
+ check_auto_comment_char_config(&config->comment_char_config);
2043
+}
2044
+
2045
+static int repo_config_callback(const char *key, const char *value,
2046
+ const struct config_context *ctx, void *data)
2047
+{
2048
+ struct repo_config *config = data;
2049
+
2050
+ comment_char_callback(key, value, ctx, &config->comment_char_config);
2051
+ return config_set_callback(key, value, ctx, config->repo->config);
2052
+}
2053
+
2054
/* Functions use to read configuration from a repository */
2055
static void repo_read_config(struct repository *repo)
2056
{
2057
struct config_options opts = { 0 };
2058
+ struct repo_config config = REPO_CONFIG_INIT(repo);
2059
2060
opts.respect_includes = 1;
2061
opts.commondir = repo->commondir;
2067
git_configset_clear(repo->config);
2068
2069
git_configset_init(repo->config);
1969
- if (config_with_options(config_set_callback, repo->config, NULL,
1970
- repo, &opts) < 0)
2070
+ if (config_with_options(repo_config_callback, &config, NULL, repo,
2071
+ &opts) < 0)
2072
/*
2073
* config_with_options() normally returns only
2074
* zero, as most errors are fatal, and
2081
* immediately.
2082
*/
2083
die(_("unknown error occurred while reading the configuration files"));
2084
+ check_deprecated_config(&config);
2085
}
2086
2087
static void git_config_check_init(struct repository *repo)
2769
char *contents = NULL;
2770
size_t contents_sz;
2771
struct config_store_data store = CONFIG_STORE_INIT;
2772
+ bool saved_check_deprecated_config = r->check_deprecated_config;
2773
+
2774
+ /*
2775
+ * Do not warn or die if there are deprecated config settings as
2776
+ * we want the user to be able to change those settings by running
2777
+ * "git config".
2778
+ */
2779
+ r->check_deprecated_config = false;
2780
2781
validate_comment_string(comment);
2782
3008
if (in_fd >= 0)
3009
close(in_fd);
3010
config_store_data_clear(&store);
3011
+ r->check_deprecated_config = saved_check_deprecated_config;
3012
return ret;
3013
3014
write_err_out: