git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v8 00/11] Untracked cache improvements
@ 2016-01-27  6:57 Christian Couder
  2016-01-27  6:57 ` [PATCH v8 01/11] dir: free untracked cache when removing it Christian Couder
                   ` (10 more replies)
  0 siblings, 11 replies; 16+ messages in thread
From: Christian Couder @ 2016-01-27  6:57 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Ævar Arnfjörð Bjarmason,
	Nguyen Thai Ngoc Duy, David Turner, Eric Sunshine,
	Torsten Bögershausen, Stefan Beller, Christian Couder

Here is a new version of a patch series to improve the untracked cache
feature.

This v8 implements core.untrackedCache as a tristate config
variable. When it's `true`, Git commands, especially `git status`,
should always add the untracked cache and use it, and when `false`,
Git commands should remove it. The default is `keep` in which case the
untracked cache is neither removed nor added, and used if it is there.

This v8 is mostly identical to the previous v7. Only patch 9/11, which
adds core.untrackedCache, has one change.

Patch 1/11 is a small bugfix.

Patch 2/11 to 4/11 add some small features that are missing.

Patchs 5/11 to 7/11 are some refactoring to prepare for the following
patchs.

Patch 8/11 deals with the "ident" field in "struct untracked_cache".

Patch 9/11 adds core.untrackedCache. As Junio suggested, the check to
see if we should add or remove the untracked cache is now made inside
a new tweak_untracked_cache() function which is called by the new
post_read_index_from() function after it calls check_ce_order().

Patch 10/11 is a hack that is needed to have test-dump-untracked-cache
work like it used to.

Patch 11/11 contains tests.

The patch series is also available there:

https://github.com/chriscool/git/tree/uc-notifs71

Christian Couder (11):
  dir: free untracked cache when removing it
  update-index: use enum for untracked cache options
  update-index: add --test-untracked-cache
  update-index: add untracked cache notifications
  update-index: move 'uc' var declaration
  dir: add {new,add}_untracked_cache()
  dir: add remove_untracked_cache()
  dir: simplify untracked cache "ident" field
  config: add core.untrackedCache
  test-dump-untracked-cache: don't modify the untracked cache
  t7063: add tests for core.untrackedCache

 Documentation/config.txt               |  9 ++++
 Documentation/git-update-index.txt     | 67 +++++++++++++++++++++----
 builtin/update-index.c                 | 62 ++++++++++++++---------
 cache.h                                |  8 +++
 config.c                               | 24 +++++++++
 contrib/completion/git-completion.bash |  1 +
 dir.c                                  | 62 ++++++++++++++++++-----
 dir.h                                  |  3 +-
 environment.c                          |  7 +++
 read-cache.c                           | 27 ++++++++++-
 t/t7063-status-untracked-cache.sh      | 89 +++++++++++++++++++++++++++++++---
 test-dump-untracked-cache.c            |  4 ++
 12 files changed, 307 insertions(+), 56 deletions(-)

-- 
2.7.0.181.g07d31f8

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v8 01/11] dir: free untracked cache when removing it
  2016-01-27  6:57 [PATCH v8 00/11] Untracked cache improvements Christian Couder
@ 2016-01-27  6:57 ` Christian Couder
  2016-01-27  6:57 ` [PATCH v8 02/11] update-index: use enum for untracked cache options Christian Couder
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: Christian Couder @ 2016-01-27  6:57 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Ævar Arnfjörð Bjarmason,
	Nguyen Thai Ngoc Duy, David Turner, Eric Sunshine,
	Torsten Bögershausen, Stefan Beller, Christian Couder

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin/update-index.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/builtin/update-index.c b/builtin/update-index.c
index 7431938..a6fff87 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;
 	}
