]> git.ipfire.org Git - thirdparty/git.git/commitdiff
test-dump-untracked-cache: don't modify the untracked cache
authorChristian Couder <christian.couder@gmail.com>
Wed, 27 Jan 2016 06:58:06 +0000 (07:58 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 Jan 2016 20:30:07 +0000 (12:30 -0800)
To correctly perform its testing function,
test-dump-untracked-cache should not change the state of the
untracked cache in the index.

As a previous patch makes read_index_from() change the state of
the untracked cache and as test-dump-untracked-cache indirectly
calls this function, we need a mechanism to prevent
read_index_from() from changing the untracked cache state when
it's called from test-dump-untracked-cache.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h
config.c
environment.c
test-dump-untracked-cache.c

diff --git a/cache.h b/cache.h
index a7f084a539ead0f7d39b5083905a5569d82fbc49..255b273d82a8ec4b51bfc582e93a55a09c6d45f9 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1604,6 +1604,13 @@ extern int git_config_get_maybe_bool(const char *key, int *dest);
 extern int git_config_get_pathname(const char *key, const char **dest);
 extern int git_config_get_untracked_cache(void);
 
+/*
+ * This is a hack for test programs like test-dump-untracked-cache to
+ * ensure that they do not modify the untracked cache when reading it.
+ * Do not use it otherwise!
+ */
+extern int ignore_untracked_cache_config;
+
 struct key_value_info {
        const char *filename;
        int linenr;
index 647a15ef7258dfedbb221bcacb7b40a30eb9b17e..b95ac3a9cd5ca4fef392a2202f0a5722d15b8dde 100644 (file)
--- a/config.c
+++ b/config.c
@@ -1599,6 +1599,10 @@ int git_config_get_untracked_cache(void)
        int val = -1;
        const char *v;
 
+       /* Hack for test programs like test-dump-untracked-cache */
+       if (ignore_untracked_cache_config)
+               return -1;
+
        if (!git_config_get_maybe_bool("core.untrackedcache", &val))
                return val;
 
index 2da7fe2e06ff38b977209d44b7404c93358430af..b329024f134a9c859689f99e8818d8b58a6b05ce 100644 (file)
@@ -87,6 +87,13 @@ int auto_comment_line_char;
 /* Parallel index stat data preload? */
 int core_preload_index = 1;
 
+/*
+ * This is a hack for test programs like test-dump-untracked-cache to
+ * ensure that they do not modify the untracked cache when reading it.
+ * Do not use it otherwise!
+ */
+int ignore_untracked_cache_config;
+
 /* This is set by setup_git_dir_gently() and/or git_default_config() */
 char *git_work_tree_cfg;
 static char *work_tree;
index 25d855d98b5cc718a6da63824e1c0f9ae39ab77c..0a1c28524668f02d3aa4d073c0c6991652cbf850 100644 (file)
@@ -44,6 +44,10 @@ int main(int ac, char **av)
 {
        struct untracked_cache *uc;
        struct strbuf base = STRBUF_INIT;
+
+       /* Hack to avoid modifying the untracked cache when we read it */
+       ignore_untracked_cache_config = 1;
+
        setup_git_directory();
        if (read_cache() < 0)
                die("unable to read index file");