Skip to contentSkip to conversation

Minor fsmonitor bugfixes, use with `git diff`

PATCH Superseded Alex Vandiver 3 participants 16 messages Dec 19, 2017 – Dec 21, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Minor fsmonitor bugfixes, use with `git diff`

This cleans up some mistakes I introduced in my previous series, and switches git diff to use the fsmonitor data.

I've noticed that git checkout HEAD drops the fsmonitor data, which surprises me -- the following patch "fixes" that but broke tests, so there's something I clearly don't understand yet going on here:

unpack-trees.c +1 -0
@@ -1262,6 +1262,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
        o->result.timestamp.nsec = o->src_index->timestamp.nsec;
        o->result.version = o->src_index->version;
        o->result.split_index = o->src_index->split_index;
+       o->result.fsmonitor_last_update = o->src_index->fsmonitor_last_update;
        if (o->result.split_index)
                o->result.split_index->refcount++;
        hashcpy(o->result.sha1, o->src_index->sha1);

- Alex

#1 lore raw

PATCH 1/6 Fix comments to agree with argument name

---
 dir.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
dir.c +2 -2
index 7c4b45e30..cf05b1da0 100644
@@ -790,9 +790,9 @@ static int add_excludes_from_buffer(char *buf, size_t size,
  * an index if 'istate' is non-null), parse it and store the
  * exclude rules in "el".
  *
- * If "ss" is not NULL, compute SHA-1 of the exclude file and fill
+ * If sha1_stat is not NULL, compute SHA-1 of the exclude file and fill
  * stat data from disk (only valid if add_excludes returns zero). If
- * ss_valid is non-zero, "ss" must contain good value as input.
+ * sha1_stat.valid is non-zero, sha1_stat must contain good value as input.
  */
 static int add_excludes(const char *fname, const char *base, int baselen,
 			struct exclude_list *el,
Signature · 1 line
2.15.1.626.gc4617b774
#2 lore raw

PATCH 2/6 fsmonitor: Add dir.h include, for untracked_cache_invalidate_path

In reply to Alex Vandiver

This missing include is currently hidden by dint of the fact that dir.h is already included by all things that currently include fsmonitor.h

---
 fsmonitor.h | 1 +
 1 file changed, 1 insertion(+)
fsmonitor.h +1 -0
index cd3cc0ccf..5f68ca4d2 100644
@@ -1,5 +1,6 @@
 #ifndef FSMONITOR_H
 #define FSMONITOR_H
+#include "dir.h"
 
 extern struct trace_key trace_fsmonitor;
 
Signature · 1 line
2.15.1.626.gc4617b774
#3 lore raw

Re: [PATCH 2/6] fsmonitor: Add dir.h include, for untracked_cache_invalidate_path

Quoted 1 line · Alex Vandiver

Subject: Re: [PATCH 2/6] fsmonitor: Add dir.h include, for untracked_cache_invalidate_path

Perhaps

"Subject: fsmonitor.h: include dir.h"

But I am not sure if this is a right direction to go in. If a .C user of fsmonitor needs (does not need) things from dir.h, that file can (does not need to) include dir.h itself.

I think this header does excessive "static inline" as premature optimization, so a better "fix" to your perceived problem may be to make them not "static inline".

Quoted 21 lines

This missing include is currently hidden by dint of the fact that dir.h is already included by all things that currently include fsmonitor.h

---

 fsmonitor.h | 1 +
 1 file changed, 1 insertion(+)
fsmonitor.h +1 -0
index cd3cc0ccf..5f68ca4d2 100644
@@ -1,5 +1,6 @@
 #ifndef FSMONITOR_H
 #define FSMONITOR_H
+#include "dir.h"
 
 extern struct trace_key trace_fsmonitor;
#4 lore raw

Re: [PATCH 2/6] fsmonitor: Add dir.h include, for untracked_cache_invalidate_path

Quoted 7 lines · Junio C Hamano
Quoted 1 line · Alex Vandiver

Subject: Re: [PATCH 2/6] fsmonitor: Add dir.h include, for untracked_cache_invalidate_path

Perhaps

"Subject: fsmonitor.h: include dir.h"

Certainly more concise.

Quoted 3 lines

But I am not sure if this is a right direction to go in. If a .C user of fsmonitor needs (does not need) things from dir.h, that file can (does not need to) include dir.h itself.

Hm; I was patterning based on existing .h files, which don't seem shy about pulling in other .h files.

Quoted 3 lines

I think this header does excessive "static inline" as premature optimization, so a better "fix" to your perceived problem may be to make them not "static inline".

Yeah, quite possibly. Ben, do you recall your rationale for inlining them in 6a6da08f6 ("fsmonitor: teach git to optionally utilize a file system monitor to speed up detecting new or changed files.", 2017-09-22) ?

- Alex

#5 lore raw

Re: [PATCH 2/6] fsmonitor: Add dir.h include, for untracked_cache_invalidate_path

Quoted 6 lines · Alex Vandiver
Quoted 3 lines

But I am not sure if this is a right direction to go in. If a .C user of fsmonitor needs (does not need) things from dir.h, that file can (does not need to) include dir.h itself.

Hm; I was patterning based on existing .h files, which don't seem shy about pulling in other .h files.

IIUC, existing X.h do pull in Y.h when X.h uses a structure or a typedef defined in Y.h (but using pointer to such a structure or a type does not count) defined in Y.h; in such a case, a user of X.h that wants to use what is defined in X.h would not be able to use it without somehow knowing the shape of such a structure or type and would be forced to pull in Y.h itself. "static inline" falls into the same category---as it stands, anybody that includes fsmonitor.h and wants to use one of these static inline functions would need to have definitions from dir.h, which I agree is wrong and I understand that you want to include dir.h there.

#6 lore raw

PATCH 3/6 fsmonitor: Update helper tool, now that flags are filled later

In reply to Alex Vandiver

dd9005a0a ("fsmonitor: delay updating state until after split index is merged", 2017-10-27) began deferring the setting of the CE_FSMONITOR_VALID flag until later, such that do_read_index() does not perform those steps. This means that t/helper/test-dump-fsmonitor showed all bits as always unset.

Split out the code which inflates the ewah into CE_FSMONITOR_VALID bits, and call that from t/helper/test-dump-fsmonitor. We cannot simply switch the code to call read_index_from or the more specific tweak_fsmonitor, because the latter would modify the extension state by calling add_fsmonitor.

---
 fsmonitor.c                    | 9 ++++++++-
 fsmonitor.h                    | 6 ++++++
 t/helper/test-dump-fsmonitor.c | 2 ++
 3 files changed, 16 insertions(+), 1 deletion(-)
fsmonitor.c +8 -1
index 0af7c4edb..7011dff15 100644
@@ -227,7 +227,7 @@ void remove_fsmonitor(struct index_state *istate)
 	}
 }
 