-- 
2.7.0.181.g07d31f8

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v8 02/11] update-index: use enum for untracked cache options
  2016-01-27  6:57 [PATCH v8 00/11] Untracked cache improvements Christian Couder
  2016-01-27  6:57 ` [PATCH v8 01/11] dir: free untracked cache when removing it Christian Couder
@ 2016-01-27  6:57 ` Christian Couder
  2016-01-27  6:57 ` [PATCH v8 03/11] update-index: add --test-untracked-cache Christian Couder
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: Christian Couder @ 2016-01-27  6:57 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Ævar Arnfjörð Bjarmason,
	Nguyen Thai Ngoc Duy, David Turner, Eric Sunshine,
	Torsten Bögershausen, Stefan Beller, Christian Couder

Helped-by: Duy Nguyen <pclouds@gmail.com>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin/update-index.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/builtin/update-index.c b/builtin/update-index.c
index a6fff87..1e546a3 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;
-- 
2.7.0.181.g07d31f8

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v8 03/11] update-index: add --test-untracked-cache
  2016-01-27  6:57 [PATCH v8 00/11] Untracked cache improvements Christian Couder
  2016-01-27  6:57 ` [PATCH v8 01/11] dir: free untracked cache when removing it Christian Couder
  2016-01-27  6:57 ` [PATCH v8 02/11] update-index: use enum for untracked cache options Christian Couder
@ 2016-01-27  6:57 ` Christian Couder
  2016-01-27  6:58 ` [PATCH v8 04/11] update-index: add untracked cache notifications Christian Couder
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: Christian Couder @ 2016-01-27  6:57 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Ævar Arnfjörð Bjarmason,
	Nguyen Thai Ngoc Duy, David Turner, Eric Sunshine,
	Torsten Bögershausen, Stefan Beller, Christian Couder

It is nice to just be able to test if untracked cache is
supported without enabling it.

Helped-by: David Turner <dturner@twopensource.com>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 Documentation/git-update-index.txt | 12 +++++++++++-
 builtin/update-index.c             |  5 +++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt
index f4e5a85..a0afe17 100644
--- a/Documentation/git-update-index.txt
+++ b/Documentation/git-update-index.txt
@@ -18,7 +18,7 @@ SYNOPSIS
 	     [--[no-]skip-worktree]
 	     [--ignore-submodules]
 	     [--[no-]split-index]
-	     [--[no-|force-]untracked-cache]
+	     [--[no-|test-|force-]untracked-cache]
 	     [--really-refresh] [--unresolve] [--again | -g]
 	     [--info-only] [--index-info]
 	     [-z] [--stdin] [--index-version <n>]
@@ -180,6 +180,16 @@ may not support it yet.
 	system must change `st_mtime` field of a directory if files
 	are added or deleted in that directory.
 
+--test-untracked-cache::
+	Only perform tests on the working directory to make sure
+	untracked cache can be used. You have to manually enable
+	untracked cache using `--force-untracked-cache` (or
+	`--untracked-cache` but this will run the tests again)
+	afterwards if you really want to use it. If a test fails
+	the exit code is 1 and a message explains what is not
+	working as needed, otherwise the exit code is 0 and OK is
+	printed.
+
 --force-untracked-cache::
 	For safety, `--untracked-cache` performs tests on the working
 	directory to make sure untracked cache can be used. These
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 1e546a3..62222dd 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));
-- 
2.7.0.181.g07d31f8

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v8 04/11] update-index: add untracked cache notifications
  2016-01-27  6:57 [PATCH v8 00/11] Untracked cache improvements Christian Couder
                   ` (2 preceding siblings ...)
  2016-01-27  6:57 ` [PATCH v8 03/11] update-index: add --test-untracked-cache Christian Couder
@ 2016-01-27  6:58 ` Christian Couder
  2017-03-30  3:28   ` Jeff King
  2016-01-27  6:58 ` [PATCH v8 05/11] update-index: move 'uc' var declaration Christian Couder
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 16+ messages in thread
From: Christian Couder @ 2016-01-27  6:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Ævar Arnfjörð Bjarmason,
	Nguyen Thai Ngoc Duy, David Turner, Eric Sunshine,
	Torsten Bögershausen, Stefan Beller, Christian Couder

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 <pclouds@gmail.com>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin/update-index.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/builtin/update-index.c b/builtin/update-index.c
index 62222dd..369c207 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) {
-- 
2.7.0.181.g07d31f8

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v8 05/11] update-index: move 'uc' var declaration
  2016-01-27  6:57 [PATCH v8 00/11] Untracked cache improvements Christian Couder
                   ` (3 preceding siblings ...)
  2016-01-27  6:58 ` [PATCH v8 04/11] update-index: add untracked cache notifications Christian Couder
@ 2016-01-27  6:58 ` Christian Couder
  2016-01-27  6:58 ` [PATCH v8 06/11] dir: add {new,add}_untracked_cache() Christian Couder
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: Christian Couder @ 2016-01-27  6:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Ævar Arnfjörð Bjarmason,
	Nguyen Thai Ngoc Duy, David Turner, Eric Sunshine,
	Torsten Bögershausen, Stefan Beller, Christian Couder

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin/update-index.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/builtin/update-index.c b/builtin/update-index.c
index 369c207..fe7aaa3 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 */
-- 
2.7.0.181.g07d31f8

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v8 06/11] dir: add {new,add}_untracked_cache()
  2016-01-27  6:57 [PATCH v8 00/11] Untracked cache improvements Christian Couder
                   ` (4 preceding siblings ...)
  2016-01-27  6:58 ` [PATCH v8 05/11] update-index: move 'uc' var declaration Christian Couder
@ 2016-01-27  6:58 ` Christian Couder
  2016-01-27  6:58 ` [PATCH v8 07/11] dir: add remove_untracked_cache() Christian Couder
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: Christian Couder @ 2016-01-27  6:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Ævar Arnfjörð Bjarmason,
	Nguyen Thai Ngoc Duy, David Turner, Eric Sunshine,
	Torsten Bögershausen, Stefan Beller, Christian Couder

Factor out code into new_untracked_cache() and
add_untracked_cache(), which will be used
in later commits.

Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin/update-index.c | 11 +----------
 dir.c                  | 18 ++++++++++++++++++
 dir.h                  |  1 +
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/builtin/update-index.c b/builtin/update-index.c
index fe7aaa3..5f8630c 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) {
diff --git a/dir.c b/dir.c
index 29aec12..8646b18 100644
--- a/dir.c
+++ b/dir.c
@@ -1864,6 +1864,24 @@ void add_untracked_ident(struct untracked_cache *uc)
 	strbuf_addch(&uc->ident, 0);
 }
 
