git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v3 00/11] Untracked cache improvements
@ 2015-12-23 21:03 Christian Couder
  2015-12-23 21:03 ` [PATCH v3 01/11] dir: free untracked cache when removing it Christian Couder
                   ` (10 more replies)
  0 siblings, 11 replies; 18+ messages in thread
From: Christian Couder @ 2015-12-23 21:03 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, Christian Couder

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

This v3 still implements core.untrackedCache as a simple bool config
variable. When it's true, Git should always try to use the untracked
cache, and when false, Git should never use it.

Patch 1/11 is a small bugfix that has been moved to the start of the
series so it might get applied independently.

Patch 2/11 to 4/11 add some small features that are missing. They
haven't been changed since the previous series.

Patchs 5/11 to 8/11 are some refactoring to prepare for the following
patchs. Among them 7/11 is new, the others haven't changed.

Patch 9/11 replaces patch 10/10 in the previous series. It deals with
the "ident" field in "struct untracked_cache". As suggested by Junio,
we keep paying attention to the location of the work tree that is
stored in this field, but otherwise things are simplified a lot.

Patch 10/11 which adds core.untrackedCache, contains a few
simplifications compared to v2.

Patch 11/11 has not been changed.

So the changes compared to v2 are mostly small updates, and patchs
7/11 and 9/11.

The patch series is also available there:

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

Thanks to the reviewers and helpers.

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 add_untracked_cache()
  dir: add new_untracked_cache()
  dir: add remove_untracked_cache()
  dir: simplify untracked cache "ident" field
  config: add core.untrackedCache
  t7063: add tests for core.untrackedCache

 Documentation/config.txt               |  7 ++++
 Documentation/git-update-index.txt     | 61 ++++++++++++++++++++++++-----
 builtin/update-index.c                 | 54 ++++++++++++++------------
 cache.h                                |  1 +
 config.c                               |  4 ++
 contrib/completion/git-completion.bash |  1 +
 dir.c                                  | 70 ++++++++++++++++++++++++++++------
 dir.h                                  |  2 +
 environment.c                          |  1 +
 t/t7063-status-untracked-cache.sh      | 52 ++++++++++++++++++++++---
 wt-status.c                            |  5 +++
 11 files changed, 207 insertions(+), 51 deletions(-)

-- 
2.7.0.rc2.11.g68ccdd4

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

* [PATCH v3 01/11] dir: free untracked cache when removing it
  2015-12-23 21:03 [PATCH v3 00/11] Untracked cache improvements Christian Couder
@ 2015-12-23 21:03 ` Christian Couder
  2015-12-23 21:03 ` [PATCH v3 02/11] update-index: use enum for untracked cache options Christian Couder
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 18+ messages in thread
From: Christian Couder @ 2015-12-23 21:03 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, 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.rc2.11.g68ccdd4

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

* [PATCH v3 02/11] update-index: use enum for untracked cache options
  2015-12-23 21:03 [PATCH v3 00/11] Untracked cache improvements Christian Couder
  2015-12-23 21:03 ` [PATCH v3 01/11] dir: free untracked cache when removing it Christian Couder
@ 2015-12-23 21:03 ` Christian Couder
  2015-12-23 21:03 ` [PATCH v3 03/11] update-index: add --test-untracked-cache Christian Couder
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 18+ messages in thread
From: Christian Couder @ 2015-12-23 21:03 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, Christian Couder

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.rc2.11.g68ccdd4

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

* [PATCH v3 03/11] update-index: add --test-untracked-cache
  2015-12-23 21:03 [PATCH v3 00/11] Untracked cache improvements Christian Couder
  2015-12-23 21:03 ` [PATCH v3 01/11] dir: free untracked cache when removing it Christian Couder
  2015-12-23 21:03 ` [PATCH v3 02/11] update-index: use enum for untracked cache options Christian Couder
@ 2015-12-23 21:03 ` Christian Couder
  2015-12-23 21:03 ` [PATCH v3 04/11] update-index: add untracked cache notifications Christian Couder
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 18+ messages in thread
From: Christian Couder @ 2015-12-23 21:03 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, Christian Couder

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

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 Documentation/git-update-index.txt | 9 ++++++++-
 builtin/update-index.c             | 5 +++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt
index f4e5a85..a0ee0c9 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,13 @@ 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.
+
 --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.rc2.11.g68ccdd4

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

* [PATCH v3 04/11] update-index: add untracked cache notifications
  2015-12-23 21:03 [PATCH v3 00/11] Untracked cache improvements Christian Couder
                   ` (2 preceding siblings ...)
  2015-12-23 21:03 ` [PATCH v3 03/11] update-index: add --test-untracked-cache Christian Couder
@ 2015-12-23 21:03 ` Christian Couder
  2015-12-24 10:01   ` Duy Nguyen
  2015-12-23 21:03 ` [PATCH v3 05/11] update-index: move 'uc' var declaration Christian Couder
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 18+ messages in thread
From: Christian Couder @ 2015-12-23 21:03 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, 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.

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