-void tweak_fsmonitor(struct index_state *istate)
+void inflate_fsmonitor_ewah(struct index_state *istate)
 {
 	int i;
 	int fsmonitor_enabled = git_config_get_fsmonitor();
@@ -250,6 +250,13 @@ void tweak_fsmonitor(struct index_state *istate)
 		ewah_free(istate->fsmonitor_dirty);
 		istate->fsmonitor_dirty = NULL;
 	}
+}
+
+void tweak_fsmonitor(struct index_state *istate)
+{
+	int fsmonitor_enabled = git_config_get_fsmonitor();
+
+	inflate_fsmonitor_ewah(istate);
 
 	switch (fsmonitor_enabled) {
 	case -1: /* keep: do nothing */
fsmonitor.h +6 -0
index 5f68ca4d2..619852d4b 100644
@@ -28,6 +28,12 @@ extern void write_fsmonitor_extension(struct strbuf *sb, struct index_state *ist
 extern void add_fsmonitor(struct index_state *istate);
 extern void remove_fsmonitor(struct index_state *istate);
 
+/*
+ * Inflate the fsmonitor_dirty ewah into the CE_FSMONITOR_VALID bits.
+ * Called by tweak_fsmonitor.
+ */
+extern void inflate_fsmonitor_ewah(struct index_state *istate);
+
 /*
  * Add/remove the fsmonitor index extension as necessary based on the current
  * core.fsmonitor setting.
t/helper/test-dump-fsmonitor.c +2 -0
index ad452707e..53b19b39b 100644
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "fsmonitor.h"
 
 int cmd_main(int ac, const char **av)
 {
@@ -8,6 +9,7 @@ int cmd_main(int ac, const char **av)
 	setup_git_directory();
 	if (do_read_index(istate, get_index_file(), 0) < 0)
 		die("unable to read index file");
+	inflate_fsmonitor_ewah(istate);
 	if (!istate->fsmonitor_last_update) {
 		printf("no fsmonitor\n");
 		return 0;
Signature · 1 line
2.15.1.626.gc4617b774
#7 lore raw

Re: [PATCH 3/6] fsmonitor: Update helper tool, now that flags are filled later

Quoted 5 lines · Alex Vandiver

dd9005a0a ("fsmonitor: delay updating state until after split index is merged", 2017-10-27) began deferring the setting of the CE_FSMONITOR_VALID flag until later, such that do_read_index() does not perform those steps. This means that t/helper/test-dump-fsmonitor showed all bits as always unset.

This isn't the right fix, actually. With split indexes, this puts us right back into "only shows a few bits" territory, because do_read_index doesn't know about split indexes.

Which means we need a way to do the whole index load but _not_ add/remove the fsmonitor cache, even if the config says to do so.

The best I'm coming up with is the below -- but I'm not happy with it, because 'keep' is meaningless as a configuration value outside of testing, since it's normally treated as an executable path. This uses the fact that fsmonitor.c currently has a:

        switch (fsmonitor_enabled) {
        case -1: /* keep: do nothing */
                break;

...despite get_config_get_fsmonitor() havong no way to return -1 at present.

Is this sort of testing generally done via environment variables, rather than magic config values?
- Alex

---------------------8<----------------

config.c +7 -2
index 6fb06c213..75fcf1a52 100644
@@ -2164,8 +2164,13 @@ int git_config_get_fsmonitor(void)
        if (core_fsmonitor && !*core_fsmonitor)
                core_fsmonitor = NULL;
 
-       if (core_fsmonitor)
-               return 1;
+
+       if (core_fsmonitor) {
+               if (!strcasecmp(core_fsmonitor, "keep"))
+                       return -1;
+               else
+                       return 1;
+       }
 
        return 0;
 }
t/helper/test-dump-fsmonitor.c +2 -1
index ad452707e..12e131530 100644
@@ -5,8 +5,9 @@ int cmd_main(int ac, const char **av)
        struct index_state *istate = &the_index;
        int i;
 
+       git_config_push_parameter("core.fsmonitor=keep");
        setup_git_directory();
-       if (do_read_index(istate, get_index_file(), 0) < 0)
+       if (read_index_from(istate, get_index_file()) < 0)
                die("unable to read index file");
        if (!istate->fsmonitor_last_update) {
                printf("no fsmonitor\n");

-----------------8<---------------------

#8 lore raw

PATCH 4/6 fsmonitor: Add a trailing newline to test-dump-fsmonitor

In reply to Alex Vandiver

This makes it more readable when used for debugging from the commandline.

---
 t/helper/test-dump-fsmonitor.c | 1 +
 1 file changed, 1 insertion(+)
t/helper/test-dump-fsmonitor.c +1 -0
index 53b19b39b..4e56929f7 100644
@@ -19,5 +19,6 @@ int cmd_main(int ac, const char **av)
 	for (i = 0; i < istate->cache_nr; i++)
 		printf((istate->cache[i]->ce_flags & CE_FSMONITOR_VALID) ? "+" : "-");
 
+	printf("\n");
 	return 0;
 }
Signature · 1 line
2.15.1.626.gc4617b774
#9 lore raw

Re: [PATCH 4/6] fsmonitor: Add a trailing newline to test-dump-fsmonitor

Quoted 1 line · Alex Vandiver

Subject: Re: [PATCH 4/6] fsmonitor: Add a trailing newline to test-dump-fsmonitor

"Subject: fsmonitor: complete the last line of test-dump-fsmonitor output"

perhaps.

Quoted 13 lines

This makes it more readable when used for debugging from the commandline.

---
 t/helper/test-dump-fsmonitor.c | 1 +
 1 file changed, 1 insertion(+)
t/helper/test-dump-fsmonitor.c +0 -0
index 53b19b39b..4e56929f7 100644

t/helper/test-dump-fsmonitor.c int cmd_main(int ac, const char **av) · line 22

Quoted 4 lines
t/helper/test-dump-fsmonitor.c +1 -0
@@ -19,5 +19,6 @@ int cmd_main(int ac, const char **av)
 	for (i = 0; i < istate->cache_nr; i++)
 		printf((istate->cache[i]->ce_flags & CE_FSMONITOR_VALID) ? "+" : "-");
 
+	printf("\n");

That (and existing) uses of printf() all feel a bit overkill ;-) Perhaps putchar() would suffice.

I am not sure if the above wants to become something like

	for (i = 0; i < istate->cache_nr; i++) {
        	putchar(istate->cache[i]->ce_flags & CE_FSMONITOR_VALID ? '+' : '-');
		quote_c_style(istate->cache[i]->name, NULL, stdout, 0);
		putchar('\n');
	}

instead of "a single long incomplete line" in the first place. Your "fix" merely turns it into "a single long complete line", which does not quite feel big enough an improvement, at least to me.

Quoted 2 lines
t/helper/test-dump-fsmonitor.c +0 -0
 	return 0;
 }