+static void new_untracked_cache(struct index_state *istate)
+{
+	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;
+	istate->untracked = uc;
+}
+
+void add_untracked_cache(struct index_state *istate)
+{
+	if (!istate->untracked) {
+		new_untracked_cache(istate);
+	add_untracked_ident(istate->untracked);
+	istate->cache_changed |= UNTRACKED_CHANGED;
+}
+
 static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *dir,
 						      int base_len,
 						      const struct pathspec *pathspec)
diff --git a/dir.h b/dir.h
index 7b5855d..cfd3636 100644
--- a/dir.h
+++ b/dir.h
@@ -308,4 +308,5 @@ void free_untracked_cache(struct untracked_cache *);
 struct untracked_cache *read_untracked_extension(const void *data, unsigned long sz);
 void write_untracked_extension(struct strbuf *out, struct untracked_cache *untracked);
 void add_untracked_ident(struct untracked_cache *);
+void add_untracked_cache(struct index_state *istate);
 #endif
-- 
2.7.0.181.g07d31f8

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v8 07/11] dir: add remove_untracked_cache()
  2016-01-27  6:57 [PATCH v8 00/11] Untracked cache improvements Christian Couder
                   ` (5 preceding siblings ...)
  2016-01-27  6:58 ` [PATCH v8 06/11] dir: add {new,add}_untracked_cache() Christian Couder
@ 2016-01-27  6:58 ` Christian Couder
  2016-01-27  6:58 ` [PATCH v8 08/11] dir: simplify untracked cache "ident" field Christian Couder
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: Christian Couder @ 2016-01-27  6:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Ævar Arnfjörð Bjarmason,
	Nguyen Thai Ngoc Duy, David Turner, Eric Sunshine,
	Torsten Bögershausen, Stefan Beller, Christian Couder

Factor out code into remove_untracked_cache(), which will be used
in a later commit.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin/update-index.c | 6 +-----
 dir.c                  | 9 +++++++++
 dir.h                  | 1 +
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/builtin/update-index.c b/builtin/update-index.c
index 5f8630c..d90154c 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"));
 	}
 
diff --git a/dir.c b/dir.c
index 8646b18..f27b8b9 100644
--- a/dir.c
+++ b/dir.c
@@ -1882,6 +1882,15 @@ void add_untracked_cache(struct index_state *istate)
 	istate->cache_changed |= UNTRACKED_CHANGED;
 }
 
+void remove_untracked_cache(struct index_state *istate)
+{
+	if (istate->untracked) {
+		free_untracked_cache(istate->untracked);
+		istate->untracked = NULL;
+		istate->cache_changed |= UNTRACKED_CHANGED;
+	}
+}
+
 static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *dir,
 						      int base_len,
 						      const struct pathspec *pathspec)
diff --git a/dir.h b/dir.h
index cfd3636..a3dacdb 100644
--- a/dir.h
+++ b/dir.h
@@ -309,4 +309,5 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
 void write_untracked_extension(struct strbuf *out, struct untracked_cache *untracked);
 void add_untracked_ident(struct untracked_cache *);
 void add_untracked_cache(struct index_state *istate);
+void remove_untracked_cache(struct index_state *istate);
 #endif
-- 
2.7.0.181.g07d31f8

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v8 08/11] dir: simplify untracked cache "ident" field
  2016-01-27  6:57 [PATCH v8 00/11] Untracked cache improvements Christian Couder
                   ` (6 preceding siblings ...)
  2016-01-27  6:58 ` [PATCH v8 07/11] dir: add remove_untracked_cache() Christian Couder
@ 2016-01-27  6:58 ` Christian Couder
  2016-01-27  6:58 ` [PATCH v8 09/11] config: add core.untrackedCache Christian Couder
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: Christian Couder @ 2016-01-27  6:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Ævar Arnfjörð Bjarmason,
	Nguyen Thai Ngoc Duy, David Turner, Eric Sunshine,
	Torsten Bögershausen, Stefan Beller, Christian Couder

It is not a good idea to compare kernel versions and disable
the untracked cache if it changes, as people may upgrade and
still want the untracked cache to work. So let's just
compare work tree locations and kernel name to decide if we
should disable it.

Also storing many locations in the ident field and comparing
to any of them can be dangerous if GIT_WORK_TREE is used with
different values. So let's just store one location, the
location of the current work tree.

The downside is that untracked cache can only be used by one
type of OS for now. Exporting a git repo to different clients
via a network to e.g. Linux and Windows means that only one
can use the untracked cache.

If the location changed in the ident field and we still want
an untracked cache, let's delete the cache and recreate it.

Note that if an untracked cache has been created by a
previous Git version, then the kernel version is stored in
the ident field. As we now compare with just the kernel
name the comparison will fail and the untracked cache will
be disabled until it's recreated.

Helped-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 dir.c | 39 ++++++++++++++++++++++++---------------
 dir.h |  1 -
 2 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/dir.c b/dir.c
index f27b8b9..f0b6d0a 100644
--- a/dir.c
+++ b/dir.c
@@ -1839,28 +1839,31 @@ static const char *get_ident_string(void)
 		return sb.buf;
 	if (uname(&uts) < 0)
 		die_errno(_("failed to get kernel name and information"));
