1111#include "date.h"
1212#include "branch.h"
1313#include "config.h"
14+ #include "dir.h"
1415#include "parse.h"
1516#include "convert.h"
1617#include "environment.h"
@@ -1951,10 +1952,110 @@ int git_configset_get_pathname(struct config_set *set, const char *key, char **d
19511952 return 1 ;
19521953}
19531954
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+
19542054/* Functions use to read configuration from a repository */
19552055static void repo_read_config (struct repository * repo )
19562056{
19572057 struct config_options opts = { 0 };
2058+ struct repo_config config = REPO_CONFIG_INIT (repo );
19582059
19592060 opts .respect_includes = 1 ;
19602061 opts .commondir = repo -> commondir ;
@@ -1966,8 +2067,8 @@ static void repo_read_config(struct repository *repo)
19662067 git_configset_clear (repo -> config );
19672068
19682069 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 )
19712072 /*
19722073 * config_with_options() normally returns only
19732074 * zero, as most errors are fatal, and
@@ -1980,6 +2081,7 @@ static void repo_read_config(struct repository *repo)
19802081 * immediately.
19812082 */
19822083 die (_ ("unknown error occurred while reading the configuration files" ));
2084+ check_deprecated_config (& config );
19832085}
19842086
19852087static void git_config_check_init (struct repository * repo )
@@ -2667,6 +2769,14 @@ int repo_config_set_multivar_in_file_gently(struct repository *r,
26672769 char * contents = NULL ;
26682770 size_t contents_sz ;
26692771 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;
26702780
26712781 validate_comment_string (comment );
26722782
@@ -2898,6 +3008,7 @@ int repo_config_set_multivar_in_file_gently(struct repository *r,
28983008 if (in_fd >= 0 )
28993009 close (in_fd );
29003010 config_store_data_clear (& store );
3011+ r -> check_deprecated_config = saved_check_deprecated_config ;
29013012 return ret ;
29023013
29033014write_err_out :
0 commit comments