#10 lore raw

Re: [PATCH 4/6] fsmonitor: Add a trailing newline to test-dump-fsmonitor

Quoted 11 lines · Junio C Hamano

That (and existing) uses of printf() all feel a bit overkill ;-) Perhaps putchar() would suffice.

I am not sure if the above wants to become something like

	for (i = 0; i < istate->cache_nr; i++) {
        	putchar(istate->cache[i]->ce_flags & CE_FSMONITOR_VALID ? '+' : '-');
		quote_c_style(istate->cache[i]->name, NULL, stdout, 0);
		putchar('\n');
	}
Quoted 3 lines

instead of "a single long incomplete line" in the first place. Your "fix" merely turns it into "a single long complete line", which does not quite feel big enough an improvement, at least to me.

The more user-digestable form like you describe already exists by way of git ls-files -f. I am not sure it is worth replicating it.

The only current uses of this tool are in tests, which only examine the first ("no fsmonitor" / "fsmonitor last update ...") line. I find it useful as a brief summary view of the fsmonitor bits, but I suppose I'd also be happy with just presence/absence and a count of set/unset bits.

Barring objections from Dscho or Ben, I'll reroll with a version that shows something like:

fsmonitor last update 1513821151547101894 (5 seconds ago) 5 files valid / 10 files invalid