diff --git a/builtin/update-index.c b/builtin/update-index.c
index 62222dd..c91e695 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,16 @@ 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;
+		if (verbose)
+			printf(_("Untracked cache enabled for '%s'\n"), 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;
+		}
+		if (verbose)
+			printf(_("Untracked cache disabled\n"));
 	}
 
 	if (active_cache_changed) {
-- 
2.7.0.rc2.11.g68ccdd4

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

* [PATCH v3 05/11] update-index: move 'uc' var declaration
  2015-12-23 21:03 [PATCH v3 00/11] Untracked cache improvements Christian Couder
                   ` (3 preceding siblings ...)
  2015-12-23 21:03 ` [PATCH v3 04/11] update-index: add untracked cache notifications Christian Couder
@ 2015-12-23 21:03 ` Christian Couder
  2015-12-23 21:03 ` [PATCH v3 06/11] dir: add add_untracked_cache() Christian Couder
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 18+ messages in thread
From: Christian Couder @ 2015-12-23 21:03 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, 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 c91e695..f667125 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.rc2.11.g68ccdd4

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

* [PATCH v3 06/11] dir: add add_untracked_cache()
  2015-12-23 21:03 [PATCH v3 00/11] Untracked cache improvements Christian Couder
                   ` (4 preceding siblings ...)
  2015-12-23 21:03 ` [PATCH v3 05/11] update-index: move 'uc' var declaration Christian Couder
@ 2015-12-23 21:03 ` Christian Couder
  2015-12-23 21:03 ` [PATCH v3 07/11] dir: add new_untracked_cache() Christian Couder
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 18+ messages in thread
From: Christian Couder @ 2015-12-23 21:03 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, Christian Couder

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

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

diff --git a/builtin/update-index.c b/builtin/update-index.c
index f667125..093725a 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();
 		if (verbose)
 			printf(_("Untracked cache enabled for '%s'\n"), get_git_work_tree());
 	} else if (untracked_cache == UC_DISABLE) {
diff --git a/dir.c b/dir.c
index d2a8f06..0f7e293 100644
--- a/dir.c
+++ b/dir.c
@@ -1938,6 +1938,20 @@ void add_untracked_ident(struct untracked_cache *uc)
 	strbuf_addch(&uc->ident, 0);
 }
 
+void add_untracked_cache(void)
+{
+	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;
+}
+
 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..ee94c76 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(void);
 #endif
-- 
2.7.0.rc2.11.g68ccdd4

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

* [PATCH v3 07/11] dir: add new_untracked_cache()
  2015-12-23 21:03 [PATCH v3 00/11] Untracked cache improvements Christian Couder
                   ` (5 preceding siblings ...)
  2015-12-23 21:03 ` [PATCH v3 06/11] dir: add add_untracked_cache() Christian Couder
