Skip to content

Commit 80c8bb3

Browse files
committed
Merge branch 'av/fsmonitor-updates' into pu
Code clean-up on fsmonitor integration, plus optional utilization of the fsmonitor data in diff-files. * av/fsmonitor-updates: fsmonitor: use fsmonitor data in `git diff` fsmonitor: remove debugging lines from t/t7519-status-fsmonitor.sh fsmonitor: make output of test-dump-fsmonitor more concise fsmonitor: update helper tool, now that flags are filled later fsmonitor: stop inline'ing mark_fsmonitor_valid / _invalid dir.c: update comments to match argument name
2 parents 714c9f2 + fa49029 commit 80c8bb3

File tree

9 files changed

+52
-26
lines changed

9 files changed

+52
-26
lines changed

builtin/add.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ int add_files_to_cache(const char *prefix,
119119
rev.diffopt.format_callback_data = &data;
120120
rev.diffopt.flags.override_submodule_config = 1;
121121
rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
122-
run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
122+
run_diff_files(&rev, DIFF_RACY_IS_MODIFIED | DIFF_SKIP_FSMONITOR);
123123
clear_pathspec(&rev.prune_data);
124124
return !!data.add_errors;
125125
}

config.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,8 +2282,13 @@ int git_config_get_fsmonitor(void)
22822282
if (core_fsmonitor && !*core_fsmonitor)
22832283
core_fsmonitor = NULL;
22842284

2285-
if (core_fsmonitor)
2286-
return 1;
2285+
2286+
if (core_fsmonitor) {
2287+
if (!strcasecmp(core_fsmonitor, "keep"))
2288+
return -1;
2289+
else
2290+
return 1;
2291+
}
22872292

22882293
return 0;
22892294
}

diff-lib.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
9696

9797
diff_set_mnemonic_prefix(&revs->diffopt, "i/", "w/");
9898

99+
if (!(option & DIFF_SKIP_FSMONITOR))
100+
refresh_fsmonitor(&the_index);
101+
99102
if (diff_unmerged_stage < 0)
100103
diff_unmerged_stage = 2;
101104
entries = active_nr;
@@ -198,6 +201,9 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
198201
if (ce_uptodate(ce) || ce_skip_worktree(ce))
199202
continue;
200203