- Alex

#11 lore raw

Re: [PATCH 4/6] fsmonitor: Add a trailing newline to test-dump-fsmonitor

Quoted 11 lines · Alex Vandiver

The only current uses of this tool are in tests, which only examine the first ("no fsmonitor" / "fsmonitor last update ...") line. I find it useful as a brief summary view of the fsmonitor bits, but I suppose I'd also be happy with just presence/absence and a count of set/unset bits.

Barring objections from Dscho or Ben, I'll reroll with a version that shows something like:

fsmonitor last update 1513821151547101894 (5 seconds ago) 5 files valid / 10 files invalid

As I agree that this is test/debug only, I do not care too deeply either way, as long as it does not end with an incomplete line ;-)

#12 lore raw

PATCH 5/6 fsmonitor: Remove debugging lines from t/t7519-status-fsmonitor.sh

In reply to Alex Vandiver

These were mistakenly left in when the test was introduced, in 1487372d3 ("fsmonitor: store fsmonitor bitmap before splitting index", 2017-11-09)

---
 t/t7519-status-fsmonitor.sh | 2 --
 1 file changed, 2 deletions(-)
t/t7519-status-fsmonitor.sh +0 -2
index eb2d13bbc..19b2a0a0f 100755
@@ -307,9 +307,7 @@ test_expect_success 'splitting the index results in the same state' '
 	dirty_repo &&
 	git update-index --fsmonitor  &&
 	git ls-files -f >expect &&
-	test-dump-fsmonitor >&2 && echo &&
 	git update-index --fsmonitor --split-index &&
-	test-dump-fsmonitor >&2 && echo &&
 	git ls-files -f >actual &&
 	test_cmp expect actual
 '
Signature · 1 line
2.15.1.626.gc4617b774
#13 lore raw

Re: [PATCH 5/6] fsmonitor: Remove debugging lines from t/t7519-status-fsmonitor.sh

Quoted 14 lines · Alex Vandiver

These were mistakenly left in when the test was introduced, in 1487372d3 ("fsmonitor: store fsmonitor bitmap before splitting index", 2017-11-09)

---
 t/t7519-status-fsmonitor.sh | 2 --
 1 file changed, 2 deletions(-)
t/t7519-status-fsmonitor.sh +0 -0
index eb2d13bbc..19b2a0a0f 100755

t/t7519-status-fsmonitor.sh test_expect_success 'splitting the index results in the same state' ' · line 313

Quoted 9 lines
t/t7519-status-fsmonitor.sh +0 -2
@@ -307,9 +307,7 @@ test_expect_success 'splitting the index results in the same state' '
 	dirty_repo &&
 	git update-index --fsmonitor  &&
 	git ls-files -f >expect &&
-	test-dump-fsmonitor >&2 && echo &&
 	git update-index --fsmonitor --split-index &&
-	test-dump-fsmonitor >&2 && echo &&
 	git ls-files -f >actual &&
 	test_cmp expect actual
 '

Hmph, by default the standard output and standard error streams are not shown in the test output, and it would help while debugging test failures, so I am not sure if this is a good change. With the previous step [4/6], we can lose the "echo", of course, and I do not think we need >&2 redirection there, either.

#14 lore raw

Re: [PATCH 5/6] fsmonitor: Remove debugging lines from t/t7519-status-fsmonitor.sh

Hi Junio,

Quoted 23 lines · Junio C Hamano
Quoted 21 lines · Alex Vandiver

