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>
Ben Peart committed
Sep 22, 2017 at 12:35 UTC
9d406cba45c871e1a777e43b37eade36ef091528
1 file changed
+32
-1
builtin/update-index.c
+32
-1
@@ -33,6 +33,7 @@ static int force_remove;
33
static int verbose;
34
static int mark_valid_only;
35
static int mark_skip_worktree_only;
36
+static int mark_fsmonitor_only;
37
#define MARK_FLAG 1
38
#define UNMARK_FLAG 2
39
static struct strbuf mtime_dir = STRBUF_INIT;
@@ -229,12 +230,12 @@ static int mark_ce_flags(const char *path, int flag, int mark)
230
int namelen = strlen(path);
231
int pos = cache_name_pos(path, namelen);
232
if (0 <= pos) {
233
+ mark_fsmonitor_invalid(&the_index, active_cache[pos]);
234
if (mark)
235
active_cache[pos]->ce_flags |= flag;
236
else
237
active_cache[pos]->ce_flags &= ~flag;
238
active_cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;
237
- mark_fsmonitor_invalid(&the_index, active_cache[pos]);
239
cache_tree_invalidate_path(&the_index, path);
240
active_cache_changed |= CE_ENTRY_CHANGED;
241
return 0;
@@ -460,6 +461,11 @@ static void update_one(const char *path)
461
die("Unable to mark file %s", path);
462
return;
463
}
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
+ }
469
470
if (force_remove) {
471
if (remove_file_from_cache(path))
@@ -918,6 +924,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
924
int lock_error = 0;
925
int split_index = -1;
926
int force_write = 0;
927
+ int fsmonitor = -1;
928
struct lock_file *lock_file;
929
struct parse_opt_ctx_t ctx;
930
strbuf_getline_fn getline_fn;
@@ -1011,6 +1018,14 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1018
N_("enable untracked cache without testing the filesystem"), UC_FORCE),
1019
OPT_SET_INT(0, "force-write-index", &force_write,
1020
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},
1029
OPT_END()
1030
};
1031
@@ -1152,6 +1167,22 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1167
die("BUG: bad untracked_cache value: %d", untracked_cache);
1168
}
1169
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
+
1186
if (active_cache_changed || force_write) {
1187
if (newfd < 0) {
1188
if (refresh_args.flags & REFRESH_QUIET)