-	strbuf_addf(&sb, "Location %s, system %s %s %s", get_git_work_tree(),
-		    uts.sysname, uts.release, uts.version);
+	strbuf_addf(&sb, "Location %s, system %s", get_git_work_tree(),
+		    uts.sysname);
 	return sb.buf;
 }
 
 static int ident_in_untracked(const struct untracked_cache *uc)
 {
-	const char *end = uc->ident.buf + uc->ident.len;
-	const char *p   = uc->ident.buf;
+	/*
+	 * Previous git versions may have saved many NUL separated
+	 * strings in the "ident" field, but it is insane to manage
+	 * many locations, so just take care of the first one.
+	 */
 
-	for (p = uc->ident.buf; p < end; p += strlen(p) + 1)
-		if (!strcmp(p, get_ident_string()))
-			return 1;
-	return 0;
+	return !strcmp(uc->ident.buf, get_ident_string());
 }
 
-void add_untracked_ident(struct untracked_cache *uc)
+static void set_untracked_ident(struct untracked_cache *uc)
 {
-	if (ident_in_untracked(uc))
-		return;
+	strbuf_reset(&uc->ident);
 	strbuf_addstr(&uc->ident, get_ident_string());
-	/* this strbuf contains a list of strings, save NUL too */
+
+	/*
+	 * This strbuf used to contain a list of NUL separated
+	 * strings, so save NUL too for backward compatibility.
+	 */
 	strbuf_addch(&uc->ident, 0);
 }
 
@@ -1871,15 +1874,21 @@ static void new_untracked_cache(struct index_state *istate)
 	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;
+	set_untracked_ident(uc);
 	istate->untracked = uc;
+	istate->cache_changed |= UNTRACKED_CHANGED;
 }
 
 void add_untracked_cache(struct index_state *istate)
 {
 	if (!istate->untracked) {
 		new_untracked_cache(istate);
-	add_untracked_ident(istate->untracked);
-	istate->cache_changed |= UNTRACKED_CHANGED;
+	} else {
+		if (!ident_in_untracked(istate->untracked)) {
+			free_untracked_cache(istate->untracked);
+			new_untracked_cache(istate);
+		}
+	}
 }
 
 void remove_untracked_cache(struct index_state *istate)
@@ -1948,7 +1957,7 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
 		return NULL;
 
 	if (!ident_in_untracked(dir->untracked)) {
-		warning(_("Untracked cache is disabled on this system."));
+		warning(_("Untracked cache is disabled on this system or location."));
 		return NULL;
 	}
 
diff --git a/dir.h b/dir.h
index a3dacdb..cd46f30 100644
--- a/dir.h
+++ b/dir.h
@@ -307,7 +307,6 @@ void untracked_cache_add_to_index(struct index_state *, const char *);
 void free_untracked_cache(struct untracked_cache *);
 struct untracked_cache *read_untracked_extension(const void *data, unsigned long sz);
 void write_untracked_extension(struct strbuf *out, struct untracked_cache *untracked);
-void add_untracked_ident(struct untracked_cache *);
 void add_untracked_cache(struct index_state *istate);
 void remove_untracked_cache(struct index_state *istate);
 #endif
-- 
2.7.0.181.g07d31f8

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v8 09/11] config: add core.untrackedCache
  2016-01-27  6:57 [PATCH v8 00/11] Untracked cache improvements Christian Couder
                   ` (7 preceding siblings ...)
  2016-01-27  6:58 ` [PATCH v8 08/11] dir: simplify untracked cache "ident" field Christian Couder
