From 9624a22ac603d3d59622b1f45a62d02f5fe55a25 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Tue, 29 Dec 2015 08:09:25 +0100 Subject: dir: free untracked cache when removing it Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin/update-index.c | 1 + 1 file changed, 1 insertion(+) (limited to 'builtin/update-index.c') diff --git a/builtin/update-index.c b/builtin/update-index.c index 7431938fa6..a6fff87c1d 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -1123,6 +1123,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) add_untracked_ident(the_index.untracked); the_index.cache_changed |= UNTRACKED_CHANGED; } else if (!untracked_cache && the_index.untracked) { + free_untracked_cache(the_index.untracked); the_index.untracked = NULL; the_index.cache_changed |= UNTRACKED_CHANGED; } -- cgit v1.2.1 From 113e6413187c65a9fbf2b845a1fb31c7d17c0755 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sun, 24 Jan 2016 16:28:15 +0100 Subject: update-index: use enum for untracked cache options Helped-by: Duy Nguyen Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin/update-index.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'builtin/update-index.c') diff --git a/builtin/update-index.c b/builtin/update-index.c index a6fff87c1d..1e546a3b3c 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -35,6 +35,14 @@ static int mark_skip_worktree_only; #define UNMARK_FLAG 2 static struct strbuf mtime_dir = STRBUF_INIT; +/* Untracked cache mode */ +enum uc_mode { + UC_UNSPECIFIED = -1, + UC_DISABLE = 0, + UC_ENABLE, + UC_FORCE +}; + __attribute__((format (printf, 1, 2))) static void report(const char *fmt, ...) { @@ -902,7 +910,7 @@ static int reupdate_callback(struct parse_opt_ctx_t *ctx, int cmd_update_index(int argc, const char **argv, const char *prefix) { int newfd, entries, has_errors = 0, line_termination = '\n'; - int untracked_cache = -1; + enum uc_mode untracked_cache = UC_UNSPECIFIED; int read_from_stdin = 0; int prefix_length = prefix ? strlen(prefix) : 0; int preferred_index_format = 0; @@ -997,7 +1005,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) OPT_BOOL(0, "untracked-cache", &untracked_cache, N_("enable/disable untracked cache")), OPT_SET_INT(0, "force-untracked-cache", &untracked_cache, - N_("enable untracked cache without testing the filesystem"), 2), + N_("enable untracked cache without testing the filesystem"), UC_FORCE), OPT_END() }; @@ -1104,10 +1112,10 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) the_index.split_index = NULL; the_index.cache_changed |= SOMETHING_CHANGED; } - if (untracked_cache > 0) { + if (untracked_cache > UC_DISABLE) { struct untracked_cache *uc; - if (untracked_cache < 2) { + if (untracked_cache < UC_FORCE) { setup_work_tree(); if (!test_if_untracked_cache_is_supported()) return 1; @@ -1122,7 +1130,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) } add_untracked_ident(the_index.untracked); the_index.cache_changed |= UNTRACKED_CHANGED; - } else if (!untracked_cache && the_index.untracked) { + } else if (untracked_cache == UC_DISABLE && the_index.untracked) { free_untracked_cache(the_index.untracked); the_index.untracked = NULL; the_index.cache_changed |= UNTRACKED_CHANGED; -- cgit v1.2.1 From eaab83d0e574c9f3440a2364a7975f9ffe75f188 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sun, 24 Jan 2016 16:28:16 +0100 Subject: update-index: add --test-untracked-cache It is nice to just be able to test if untracked cache is supported without enabling it. Helped-by: David Turner Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin/update-index.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'builtin/update-index.c') diff --git a/builtin/update-index.c b/builtin/update-index.c index 1e546a3b3c..62222dd8c7 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -40,6 +40,7 @@ enum uc_mode { UC_UNSPECIFIED = -1, UC_DISABLE = 0, UC_ENABLE, + UC_TEST, UC_FORCE }; @@ -1004,6 +1005,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) N_("enable or disable split index")), OPT_BOOL(0, "untracked-cache", &untracked_cache, N_("enable/disable untracked cache")), + OPT_SET_INT(0, "test-untracked-cache", &untracked_cache, + N_("test if the filesystem supports untracked cache"), UC_TEST), OPT_SET_INT(0, "force-untracked-cache", &untracked_cache, N_("enable untracked cache without testing the filesystem"), UC_FORCE), OPT_END() @@ -1119,6 +1122,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) setup_work_tree(); if (!test_if_untracked_cache_is_supported()) return 1; + if (untracked_cache == UC_TEST) + return 0; } if (!the_index.untracked) { uc = xcalloc(1, sizeof(*uc)); -- cgit v1.2.1 From 6d19db1491f1f48c5112f460e1f2d2e359e113c9 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sun, 24 Jan 2016 16:28:17 +0100 Subject: update-index: add untracked cache notifications Attempting to flip the untracked-cache feature on for a random index file with cd /random/unrelated/place git --git-dir=/somewhere/else/.git update-index --untracked-cache would not work as you might expect. Because flipping the feature on in the index also records the location of the corresponding working tree (/random/unrelated/place in the above example), when the index is subsequently used to keep track of files in the working tree in /somewhere/else, the feature is disabled. With this patch "git update-index --[test-]untracked-cache" tells the user in which directory tests are performed. This makes it easy to spot any problem. Also in verbose mode, let's tell the user when the cache is enabled or disabled. Helped-by: Duy Nguyen Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin/update-index.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'builtin/update-index.c') diff --git a/builtin/update-index.c b/builtin/update-index.c index 62222dd8c7..369c207312 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -130,7 +130,7 @@ static int test_if_untracked_cache_is_supported(void) if (!mkdtemp(mtime_dir.buf)) die_errno("Could not make temporary directory"); - fprintf(stderr, _("Testing ")); + fprintf(stderr, _("Testing mtime in '%s' "), xgetcwd()); atexit(remove_test_directory); xstat_mtime_dir(&st); fill_stat_data(&base, &st); @@ -1135,10 +1135,14 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) } add_untracked_ident(the_index.untracked); the_index.cache_changed |= UNTRACKED_CHANGED; - } else if (untracked_cache == UC_DISABLE && the_index.untracked) { - free_untracked_cache(the_index.untracked); - the_index.untracked = NULL; - the_index.cache_changed |= UNTRACKED_CHANGED; + report(_("Untracked cache enabled for '%s'"), get_git_work_tree()); + } else if (untracked_cache == UC_DISABLE) { + if (the_index.untracked) { + free_untracked_cache(the_index.untracked); + the_index.untracked = NULL; + the_index.cache_changed |= UNTRACKED_CHANGED; + } + report(_("Untracked cache disabled")); } if (active_cache_changed) { -- cgit v1.2.1 From e7c0c5354be01bedb4c6f0ad3b095ff0bfefa272 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sun, 24 Jan 2016 16:28:18 +0100 Subject: update-index: move 'uc' var declaration Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin/update-index.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'builtin/update-index.c') diff --git a/builtin/update-index.c b/builtin/update-index.c index 369c207312..fe7aaa34a4 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -1116,8 +1116,6 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) the_index.cache_changed |= SOMETHING_CHANGED; } if (untracked_cache > UC_DISABLE) { - struct untracked_cache *uc; - if (untracked_cache < UC_FORCE) { setup_work_tree(); if (!test_if_untracked_cache_is_supported()) @@ -1126,7 +1124,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) return 0; } if (!the_index.untracked) { - uc = xcalloc(1, sizeof(*uc)); + struct untracked_cache *uc = xcalloc(1, sizeof(*uc)); strbuf_init(&uc->ident, 100); uc->exclude_per_dir = ".gitignore"; /* should be the same flags used by git-status */ -- cgit v1.2.1 From 4a4ca4796df6b81d5995f31e87e9e6a64c2b889d Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sun, 24 Jan 2016 16:28:19 +0100 Subject: dir: add {new,add}_untracked_cache() Factor out code into new_untracked_cache() and add_untracked_cache(), which will be used in later commits. Helped-by: Eric Sunshine Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin/update-index.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'builtin/update-index.c') diff --git a/builtin/update-index.c b/builtin/update-index.c index fe7aaa34a4..5f8630c61b 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -1123,16 +1123,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) if (untracked_cache == UC_TEST) return 0; } - if (!the_index.untracked) { - struct untracked_cache *uc = xcalloc(1, sizeof(*uc)); - strbuf_init(&uc->ident, 100); - uc->exclude_per_dir = ".gitignore"; - /* should be the same flags used by git-status */ - uc->dir_flags = DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES; - the_index.untracked = uc; - } - add_untracked_ident(the_index.untracked); - the_index.cache_changed |= UNTRACKED_CHANGED; + add_untracked_cache(&the_index); report(_("Untracked cache enabled for '%s'"), get_git_work_tree()); } else if (untracked_cache == UC_DISABLE) { if (the_index.untracked) { -- cgit v1.2.1 From 07b29bfd8d3de9a16c1c93e285b6980ca6b77b45 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sun, 24 Jan 2016 16:28:20 +0100 Subject: dir: add remove_untracked_cache() Factor out code into remove_untracked_cache(), which will be used in a later commit. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin/update-index.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'builtin/update-index.c') diff --git a/builtin/update-index.c b/builtin/update-index.c index 5f8630c61b..d90154c59a 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -1126,11 +1126,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) add_untracked_cache(&the_index); report(_("Untracked cache enabled for '%s'"), get_git_work_tree()); } else if (untracked_cache == UC_DISABLE) { - if (the_index.untracked) { - free_untracked_cache(the_index.untracked); - the_index.untracked = NULL; - the_index.cache_changed |= UNTRACKED_CHANGED; - } + remove_untracked_cache(&the_index); report(_("Untracked cache disabled")); } -- cgit v1.2.1 From 435ec090ec6aed9c533e096b31947b3fa765548e Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Wed, 27 Jan 2016 07:58:05 +0100 Subject: config: add core.untrackedCache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we know that mtime on directory as given by the environment is usable for the purpose of untracked cache, we may want the untracked cache to be always used without any mtime test or kernel name check being performed. Also when we know that mtime is not usable for the purpose of untracked cache, for example because the repo is shared over a network file system, we may want the untracked-cache to be automatically removed from the index. Allow the user to express such preference by setting the 'core.untrackedCache' configuration variable, which can take 'keep', 'false', or 'true' and default to 'keep'. When read_index_from() is called, it now adds or removes the untracked cache in the index to respect the value of this variable. So it does nothing if the value is `keep` or if the variable is unset; it adds the untracked cache if the value is `true`; and it removes the cache if the value is `false`. `git update-index --[no-|force-]untracked-cache` still adds the untracked cache to, or removes it, from the index, but this shows a warning if it goes against the value of core.untrackedCache, because the next time the index is read the untracked cache will be added or removed if the configuration is set to do so. Also `--untracked-cache` used to check that the underlying operating system and file system change `st_mtime` field of a directory if files are added or deleted in that directory. But because those tests take a long time, `--untracked-cache` no longer performs them. Instead, there is now `--test-untracked-cache` to perform the tests. This change makes `--untracked-cache` the same as `--force-untracked-cache`. This last change is backward incompatible and should be mentioned in the release notes. Helped-by: Duy Nguyen Helped-by: Torsten Bögershausen Helped-by: Stefan Beller Signed-off-by: Christian Couder Signed-off-by: Ævar Arnfjörð Bjarmason read-cache: Duy'sfixup Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin/update-index.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'builtin/update-index.c') diff --git a/builtin/update-index.c b/builtin/update-index.c index d90154c59a..7a5533491e 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -1115,19 +1115,32 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) the_index.split_index = NULL; the_index.cache_changed |= SOMETHING_CHANGED; } - if (untracked_cache > UC_DISABLE) { - if (untracked_cache < UC_FORCE) { - setup_work_tree(); - if (!test_if_untracked_cache_is_supported()) - return 1; - if (untracked_cache == UC_TEST) - return 0; - } - add_untracked_cache(&the_index); - report(_("Untracked cache enabled for '%s'"), get_git_work_tree()); - } else if (untracked_cache == UC_DISABLE) { + + switch (untracked_cache) { + case UC_UNSPECIFIED: + break; + case UC_DISABLE: + if (git_config_get_untracked_cache() == 1) + warning("core.untrackedCache is set to true; " + "remove or change it, if you really want to " + "disable the untracked cache"); remove_untracked_cache(&the_index); report(_("Untracked cache disabled")); + break; + case UC_TEST: + setup_work_tree(); + return !test_if_untracked_cache_is_supported(); + case UC_ENABLE: + case UC_FORCE: + if (git_config_get_untracked_cache() == 0) + warning("core.untrackedCache is set to false; " + "remove or change it, if you really want to " + "enable the untracked cache"); + add_untracked_cache(&the_index); + report(_("Untracked cache enabled for '%s'"), get_git_work_tree()); + break; + default: + die("Bug: bad untracked_cache value: %d", untracked_cache); } if (active_cache_changed) { -- cgit v1.2.1