204+
if (ce->ce_flags & CE_FSMONITOR_VALID && !(option & DIFF_SKIP_FSMONITOR))
205+
continue;
206+
201207
/* If CE_VALID is set, don't look at workdir for file removal */
202208
if (ce->ce_flags & CE_VALID) {
203209
changed = 0;

diff.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ extern const char *diff_aligned_abbrev(const struct object_id *sha1, int);
416416
#define DIFF_SILENT_ON_REMOVED 01
417417
/* report racily-clean paths as modified */
418418
#define DIFF_RACY_IS_MODIFIED 02
419+
/* skip loading the fsmonitor data */
420+
#define DIFF_SKIP_FSMONITOR 04
419421
extern int run_diff_files(struct rev_info *revs, unsigned int option);
420422
extern int run_diff_index(struct rev_info *revs, int cached);
421423

dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,9 +798,9 @@ static int add_excludes_from_buffer(char *buf, size_t size,
798798
* an index if 'istate' is non-null), parse it and store the
799799
* exclude rules in "el".
800800
*
801-
* If "ss" is not NULL, compute SHA-1 of the exclude file and fill
801+
* If sha1_stat is not NULL, compute SHA-1 of the exclude file and fill
802802
* stat data from disk (only valid if add_excludes returns zero). If
803-
* ss_valid is non-zero, "ss" must contain good value as input.
803+
* sha1_stat.valid is non-zero, sha1_stat must contain good value as input.
804804
*/
805805
static int add_excludes(const char *fname, const char *base, int baselen,
806806
struct exclude_list *el, struct index_state *istate,

fsmonitor.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,24 @@ void refresh_fsmonitor(struct index_state *istate)
191191
istate->fsmonitor_last_update = last_update;
192192
}
193193

194+
void mark_fsmonitor_valid(struct cache_entry *ce)
195+
{
196+
if (core_fsmonitor) {
197+
ce->ce_flags |= CE_FSMONITOR_VALID;
198+
trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_clean '%s'", ce->name);
199+
}
200+
}
201+
202+
void mark_fsmonitor_invalid(struct index_state *istate, struct cache_entry *ce)
203+
{
204+
if (core_fsmonitor) {
205+
ce->ce_flags &= ~CE_FSMONITOR_VALID;
206+
untracked_cache_invalidate_path(istate, ce->name, 1);
207+
trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_invalid '%s'", ce->name);
208+
}
209+
}
210+
211+
194212
void add_fsmonitor(struct index_state *istate)
195213
{
196214
int i;

fsmonitor.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,7 @@ extern void refresh_fsmonitor(struct index_state *istate);
4646
* called any time the cache entry has been updated to reflect the
4747
* current state of the file on disk.
4848
*/
49-
static inline void mark_fsmonitor_valid(struct cache_entry *ce)
50-
{
51-
if (core_fsmonitor) {
52-
ce->ce_flags |= CE_FSMONITOR_VALID;
53-
trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_clean '%s'", ce->name);
54-
}
55-
}
49+
extern void mark_fsmonitor_valid(struct cache_entry *ce);
5650

5751
/*
5852
* Clear the given cache entry's CE_FSMONITOR_VALID bit and invalidate
@@ -61,13 +55,6 @@ static inline void mark_fsmonitor_valid(struct cache_entry *ce)
6155
* trigger an lstat() or invalidate the untracked cache for the
6256
* corresponding directory
6357
*/
64-
static inline void mark_fsmonitor_invalid(struct index_state *istate, struct cache_entry *ce)
65-
{
66-
if (core_fsmonitor) {
67-
ce->ce_flags &= ~CE_FSMONITOR_VALID;
68-
untracked_cache_invalidate_path(istate, ce->name, 1);
69-
trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_invalid '%s'", ce->name);
70-
}
71-
}
58+
extern void mark_fsmonitor_invalid(struct index_state *istate, struct cache_entry *ce);
7259

7360
#endif

t/helper/test-dump-fsmonitor.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
#include "cache.h"
2+
#include "config.h"
23

34
int cmd_main(int ac, const char **av)
45
{
56
struct index_state *istate = &the_index;
6-
int i;
7+
uint64_t now = getnanotime();
8+
int i, valid = 0;
79

10+
git_config_push_parameter("core.fsmonitor=keep");
811
setup_git_directory();
9-
if (do_read_index(istate, get_index_file(), 0) < 0)
12+
if (read_index_from(istate, get_index_file(), get_git_dir()) < 0)
1013
die("unable to read index file");
1114
if (!istate->fsmonitor_last_update) {
1215
printf("no fsmonitor\n");
1316
return 0;
1417
}
15-
printf("fsmonitor last update %"PRIuMAX"\n", (uintmax_t)istate->fsmonitor_last_update);
18+
19+
printf("fsmonitor last update %"PRIuMAX", (%.2f seconds ago)\n",
20+
(uintmax_t)istate->fsmonitor_last_update,
21+
(now - istate->fsmonitor_last_update)/1.0e9);
1622

1723
for (i = 0; i < istate->cache_nr; i++)
18-
printf((istate->cache[i]->ce_flags & CE_FSMONITOR_VALID) ? "+" : "-");
24+
if (istate->cache[i]->ce_flags & CE_FSMONITOR_VALID)
25+
valid++;
26+
27+
printf(" valid: %d\n", valid);
28+
printf(" invalid: %d\n", istate->cache_nr - valid);
1929

2030
return 0;
2131
}

t/t7519-status-fsmonitor.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,7 @@ test_expect_success 'splitting the index results in the same state' '
307307
dirty_repo &&
308308
git update-index --fsmonitor &&
309309
git ls-files -f >expect &&
310-
test-dump-fsmonitor >&2 && echo &&
311310
git update-index --fsmonitor --split-index &&
312-
test-dump-fsmonitor >&2 && echo &&
313311
git ls-files -f >actual &&
314312
test_cmp expect actual
315313
'

0 commit comments

Comments
 (0)