@ 2016-01-27  6:58 ` Christian Couder
  2016-01-27  6:58 ` [PATCH v8 10/11] test-dump-untracked-cache: don't modify the untracked cache Christian Couder
  2016-01-27  6:58 ` [PATCH v8 11/11] t7063: add tests for core.untrackedCache Christian Couder
  10 siblings, 0 replies; 16+ messages in thread
From: Christian Couder @ 2016-01-27  6:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Ævar Arnfjörð Bjarmason,
	Nguyen Thai Ngoc Duy, David Turner, Eric Sunshine,
	Torsten Bögershausen, Stefan Beller, Christian Couder

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 <pclouds@gmail.com>
Helped-by: Torsten Bögershausen <tboegi@web.de>
Helped-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>

read-cache: Duy'sfixup

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 Documentation/config.txt               |  9 +++++
 Documentation/git-update-index.txt     | 67 ++++++++++++++++++++++++++--------
 builtin/update-index.c                 | 35 ++++++++++++------
 cache.h                                |  1 +
 config.c                               | 20 ++++++++++
 contrib/completion/git-completion.bash |  1 +
 read-cache.c                           | 27 +++++++++++++-
 t/t7063-status-untracked-cache.sh      |  4 +-
 8 files changed, 133 insertions(+), 31 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 07f7a3b..354fd1c 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -308,6 +308,15 @@ core.trustctime::
 	crawlers and some backup systems).
 	See linkgit:git-update-index[1]. True by default.
 
+core.untrackedCache::
+	Determines what to do about the untracked cache feature of the
+	index. It will be kept, if this variable is unset or set to
+	`keep`. It will automatically be added if set to `true`. And
+	it will automatically be removed, if set to `false`. Before
+	setting it to `true`, you should check that mtime is working
+	properly on your system.
+	See linkgit:git-update-index[1]. `keep` by default.
+
 core.checkStat::
 	Determines which stat fields to match between the index
 	and work tree. The user can set this to 'default' or
diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt
index a0afe17..c6cbed1 100644
--- a/Documentation/git-update-index.txt
+++ b/Documentation/git-update-index.txt
@@ -174,27 +174,30 @@ may not support it yet.
 
 --untracked-cache::
 --no-untracked-cache::
-	Enable or disable untracked cache extension. This could speed
-	up for commands that involve determining untracked files such
-	as `git status`. The underlying operating system and file
-	system must change `st_mtime` field of a directory if files
-	are added or deleted in that directory.
+	Enable or disable untracked cache feature. Please use
+	`--test-untracked-cache` before enabling it.
++
+These options take effect whatever the value of the `core.untrackedCache`
+configuration variable (see linkgit:git-config[1]). But a warning is
+emitted when the change goes against the configured value, as the
+configured value will take effect next time the index is read and this
+will remove the intended effect of the option.
 
 --test-untracked-cache::
 	Only perform tests on the working directory to make sure
 	untracked cache can be used. You have to manually enable
-	untracked cache using `--force-untracked-cache` (or
-	`--untracked-cache` but this will run the tests again)
-	afterwards if you really want to use it. If a test fails
-	the exit code is 1 and a message explains what is not
-	working as needed, otherwise the exit code is 0 and OK is
-	printed.
+	untracked cache using `--untracked-cache` or
+	`--force-untracked-cache` or the `core.untrackedCache`
+	configuration variable afterwards if you really want to use
+	it. If a test fails the exit code is 1 and a message
+	explains what is not working as needed, otherwise the exit
+	code is 0 and OK is printed.
 
 --force-untracked-cache::
-	For safety, `--untracked-cache` performs tests on the working
-	directory to make sure untracked cache can be used. These
-	tests can take a few seconds. `--force-untracked-cache` can be
-	used to skip the tests.
+	Same as `--untracked-cache`. Provided for backwards
+	compatibility with older versions of Git where
+	`--untracked-cache` used to imply `--test-untracked-cache` but
+	this option would enable the extension unconditionally.
 
 \--::
 	Do not interpret any more arguments as options.
@@ -385,6 +388,37 @@ Although this bit looks similar to assume-unchanged bit, its goal is
 different from assume-unchanged bit's. Skip-worktree also takes
 precedence over assume-unchanged bit when both are set.
 
+Untracked cache
+---------------
+
+This cache is meant to speed up commands that involve determining
+untracked files such as `git status`.
+
+This feature works by recording the mtime of the working tree
+directories and then omitting reading directories and stat calls
+against files in those directories whose mtime hasn't changed. For
+this to work the underlying operating system and file system must
+change the `st_mtime` field of directories if files in the directory
+are added, modified or deleted.
+
+You can test whether the filesystem supports that with the
+`--test-untracked-cache` option. The `--untracked-cache` option used
+to implicitly perform that test in older versions of Git, but that's
+no longer the case.
+
+If you want to enable (or disable) this feature, it is easier to use
+the `core.untrackedCache` configuration variable (see
+linkgit:git-config[1]) than using the `--untracked-cache` option to
+`git update-index` in each repository, especially if you want to do so
+across all repositories you use, because you can set the configuration
+variable to `true` (or `false`) in your `$HOME/.gitconfig` just once
+and have it affect all repositories you touch.
+
+When the `core.untrackedCache` configuration variable is changed, the
+untracked cache is added to or removed from the index the next time a
+command reads the index; while when `--[no-|force-]untracked-cache`
+are used, the untracked cache is immediately added to or removed from
+the index.
 
 Configuration
 -------------
@@ -410,6 +444,9 @@ It can be useful when the inode change time is regularly modified by
 something outside Git (file system crawlers and backup systems use
 ctime for marking files processed) (see linkgit:git-config[1]).
 
+The untracked cache extension can be enabled by the
+`core.untrackedCache` configuration variable (see
+linkgit:git-config[1]).
 
 SEE ALSO
 --------
diff --git a/builtin/update-index.c b/builtin/update-index.c
index d90154c..7a55334 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) {
diff --git a/cache.h b/cache.h
index dfc459c..e2900d1 100644
--- a/cache.h
+++ b/cache.h
@@ -1606,6 +1606,7 @@ extern int git_config_get_bool(const char *key, int *dest);
 extern int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest);
 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);
 
 struct key_value_info {
 	const char *filename;
diff --git a/config.c b/config.c
index 86a5eb2..647a15e 100644
--- a/config.c
+++ b/config.c
@@ -1594,6 +1594,26 @@ int git_config_get_pathname(const char *key, const char **dest)
 	return ret;
 }
 
+int git_config_get_untracked_cache(void)
+{
+	int val = -1;
+	const char *v;
+
+	if (!git_config_get_maybe_bool("core.untrackedcache", &val))
+		return val;
+
+	if (!git_config_get_value("core.untrackedcache", &v)) {
+		if (!strcasecmp(v, "keep"))
+			return -1;
+
+		error("unknown core.untrackedCache value '%s'; "
+		      "using 'keep' default value", v);
+		return -1;
+	}
+
+	return -1; /* default value */
+}
+
 NORETURN
 void git_die_config_linenr(const char *key, const char *filename, int linenr)
 {
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index ab4da7f..de4b5ed 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2056,6 +2056,7 @@ _git_config ()
 		core.sparseCheckout
 		core.symlinks
 		core.trustctime
+		core.untrackedCache
 		core.warnAmbiguousRefs
 		core.whitespace
 		core.worktree
diff --git a/read-cache.c b/read-cache.c
index 5be7cd1..d9fb78b 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1519,6 +1519,28 @@ static void check_ce_order(struct index_state *istate)
 	}
 }
 
+static void tweak_untracked_cache(struct index_state *istate)
+{
+	switch (git_config_get_untracked_cache()) {
+	case -1: /* keep: do nothing */
+		break;
+	case 0: /* false */
+		remove_untracked_cache(istate);
+		break;
+	case 1: /* true */
+		add_untracked_cache(istate);
+		break;
+	default: /* unknown value: do nothing */
+		break;
+	}
+}
+
+static void post_read_index_from(struct index_state *istate)
+{
+	check_ce_order(istate);
+	tweak_untracked_cache(istate);
+}
+
 /* remember to discard_cache() before reading a different cache! */
 int do_read_index(struct index_state *istate, const char *path, int must_exist)
 {
@@ -1622,9 +1644,10 @@ int read_index_from(struct index_state *istate, const char *path)
 		return istate->cache_nr;
 
 	ret = do_read_index(istate, path, 0);
+
 	split_index = istate->split_index;
 	if (!split_index || is_null_sha1(split_index->base_sha1)) {
-		check_ce_order(istate);
+		post_read_index_from(istate);
 		return ret;
 	}
 
@@ -1642,7 +1665,7 @@ int read_index_from(struct index_state *istate, const char *path)
 			     sha1_to_hex(split_index->base_sha1)),
 		    sha1_to_hex(split_index->base->sha1));
 	merge_base_index(istate);
-	check_ce_order(istate);
+	post_read_index_from(istate);
 	return ret;
 }
 
diff --git a/t/t7063-status-untracked-cache.sh b/t/t7063-status-untracked-cache.sh
index 0e8d0d4..253160a 100755
--- a/t/t7063-status-untracked-cache.sh
+++ b/t/t7063-status-untracked-cache.sh
@@ -8,10 +8,8 @@ avoid_racy() {
 	sleep 1
 }
 
-# It's fine if git update-index returns an error code other than one,
-# it'll be caught in the first test.
 test_lazy_prereq UNTRACKED_CACHE '
-	{ git update-index --untracked-cache; ret=$?; } &&
+	{ git update-index --test-untracked-cache; ret=$?; } &&
 	test $ret -ne 1
 '
 
-- 
2.7.0.181.g07d31f8

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v8 10/11] test-dump-untracked-cache: don't modify the untracked cache
  2016-01-27  6:57 [PATCH v8 00/11] Untracked cache improvements Christian Couder
                   ` (8 preceding siblings ...)
  2016-01-27  6:58 ` [PATCH v8 09/11] config: add core.untrackedCache Christian Couder
@ 2016-01-27  6:58 ` Christian Couder
  2016-01-27  6:58 ` [PATCH v8 11/11] t7063: add tests for core.untrackedCache Christian Couder
  10 siblings, 0 replies; 16+ messages in thread
From: Christian Couder @ 2016-01-27  6:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Ævar Arnfjörð Bjarmason,
	Nguyen Thai Ngoc Duy, David Turner, Eric Sunshine,
	Torsten Bögershausen, Stefan Beller, Christian Couder

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>
---
 cache.h                     | 7 +++++++
 config.c                    | 4 ++++
 environment.c               | 7 +++++++
 test-dump-untracked-cache.c | 4 ++++
 4 files changed, 22 insertions(+)

diff --git a/cache.h b/cache.h
index e2900d1..69b08e9 100644
--- a/cache.h
+++ b/cache.h
@@ -1608,6 +1608,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;
diff --git a/config.c b/config.c
index 647a15e..b95ac3a 100644
--- 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;
 
diff --git a/environment.c b/environment.c
index 1cc4aab..6dec9d0 100644
--- a/environment.c
+++ b/environment.c
@@ -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;
diff --git a/test-dump-untracked-cache.c b/test-dump-untracked-cache.c
index 25d855d..0a1c285 100644
--- a/test-dump-untracked-cache.c
+++ b/test-dump-untracked-cache.c
@@ -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");
-- 
2.7.0.181.g07d31f8

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v8 11/11] t7063: add tests for core.untrackedCache
  2016-01-27  6:57 [PATCH v8 00/11] Untracked cache improvements Christian Couder
                   ` (9 preceding siblings ...)
  2016-01-27  6:58 ` [PATCH v8 10/11] test-dump-untracked-cache: don't modify the untracked cache Christian Couder
@ 2016-01-27  6:58 ` Christian Couder
  10 siblings, 0 replies; 16+ messages in thread