@ 2015-12-23 21:03 ` Christian Couder
  2015-12-23 22:53   ` Eric Sunshine
  2015-12-23 21:03 ` [PATCH v3 08/11] dir: add remove_untracked_cache() Christian Couder
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 18+ messages in thread
From: Christian Couder @ 2015-12-23 21:03 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, Christian Couder

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

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 dir.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/dir.c b/dir.c
index 0f7e293..4227ba6 100644
--- a/dir.c
+++ b/dir.c
@@ -1938,16 +1938,20 @@ void add_untracked_ident(struct untracked_cache *uc)
 	strbuf_addch(&uc->ident, 0);
 }
 
+static void new_untracked_cache(void)
+{
+	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;
+}
+
 void add_untracked_cache(void)
 {
-	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;
-	}
+	if (!the_index.untracked)
+		new_untracked_cache();
 	add_untracked_ident(the_index.untracked);
 	the_index.cache_changed |= UNTRACKED_CHANGED;
 }
-- 
2.7.0.rc2.11.g68ccdd4

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

* [PATCH v3 08/11] dir: add remove_untracked_cache()
  2015-12-23 21:03 [PATCH v3 00/11] Untracked cache improvements Christian Couder
                   ` (6 preceding siblings ...)
  2015-12-23 21:03 ` [PATCH v3 07/11] dir: add new_untracked_cache() Christian Couder
@ 2015-12-23 21:03 ` Christian Couder
  2015-12-23 21:03 ` [PATCH v3 09/11] dir: simplify untracked cache "ident" field Christian Couder
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 18+ messages in thread
From: Christian Couder @ 2015-12-23 21:03 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, 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 093725a..3e5b4a6 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -1127,11 +1127,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
 		if (verbose)
 			printf(_("Untracked cache enabled for '%s'\n"), 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();
 		if (verbose)
 			printf(_("Untracked cache disabled\n"));
 	}
diff --git a/dir.c b/dir.c
index 4227ba6..dba1ad0 100644
--- a/dir.c
+++ b/dir.c
@@ -1956,6 +1956,15 @@ void add_untracked_cache(void)
 	the_index.cache_changed |= UNTRACKED_CHANGED;
 }
 
+void remove_untracked_cache(void)
+{
+	if (the_index.untracked) {
+		free_untracked_cache(the_index.untracked);
+		the_index.untracked = NULL;
+		the_index.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 ee94c76..3e5114d 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(void);
+void remove_untracked_cache(void);
 #endif
-- 
2.7.0.rc2.11.g68ccdd4

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

* [PATCH v3 09/11] dir: simplify untracked cache "ident" field
  2015-12-23 21:03 [PATCH v3 00/11] Untracked cache improvements Christian Couder
                   ` (7 preceding siblings ...)
  2015-12-23 21:03 ` [PATCH v3 08/11] dir: add remove_untracked_cache() Christian Couder
@ 2015-12-23 21:03 ` Christian Couder
  2015-12-23 21:03 ` [PATCH v3 10/11] config: add core.untrackedCache Christian Couder
  2015-12-23 21:03 ` [PATCH v3 11/11] t7063: add tests for core.untrackedCache Christian Couder
  10 siblings, 0 replies; 18+ messages in thread
From: Christian Couder @ 2015-12-23 21:03 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, 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 to decide if we should disable
it.

Also it's not useful to store many locations in the ident
field and compare to any of them. It can even 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.

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

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 dir.c | 49 ++++++++++++++++++++++++++++++++++---------------
 1 file changed, 34 insertions(+), 15 deletions(-)

diff --git a/dir.c b/dir.c
index dba1ad0..7596a3f 100644
--- a/dir.c
+++ b/dir.c
@@ -1918,23 +1918,36 @@ static const char *get_ident_string(void)
 	return sb.buf;
 }
 
-static int ident_in_untracked(const struct untracked_cache *uc)
+static int ident_current_location_in_untracked(const struct untracked_cache *uc)
 {
-	const char *end = uc->ident.buf + uc->ident.len;
-	const char *p   = uc->ident.buf;
+	struct strbuf cur_loc = STRBUF_INIT;
+	int res = 0;
 
-	for (p = uc->ident.buf; p < end; p += strlen(p) + 1)
-		if (!strcmp(p, get_ident_string()))
-			return 1;
-	return 0;
+	/*
+	 * Previous git versions may have saved many strings in the
+	 * "ident" field, but it is insane to manage many locations,
+	 * so just take care of the first one.
+	 */
+
+	strbuf_addf(&cur_loc, "Location %s, system ", get_git_work_tree());
+
+	if (starts_with(uc->ident.buf, cur_loc.buf))
+		res = 1;
+
+	strbuf_release(&cur_loc);
+
+	return res;
 }
 
