Skip to content

Commit 9d406cb

Browse files
benpeartgitster
authored andcommitted
update-index: add fsmonitor support to update-index
Add support in update-index to manually add/remove the fsmonitor extension via --[no-]fsmonitor flags. Add support in update-index to manually set/clear the fsmonitor valid bit via --[no-]fsmonitor-valid flags. Signed-off-by: Ben Peart <benpeart@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d8c71db commit 9d406cb

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

builtin/update-index.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ static int force_remove;
3333
static int verbose;
3434
static int mark_valid_only;
3535
static int mark_skip_worktree_only;
36+
static int mark_fsmonitor_only;
3637
#define MARK_FLAG 1
3738
#define UNMARK_FLAG 2
3839
static struct strbuf mtime_dir = STRBUF_INIT;
@@ -229,12 +230,12 @@ static int mark_ce_flags(const char *path, int flag, int mark)
229230
int namelen = strlen(path);
230231
int pos = cache_name_pos(path, namelen);
231232
if (0 <= pos) {
233+
mark_fsmonitor_invalid(&the_index, active_cache[pos]);
232234
if (mark)
233235
active_cache[pos]->ce_flags |= flag;
234236
else
235237
active_cache[pos]->ce_flags &= ~flag;
236238
active_cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;
237-
mark_fsmonitor_invalid(&the_index, active_cache[pos]);
238239
cache_tree_invalidate_path(&the_index, path);
239240
active_cache_changed |= CE_ENTRY_CHANGED;
240241
return 0;
@@ -460,6 +461,11 @@ static void update_one(const char *path)
460461
die("Unable to mark file %s", path);
461462
return;
462463
}
464+
if (mark_fsmonitor_only) {
465+
if (mark_ce_flags(path, CE_FSMONITOR_VALID, mark_fsmonitor_only == MARK_FLAG))
466+
die("Unable to mark file %s", path);
467+
return;
468+
}
463469

464470
if (force_remove) {
465471
if (remove_file_from_cache(path))
@@ -918,6 +924,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
918924
int lock_error = 0;
919925
int split_index = -1;
920926
int force_write = 0;
927+
int fsmonitor = -1;
921928
struct lock_file *lock_file;
922929
struct parse_opt_ctx_t ctx;
923930
strbuf_getline_fn getline_fn;
@@ -1011,6 +1018,14 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
10111018
N_("enable untracked cache without testing the filesystem"), UC_FORCE),
10121019
OPT_SET_INT(0, "force-write-index", &force_write,
10131020
N_("write out the index even if is not flagged as changed"), 1),
1021+
OPT_BOOL(0, "fsmonitor", &fsmonitor,
1022+
N_("enable or disable file system monitor")),
1023+
{OPTION_SET_INT, 0, "fsmonitor-valid", &mark_fsmonitor_only, NULL,
1024+
N_("mark files as fsmonitor valid"),
1025+
PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, MARK_FLAG},
1026+
{OPTION_SET_INT, 0, "no-fsmonitor-valid", &mark_fsmonitor_only, NULL,
1027+
N_("clear fsmonitor valid bit"),
1028+
PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, UNMARK_FLAG},
10141029
OPT_END()
10151030
};
10161031

@@ -1152,6 +1167,22 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11521167
die("BUG: bad untracked_cache value: %d", untracked_cache);
11531168
}
11541169

1170+
if (fsmonitor > 0) {
1171+
if (git_config_get_fsmonitor() == 0)
1172+
warning(_("core.fsmonitor is unset; "
1173+
"set it if you really want to "
1174+
"enable fsmonitor"));
1175+
add_fsmonitor(&the_index);
1176+
report(_("fsmonitor enabled"));
1177+
} else if (!fsmonitor) {
1178+
if (git_config_get_fsmonitor() == 1)
1179+
warning(_("core.fsmonitor is set; "
1180+
"remove it if you really want to "
1181+
"disable fsmonitor"));
1182+
remove_fsmonitor(&the_index);
1183+
report(_("fsmonitor disabled"));
1184+
}
1185+
11551186
if (active_cache_changed || force_write) {
11561187
if (newfd < 0) {
11571188
if (refresh_args.flags & REFRESH_QUIET)

0 commit comments

Comments
 (0)