From: Christian Couder @ 2016-01-27  6:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Ævar Arnfjörð Bjarmason,
	Nguyen Thai Ngoc Duy, David Turner, Eric Sunshine,
	Torsten Bögershausen, Stefan Beller, Christian Couder

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 t/t7063-status-untracked-cache.sh | 85 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 81 insertions(+), 4 deletions(-)

diff --git a/t/t7063-status-untracked-cache.sh b/t/t7063-status-untracked-cache.sh
index 253160a..a971884 100755
--- a/t/t7063-status-untracked-cache.sh
+++ b/t/t7063-status-untracked-cache.sh
@@ -18,6 +18,10 @@ if ! test_have_prereq UNTRACKED_CACHE; then
 	test_done
 fi
 
+test_expect_success 'core.untrackedCache is unset' '
+	test_must_fail git config --get core.untrackedCache
+'
+
 test_expect_success 'setup' '
 	git init worktree &&
 	cd worktree &&
@@ -30,13 +34,13 @@ test_expect_success 'setup' '
 
 test_expect_success 'untracked cache is empty' '
 	test-dump-untracked-cache >../actual &&
-	cat >../expect <<EOF &&
+	cat >../expect-empty <<EOF &&
 info/exclude 0000000000000000000000000000000000000000
 core.excludesfile 0000000000000000000000000000000000000000
 exclude_per_dir .gitignore
 flags 00000006
 EOF