-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);
 }
 
@@ -1945,15 +1958,21 @@ static void new_untracked_cache(void)
 	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(the_index.untracked);
 	the_index.untracked = uc;
+	the_index.cache_changed |= UNTRACKED_CHANGED;
 }
 
 void add_untracked_cache(void)
 {
-	if (!the_index.untracked)
+	if (!the_index.untracked) {
 		new_untracked_cache();
-	add_untracked_ident(the_index.untracked);
-	the_index.cache_changed |= UNTRACKED_CHANGED;
+	} else {
+		if (!ident_current_location_in_untracked(the_index.untracked)) {
+			free_untracked_cache(the_index.untracked);
+			new_untracked_cache();
+		}
+	}
 }
 
 void remove_untracked_cache(void)
@@ -2021,7 +2040,7 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
 	if (dir->exclude_list_group[EXC_CMDL].nr)
 		return NULL;
 
-	if (!ident_in_untracked(dir->untracked)) {
+	if (!ident_current_location_in_untracked(dir->untracked)) {
 		warning(_("Untracked cache is disabled on this system."));
 		return NULL;
 	}
-- 
2.7.0.rc2.11.g68ccdd4

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

* [PATCH v3 10/11] config: add core.untrackedCache
  2015-12-23 21:03 [PATCH v3 00/11] Untracked cache improvements Christian Couder
                   ` (8 preceding siblings ...)
  2015-12-23 21:03 ` [PATCH v3 09/11] dir: simplify untracked cache "ident" field Christian Couder
@ 2015-12-23 21:03 ` Christian Couder
  2015-12-24 10:13   ` Duy Nguyen
  2015-12-23 21:03 ` [PATCH v3 11/11] t7063: add tests for core.untrackedCache Christian Couder
  10 siblings, 1 reply; 18+ messages in thread
From: Christian Couder @ 2015-12-23 21:03 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, Christian Couder

When we know that mtime is fully supported by the environment, we
might want the untracked cache to be always used by default without
any mtime test or kernel version check being performed.

Also when we know that mtime is not supported by the environment,
for example because the repo is shared over a network file system,
then we might want 'git update-index --untracked-cache' to fail
immediately instead of performing tests (because it might work on
some systems using the repo over the network file system but not
others).

The normal way to achieve the above in Git is to use a config
variable. That's why this patch introduces "core.untrackedCache".

To keep things simple, this variable is a bool which default to
false.

When "git status" is run, it now adds or removes the untracked
cache in the index to respect the value of this variable.

The job of `git update-index --[no-|force-]untracked-cache` was
to add or remove the untracked cache from the index. This was a
kind of configuration because this was persistant across git
commands. To make this kind of configuration compatible with the
new config variable, the simple thing to do, and what this patch
does, is to make `git update-index --[no-|force-]untracked-cache`
set or unset this config option.

This new behavior is a backward incompatible change, but that is
deliberate. The untracked cache feature has been experimental
and is very unlikely used by beginners.

When people will upgrade, this will remove any untracked cache
they used unless they set "core.untrackedCache" before upgrading.
This should be stated in the release notes.

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
those tests take a long time and there is now
`--test-untracked-cache` to perform them.

That's why, to be more consistent with other git commands, this
patch prevents `--untracked-cache` to perform tests, so that
after this patch there is no difference any more between
`--untracked-cache` and `--force-untracked-cache`.

All the changes to `--[no-|force-]untracked-cache` make it
possible to deprecate those options in the future.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 Documentation/config.txt               |  7 ++++
 Documentation/git-update-index.txt     | 58 +++++++++++++++++++++++++++-------
 builtin/update-index.c                 | 15 +++++----
 cache.h                                |  1 +
 config.c                               |  4 +++
 contrib/completion/git-completion.bash |  1 +
 environment.c                          |  1 +
 t/t7063-status-untracked-cache.sh      |  4 +--
 wt-status.c                            |  5 +++
 9 files changed, 74 insertions(+), 22 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index f617886..08f0510 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -308,6 +308,13 @@ core.trustctime::
 	crawlers and some backup systems).
 	See linkgit:git-update-index[1]. True by default.
 
+core.untrackedCache::
+	Determines if untracked cache will be enabled. Using
+	'git update-index --[no-|force-]untracked-cache' will set
+	this variable. Before setting it to true, you should check
+	that mtime is working properly on your system.
+	See linkgit:git-update-index[1]. False 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 a0ee0c9..bab6394 100644
--- a/Documentation/git-update-index.txt
+++ b/Documentation/git-update-index.txt
@@ -174,24 +174,29 @@ 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 extension. Please use
+	`--test-untracked-cache` before enabling it.
++
+These options are mostly aliases for setting the `core.untrackedCache`
+configuration variable to 'true' or 'false' in the local config file
+(see linkgit:git-config[1]). You can equivalently just set those
+configuration values directly. These options are just provided for
+backwards compatibility with the older versions of Git where this was
+the only way to enable or disable the untracked cache extension.
 
 --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.
+	untracked cache using `--untracked-cache` or
+	`--force-untracked-cache` or the `core.untrackedCache`
+	configuration variable afterwards if you really want to use
+	it.
 
 --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.
@@ -382,6 +387,33 @@ 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 could 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.
+
+It is recommended to use the `core.untrackedCache` configuration
+variable (see linkgit:git-config[1]) to enable or disable this feature
+instead of using the `--[no-|force-]untracked-cache` which are going
+to set or unset this configuration variable anyway.
+
+When the `core.untrackedCache` configuration variable is changed, the
+untracked cache is added or removed from the index the next time "git
+status" is run, while when `--[no-|force-]untracked-cache` are used,
+the untracked cache is immediately added to the index.
 
 Configuration
 -------------
@@ -407,6 +439,8 @@ 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 is 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 3e5b4a6..9bb70dc 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -1115,18 +1115,19 @@ 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_TEST) {
+		setup_work_tree();
+		return !test_if_untracked_cache_is_supported();
+	}
 	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;
-		}
+		if (!use_untracked_cache && git_config_set("core.untrackedCache", "true"))
+			die("could not set core.untrackedCache to true");
 		add_untracked_cache();
 		if (verbose)
 			printf(_("Untracked cache enabled for '%s'\n"), get_git_work_tree());
 	} else if (untracked_cache == UC_DISABLE) {
+		if (use_untracked_cache && git_config_set("core.untrackedCache", "false"))
+			die("could not set core.untrackedCache to false");
 		remove_untracked_cache();
 		if (verbose)
 			printf(_("Untracked cache disabled\n"));
diff --git a/cache.h b/cache.h
index c63fcc1..8d09858 100644
--- a/cache.h
+++ b/cache.h
@@ -619,6 +619,7 @@ extern void set_alternate_index_output(const char *);
 /* Environment bits from configuration mechanism */
 extern int trust_executable_bit;
 extern int trust_ctime;
+extern int use_untracked_cache;
 extern int check_stat;
 extern int quote_path_fully;
 extern int has_symlinks;
diff --git a/config.c b/config.c
index 86a5eb2..b52916d 100644
--- a/config.c
+++ b/config.c
@@ -691,6 +691,10 @@ static int git_default_core_config(const char *var, const char *value)
 		trust_ctime = git_config_bool(var, value);
 		return 0;
 	}
+	if (!strcmp(var, "core.untrackedcache")) {
+		use_untracked_cache = git_config_bool(var, value);
+		return 0;
+	}
 	if (!strcmp(var, "core.checkstat")) {
 		if (!strcasecmp(value, "default"))
 			check_stat = 1;
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6956807..84bcec3 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2055,6 +2055,7 @@ _git_config ()
 		core.sparseCheckout
 		core.symlinks
 		core.trustctime
+		core.untrackedCache
 		core.warnAmbiguousRefs
 		core.whitespace
 		core.worktree
diff --git a/environment.c b/environment.c
index 2da7fe2..9ca71b1 100644
--- a/environment.c
+++ b/environment.c
@@ -14,6 +14,7 @@
 
 int trust_executable_bit = 1;
 int trust_ctime = 1;
+int use_untracked_cache;
 int check_stat = 1;
 int has_symlinks = 1;
 int minimum_abbrev = 4, default_abbrev = 7;
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
 '
 
diff --git a/wt-status.c b/wt-status.c
index bba2596..6766f80 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -578,6 +578,11 @@ static void wt_status_collect_untracked(struct wt_status *s)
 	if (!s->show_untracked_files)
 		return;
 
+	if (use_untracked_cache)
+		add_untracked_cache();
+	else
+		remove_untracked_cache();
+
 	memset(&dir, 0, sizeof(dir));
 	if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES)
 		dir.flags |=
-- 
2.7.0.rc2.11.g68ccdd4

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

* [PATCH v3 11/11] t7063: add tests for core.untrackedCache
  2015-12-23 21:03 [PATCH v3 00/11] Untracked cache improvements Christian Couder
                   ` (9 preceding siblings ...)
  2015-12-23 21:03 ` [PATCH v3 10/11] config: add core.untrackedCache Christian Couder
@ 2015-12-23 21:03 ` Christian Couder
  10 siblings, 0 replies; 18+ messages in thread
From: Christian Couder @ 2015-12-23 21:03 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, Christian Couder

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

diff --git a/t/t7063-status-untracked-cache.sh b/t/t7063-status-untracked-cache.sh
index 253160a..f0af41c 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 &&
@@ -28,6 +32,11 @@ test_expect_success 'setup' '
 	git update-index --untracked-cache
 '
 
+test_expect_success 'core.untrackedCache is true' '
+	UC=$(git config core.untrackedCache) &&
+	test "$UC" = "true"
+'
+
 test_expect_success 'untracked cache is empty' '
 	test-dump-untracked-cache >../actual &&
 	cat >../expect <<EOF &&
@@ -506,7 +515,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 +534,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 +578,39 @@ EOF
 	test_cmp ../status.expect ../status.actual
 '
 
+test_expect_success '--no-untracked-cache removes the cache' '
+	git update-index --no-untracked-cache &&
+	UC=$(git config core.untrackedCache) &&
+	test "$UC" = "false" &&
+	test-dump-untracked-cache >../actual &&
+	echo "no untracked cache" >../expect &&
+	test_cmp ../expect ../actual
+'
+
+test_expect_success 'git status does not change anything' '
+	git status &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect ../actual &&
+	UC=$(git config core.untrackedCache) &&
+	test "$UC" = "false"
+'
+
+test_expect_success 'setting core.untrackedCache and using git status creates the cache' '
+	git config core.untrackedCache true &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect ../actual &&
+	git status &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect-from-test-dump ../actual
+'
+
+test_expect_success 'unsetting core.untrackedCache and using git status removes the cache' '
+	git config --unset core.untrackedCache &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect-from-test-dump ../actual &&
+	git status &&
+	test-dump-untracked-cache >../actual &&
+	test_cmp ../expect ../actual
+'
+
 test_done
-- 
2.7.0.rc2.11.g68ccdd4

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

* Re: [PATCH v3 07/11] dir: add new_untracked_cache()
  2015-12-23 21:03 ` [PATCH v3 07/11] dir: add new_untracked_cache() Christian Couder
@ 2015-12-23 22:53   ` Eric Sunshine
  2015-12-24  7:35     ` Christian Couder
  0 siblings, 1 reply; 18+ messages in thread
From: Eric Sunshine @ 2015-12-23 22:53 UTC (permalink / raw
  To: Christian Couder
  Cc: Git List, Junio C Hamano, Jeff King,
	Ævar Arnfjörð Bjarmason, Nguyen Thai Ngoc Duy,
	David Turner, Torsten Bögershausen, Christian Couder

On Wed, Dec 23, 2015 at 4:03 PM, Christian Couder
<christian.couder@gmail.com> wrote:
>     Factor out code into new_untracked_cache(), which will be used
>     multiple times in a later commit.

Odd indentation: s/^\s+//

> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---
> diff --git a/dir.c b/dir.c
> @@ -1938,16 +1938,20 @@ void add_untracked_ident(struct untracked_cache *uc)
>         strbuf_addch(&uc->ident, 0);
>  }
>
> +static void new_untracked_cache(void)
> +{
> +       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;
> +}

This and the previous patch both move the same code around. As a
reviewer, I could easily see the two patches combined, and would not
find the unified patch onerous to review.

>  void add_untracked_cache(void)
>  {
> -       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;
> -       }
> +       if (!the_index.untracked)
> +               new_untracked_cache();
>         add_untracked_ident(the_index.untracked);
>         the_index.cache_changed |= UNTRACKED_CHANGED;
>  }
> --
> 2.7.0.rc2.11.g68ccdd4

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

* Re: [PATCH v3 07/11] dir: add new_untracked_cache()
  2015-12-23 22:53   ` Eric Sunshine
@ 2015-12-24  7:35     ` Christian Couder
  0 siblings, 0 replies; 18+ messages in thread
From: Christian Couder @ 2015-12-24  7:35 UTC (permalink / raw
  To: Eric Sunshine
  Cc: Git List, Junio C Hamano, Jeff King,
	Ævar Arnfjörð Bjarmason, Nguyen Thai Ngoc Duy,
	David Turner, Torsten Bögershausen, Christian Couder

On Wed, Dec 23, 2015 at 11:53 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
> On Wed, Dec 23, 2015 at 4:03 PM, Christian Couder
> <christian.couder@gmail.com> wrote:
>>     Factor out code into new_untracked_cache(), which will be used
>>     multiple times in a later commit.
>
> Odd indentation: s/^\s+//

Yeah, will fix.

>> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
>> ---
>> diff --git a/dir.c b/dir.c
>> @@ -1938,16 +1938,20 @@ void add_untracked_ident(struct untracked_cache *uc)
>>         strbuf_addch(&uc->ident, 0);
>>  }
>>
>> +static void new_untracked_cache(void)
>> +{
>> +       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;
>> +}
>
> This and the previous patch both move the same code around. As a
> reviewer, I could easily see the two patches combined, and would not
> find the unified patch onerous to review.

Ok, I will squash them.

By the way it looks like I have overlooked some reviews by David and
Tosten from the previous round.
Sorry about that. I will take them into account in the next version.

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

* Re: [PATCH v3 04/11] update-index: add untracked cache notifications
  2015-12-23 21:03 ` [PATCH v3 04/11] update-index: add untracked cache notifications Christian Couder
@ 2015-12-24 10:01   ` Duy Nguyen
  2015-12-24 21:11     ` Christian Couder
  0 siblings, 1 reply; 18+ messages in thread
From: Duy Nguyen @ 2015-12-24 10:01 UTC (permalink / raw
  To: Christian Couder
  Cc: Git Mailing List, Junio C Hamano, Jeff King,
	Ævar Arnfjörð Bjarmason, David Turner,
	Eric Sunshine, Torsten Bögershausen, Christian Couder

On Thu, Dec 24, 2015 at 4:03 AM, Christian Couder
<christian.couder@gmail.com> wrote:
> 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.
>
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---
>  builtin/update-index.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/builtin/update-index.c b/builtin/update-index.c
> index 62222dd..c91e695 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,16 @@ 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;
> +               if (verbose)
> +                       printf(_("Untracked cache enabled for '%s'\n"), get_git_work_tree());

Nit. If you use report(), then you can skip "if (verbose)" because
it's done inside report().

> +       } 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;
> +               }
> +               if (verbose)
> +                       printf(_("Untracked cache disabled\n"));
>         }
>
>         if (active_cache_changed) {
> --
> 2.7.0.rc2.11.g68ccdd4
>
-- 
Duy

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

* Re: [PATCH v3 10/11] config: add core.untrackedCache
  2015-12-23 21:03 ` [PATCH v3 10/11] config: add core.untrackedCache Christian Couder
@ 2015-12-24 10:13   ` Duy Nguyen
  2015-12-24 21:10     ` Christian Couder
  0 siblings, 1 reply; 18+ messages in thread
From: Duy Nguyen @ 2015-12-24 10:13 UTC (permalink / raw
  To: Christian Couder
  Cc: Git Mailing List, Junio C Hamano, Jeff King,
	Ævar Arnfjörð Bjarmason, David Turner,
	Eric Sunshine, Torsten Bögershausen, Christian Couder

On Thu, Dec 24, 2015 at 4:03 AM, Christian Couder
<christian.couder@gmail.com> wrote:
>  --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.

Nit. The reason --force-untracked-cache remains can probably stay in
the commit message. Here we can simply say "synonym of
--untracked-cache, deprecated" or something like that (or even ".. to
be deleted in version N.M").
-- 
Duy

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

* Re: [PATCH v3 10/11] config: add core.untrackedCache
  2015-12-24 10:13   ` Duy Nguyen
@ 2015-12-24 21:10     ` Christian Couder
  0 siblings, 0 replies; 18+ messages in thread
From: Christian Couder @ 2015-12-24 21:10 UTC (permalink / raw
  To: Duy Nguyen
  Cc: Git Mailing List, Junio C Hamano, Jeff King,
	Ævar Arnfjörð Bjarmason, David Turner,
	Eric Sunshine, Torsten Bögershausen, Christian Couder

On Thu, Dec 24, 2015 at 11:13 AM, Duy Nguyen <pclouds@gmail.com> wrote:
> On Thu, Dec 24, 2015 at 4:03 AM, Christian Couder
> <christian.couder@gmail.com> wrote:
>>  --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.
>
> Nit. The reason --force-untracked-cache remains can probably stay in
> the commit message. Here we can simply say "synonym of
> --untracked-cache, deprecated" or something like that (or even ".. to
> be deleted in version N.M").

Yeah, I think "deprecated" should be enough and clearer, but I will
see with AEvar who helped me on this.

Thanks,
Christian.

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

* Re: [PATCH v3 04/11] update-index: add untracked cache notifications
  2015-12-24 10:01   ` Duy Nguyen
@ 2015-12-24 21:11     ` Christian Couder
  0 siblings, 0 replies; 18+ messages in thread
From: Christian Couder @ 2015-12-24 21:11 UTC (permalink / raw
  To: Duy Nguyen
  Cc: Git Mailing List, Junio C Hamano, Jeff King,
	Ævar Arnfjörð Bjarmason, David Turner,
	Eric Sunshine, Torsten Bögershausen, Christian Couder

On Thu, Dec 24, 2015 at 11:01 AM, Duy Nguyen <pclouds@gmail.com> wrote:
> On Thu, Dec 24, 2015 at 4:03 AM, Christian Couder
> <christian.couder@gmail.com> wrote:
>> @@ -1135,10 +1135,16 @@ 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;
>> +               if (verbose)
>> +                       printf(_("Untracked cache enabled for '%s'\n"), get_git_work_tree());
>
> Nit. If you use report(), then you can skip "if (verbose)" because
> it's done inside report().

Ok, will do.

Thanks,
Christian.

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

end of thread, other threads:[~2015-12-24 21:11 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-23 21:03 [PATCH v3 00/11] Untracked cache improvements Christian Couder
2015-12-23 21:03 ` [PATCH v3 01/11] dir: free untracked cache when removing it Christian Couder
2015-12-23 21:03 ` [PATCH v3 02/11] update-index: use enum for untracked cache options Christian Couder
2015-12-23 21:03 ` [PATCH v3 03/11] update-index: add --test-untracked-cache Christian Couder
2015-12-23 21:03 ` [PATCH v3 04/11] update-index: add untracked cache notifications Christian Couder
2015-12-24 10:01   ` Duy Nguyen
2015-12-24 21:11     ` Christian Couder
2015-12-23 21:03 ` [PATCH v3 05/11] update-index: move 'uc' var declaration Christian Couder
2015-12-23 21:03 ` [PATCH v3 06/11] dir: add add_untracked_cache() Christian Couder
2015-12-23 21:03 ` [PATCH v3 07/11] dir: add new_untracked_cache() Christian Couder
2015-12-23 22:53   ` Eric Sunshine
2015-12-24  7:35     ` Christian Couder
2015-12-23 21:03 ` [PATCH v3 08/11] dir: add remove_untracked_cache() Christian Couder
2015-12-23 21:03 ` [PATCH v3 09/11] dir: simplify untracked cache "ident" field Christian Couder
2015-12-23 21:03 ` [PATCH v3 10/11] config: add core.untrackedCache Christian Couder
2015-12-24 10:13   ` Duy Nguyen
2015-12-24 21:10     ` Christian Couder
2015-12-23 21:03 ` [PATCH v3 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).