These were mistakenly left in when the test was introduced, in 1487372d3 ("fsmonitor: store fsmonitor bitmap before splitting index", 2017-11-09)

---
 t/t7519-status-fsmonitor.sh | 2 --
 1 file changed, 2 deletions(-)
t/t7519-status-fsmonitor.sh +0 -2
index eb2d13bbc..19b2a0a0f 100755
@@ -307,9 +307,7 @@ test_expect_success 'splitting the index results in the same state' '
 	dirty_repo &&
 	git update-index --fsmonitor  &&
 	git ls-files -f >expect &&
-	test-dump-fsmonitor >&2 && echo &&
 	git update-index --fsmonitor --split-index &&
-	test-dump-fsmonitor >&2 && echo &&
 	git ls-files -f >actual &&
Quoted 8 lines

t/t7519-status-fsmonitor.sh test_expect_success 'splitting the index results in the same state' ' · line 313

Quoted 2 lines
t/t7519-status-fsmonitor.sh +0 -0
 	test_cmp expect actual
 '

Hmph, by default the standard output and standard error streams are not shown in the test output, and it would help while debugging test failures, so I am not sure if this is a good change. With the previous step [4/6], we can lose the "echo", of course, and I do not think we need >&2 redirection there, either.

I think you got it backwards. Sure, this helps debugging, but it hurts runtime of the entire test suite (which I might have happened to mention a couple of times takes way too long on Windows, thanks to our choice of test "framework").

And in the bigger picture, I think that it is very, very easy to insert those debugging statements when something breaks (we have to do that with other tests, anyways).

So I am in favor of this patch, and disagree with your assessment, Junio.

Ciao,
Dscho

#15 lore raw

PATCH 6/6 fsmonitor: Use fsmonitor data in `git diff`

In reply to Alex Vandiver

With fsmonitor enabled, the first call to match_stat_with_submodule calls refresh_fsmonitor, incurring the overhead of reading the list of updated files -- but run_diff_files does not respect the CE_FSMONITOR_VALID flag.

Make use of the fsmonitor extension to skip lstat() calls on files that fsmonitor judged as unmodified. Skip use of the fsmonitor extension when called by "add", as the format_callback in such cases expects to be called even when the file is believed to be "up to date" with the index.

Notably, this change improves performance of the git shell prompt when GIT_PS1_SHOWDIRTYSTATE is set.

---
 builtin/add.c | 2 +-
 diff-lib.c    | 6 ++++++
 diff.h        | 2 ++
 3 files changed, 9 insertions(+), 1 deletion(-)
builtin/add.c +1 -1
index bf01d89e2..bba20b46e 100644
@@ -119,7 +119,7 @@ int add_files_to_cache(const char *prefix,
 	rev.diffopt.format_callback_data = &data;
 	rev.diffopt.flags.override_submodule_config = 1;
 	rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
-	run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
+	run_diff_files(&rev, DIFF_RACY_IS_MODIFIED | DIFF_SKIP_FSMONITOR);
 	clear_pathspec(&rev.prune_data);
 	return !!data.add_errors;
 }
diff-lib.c +6 -0
index 8104603a3..13ff00d81 100644
@@ -95,6 +95,9 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 
 	diff_set_mnemonic_prefix(&revs->diffopt, "i/", "w/");
 
+	if (!(option & DIFF_SKIP_FSMONITOR))
+		refresh_fsmonitor(&the_index);
+
 	if (diff_unmerged_stage < 0)
 		diff_unmerged_stage = 2;
 	entries = active_nr;
@@ -197,6 +200,9 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 		if (ce_uptodate(ce) || ce_skip_worktree(ce))
 			continue;
 
+		if (ce->ce_flags & CE_FSMONITOR_VALID && !(option & DIFF_SKIP_FSMONITOR))
+			continue;
+
 		/* If CE_VALID is set, don't look at workdir for file removal */
 		if (ce->ce_flags & CE_VALID) {
 			changed = 0;
diff.h +2 -0
index 36a09624f..1060bc495 100644
@@ -395,6 +395,8 @@ extern const char *diff_aligned_abbrev(const struct object_id *sha1, int);
 #define DIFF_SILENT_ON_REMOVED 01
 /* report racily-clean paths as modified */
 #define DIFF_RACY_IS_MODIFIED 02
+/* skip loading the fsmonitor data */
+#define DIFF_SKIP_FSMONITOR 04
 extern int run_diff_files(struct rev_info *revs, unsigned int option);
 extern int run_diff_index(struct rev_info *revs, int cached);
 
Signature · 1 line
2.15.1.626.gc4617b774