-	test_cmp ../expect ../actual
+	test_cmp ../expect-empty ../actual
 '
 
 cat >../status.expect <<EOF &&
@@ -506,7 +510,7 @@ EOF
 
 test_expect_success 'verify untracked cache dump (sparse/subdirs)' '
 	test-dump-untracked-cache >../actual &&
-	cat >../expect <<EOF &&
+	cat >../expect-from-test-dump <<EOF &&
 info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
 core.excludesfile 0000000000000000000000000000000000000000
 exclude_per_dir .gitignore
@@ -525,7 +529,7 @@ file
 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
 two
 EOF
-	test_cmp ../expect ../actual
+	test_cmp ../expect-from-test-dump ../actual
 '
 
 test_expect_success 'test sparse status again with untracked cache and subdir' '
@@ -569,4 +573,77 @@ EOF
 	test_cmp ../status.expect ../status.actual
 '
 
+test_expect_success '--no-untracked-cache removes the cache' '
+	git update-index --no-untracked-cache &&
+	test-dump-untracked-cache >../actual &&
+	echo "no untracked cache" >../expect-no-uc &&
+	test_cmp ../expect-no-uc ../actual
+'
+
+test_expect_success 'git status does not change anything' '
+	git status &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect-no-uc ../actual
+'
+
+test_expect_success 'setting core.untrackedCache to true and using git status creates the cache' '
+	git config core.untrackedCache true &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect-no-uc ../actual &&
+	git status &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect-from-test-dump ../actual
+'
+
+test_expect_success 'using --no-untracked-cache does not fail when core.untrackedCache is true' '
+	git update-index --no-untracked-cache &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect-no-uc ../actual &&
+	git update-index --untracked-cache &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect-empty ../actual
+'
+
+test_expect_success 'setting core.untrackedCache to false and using git status removes the cache' '
+	git config core.untrackedCache false &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect-empty ../actual &&
+	git status &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect-no-uc ../actual
+'
+
+test_expect_success 'using --untracked-cache does not fail when core.untrackedCache is false' '
+	git update-index --untracked-cache &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect-empty ../actual
+'
+
+test_expect_success 'setting core.untrackedCache to keep' '
+	git config core.untrackedCache keep &&
+	git update-index --untracked-cache &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect-empty ../actual &&
+	git status &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect-from-test-dump ../actual &&
+	git update-index --no-untracked-cache &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect-no-uc ../actual &&
+	git update-index --force-untracked-cache &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect-empty ../actual &&
+	git status &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect-from-test-dump ../actual
+'
+
+test_expect_success 'test ident field is working' '
+	mkdir ../other_worktree &&
+	cp -R done dthree dtwo four three ../other_worktree &&
+	GIT_WORK_TREE=../other_worktree git status 2>../err &&
+	echo "warning: Untracked cache is disabled on this system or location." >../expect &&
+	test_cmp ../expect ../err
+'
+
 test_done
-- 
2.7.0.181.g07d31f8

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v8 04/11] update-index: add untracked cache notifications
  2016-01-27  6:58 ` [PATCH v8 04/11] update-index: add untracked cache notifications Christian Couder
@ 2017-03-30  3:28   ` Jeff King
  2017-03-30  6:24     ` Christian Couder
  2017-03-30 17:33     ` Junio C Hamano
  0 siblings, 2 replies; 16+ messages in thread
From: Jeff King @ 2017-03-30  3:28 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Junio C Hamano, Ævar Arnfjörð Bjarmason,
	Nguyen Thai Ngoc Duy, David Turner, Eric Sunshine,
	Torsten Bögershausen, Stefan Beller, Christian Couder

On Wed, Jan 27, 2016 at 07:58:00AM +0100, Christian Couder wrote:

> diff --git a/builtin/update-index.c b/builtin/update-index.c
> index 62222dd..369c207 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());

Coverity points out that this is a leak (xgetcwd returns an allocated
buffer).

-Peff

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v8 04/11] update-index: add untracked cache notifications
  2017-03-30  3:28   ` Jeff King
@ 2017-03-30  6:24     ` Christian Couder
  2017-03-30 17:33     ` Junio C Hamano
  1 sibling, 0 replies; 16+ messages in thread
From: Christian Couder @ 2017-03-30  6:24 UTC (permalink / raw)
  To: Jeff King
  Cc: git, Junio C Hamano, Ævar Arnfjörð Bjarmason,
	Nguyen Thai Ngoc Duy, David Turner, Eric Sunshine,
	Torsten Bögershausen, Stefan Beller, Christian Couder

On Thu, Mar 30, 2017 at 5:28 AM, Jeff King <peff@peff.net> wrote:
> On Wed, Jan 27, 2016 at 07:58:00AM +0100, Christian Couder wrote:
>
>> diff --git a/builtin/update-index.c b/builtin/update-index.c
>> index 62222dd..369c207 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());
>
> Coverity points out that this is a leak (xgetcwd returns an allocated
> buffer).

Thanks!

http://public-inbox.org/git/20170330062208.29018-1-chriscool@tuxfamily.org/

should fix it.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v8 04/11] update-index: add untracked cache notifications
  2017-03-30  3:28   ` Jeff King
  2017-03-30  6:24     ` Christian Couder
@ 2017-03-30 17:33     ` Junio C Hamano
  2017-03-30 17:47       ` Stefan Beller
  1 sibling, 1 reply; 16+ messages in thread
From: Junio C Hamano @ 2017-03-30 17:33 UTC (permalink / raw)
  To: Jeff King
  Cc: Christian Couder, git, Ævar Arnfjörð Bjarmason,
	Nguyen Thai Ngoc Duy, David Turner, Eric Sunshine,
	Torsten Bögershausen, Stefan Beller, Christian Couder

Jeff King <peff@peff.net> writes:

> On Wed, Jan 27, 2016 at 07:58:00AM +0100, Christian Couder wrote:
>
>> diff --git a/builtin/update-index.c b/builtin/update-index.c
>> index 62222dd..369c207 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());
>
> Coverity points out that this is a leak (xgetcwd returns an allocated
> buffer).

I saw that quite recently and was wondering why it reported it this
late.  It has been in 'master' for more than a month.

In any case, thanks for noticing and I agree the fix in the other
message is obviously correct.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v8 04/11] update-index: add untracked cache notifications
  2017-03-30 17:33     ` Junio C Hamano
@ 2017-03-30 17:47       ` Stefan Beller
  0 siblings, 0 replies; 16+ messages in thread
From: Stefan Beller @ 2017-03-30 17:47 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Jeff King, Christian Couder, git@vger.kernel.org,
	Ævar Arnfjörð Bjarmason, Nguyen Thai Ngoc Duy,
	David Turner, Eric Sunshine, Torsten Bögershausen,
	Christian Couder

On Thu, Mar 30, 2017 at 10:33 AM, Junio C Hamano <gitster@pobox.com> wrote:
>>
>> Coverity points out that this is a leak (xgetcwd returns an allocated
>> buffer).
>
> I saw that quite recently and was wondering why it reported it this
> late.  It has been in 'master' for more than a month.

Because the repo/script for coverity was broken. It was missing
a hard reset, such that the merge conflict that occurred once upon
a time stayed in the repo and the checkout and merge of the newer
version did not succeed for quite some time.

I fixed it yesterday and will monitor the script more carefully now.

Stefan

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2017-03-30 17:47 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-27  6:57 [PATCH v8 00/11] Untracked cache improvements Christian Couder
2016-01-27  6:57 ` [PATCH v8 01/11] dir: free untracked cache when removing it Christian Couder
2016-01-27  6:57 ` [PATCH v8 02/11] update-index: use enum for untracked cache options Christian Couder
2016-01-27  6:57 ` [PATCH v8 03/11] update-index: add --test-untracked-cache Christian Couder
2016-01-27  6:58 ` [PATCH v8 04/11] update-index: add untracked cache notifications Christian Couder
2017-03-30  3:28   ` Jeff King
2017-03-30  6:24     ` Christian Couder
2017-03-30 17:33     ` Junio C Hamano
2017-03-30 17:47       ` Stefan Beller
2016-01-27  6:58 ` [PATCH v8 05/11] update-index: move 'uc' var declaration Christian Couder
2016-01-27  6:58 ` [PATCH v8 06/11] dir: add {new,add}_untracked_cache() Christian Couder
2016-01-27  6:58 ` [PATCH v8 07/11] dir: add remove_untracked_cache() Christian Couder
2016-01-27  6:58 ` [PATCH v8 08/11] dir: simplify untracked cache "ident" field Christian Couder
2016-01-27  6:58 ` [PATCH v8 09/11] config: add core.untrackedCache Christian Couder
2016-01-27  6:58 ` [PATCH v8 10/11] test-dump-untracked-cache: don't modify the untracked cache Christian Couder
2016-01-27  6:58 ` [PATCH v8 11/11] t7063: add tests for core.untrackedCache Christian Couder

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).