Skip to content

Commit 7c97174

Browse files
jeffhostetlergitster
authored andcommitted
fsmonitor: move untracked-cache invalidation into helper functions
Move the call to invalidate the untracked-cache for the FSEvent pathname into the two helper functions. In a later commit in this series, we will call these helpers from other contexts and it safer to include the UC invalidation in the helpers than to remember to also add it to each helper call-site. This has the side-effect of invalidating the UC *before* we invalidate the ce_flags in the cache-entry. These activities are independent and do not affect each other. Also, by doing the UC work first, we can avoid worrying about "early returns" or the need for the usual "goto the end" in each of the handler functions. Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 48f4cd7 commit 7c97174

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

fsmonitor.c

+19-7
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ static void handle_path_without_trailing_slash(
188188
{
189189
int i;
190190

191+
/*
192+
* Mark the untracked cache dirty for this path (regardless of
193+
* whether or not we find an exact match for it in the index).
194+
* Since the path is unqualified (no trailing slash hint in the
195+
* FSEvent), it may refer to a file or directory. So we should
196+
* not assume one or the other and should always let the untracked
197+
* cache decide what needs to invalidated.
198+
*/
199+
untracked_cache_invalidate_trimmed_path(istate, name, 0);
200+
191201
if (pos >= 0) {
192202
/*
193203
* We have an exact match for this path and can just
@@ -249,6 +259,15 @@ static void handle_path_with_trailing_slash(
249259
{
250260
int i;
251261

262+
/*
263+
* Mark the untracked cache dirty for this directory path
264+
* (regardless of whether or not we find an exact match for it
265+
* in the index or find it to be proper prefix of one or more
266+
* files in the index), since the FSEvent is hinting that
267+
* there may be changes on or within the directory.
268+
*/
269+
untracked_cache_invalidate_trimmed_path(istate, name, 0);
270+
252271
if (pos < 0)
253272
pos = -pos - 1;
254273

@@ -274,13 +293,6 @@ static void fsmonitor_refresh_callback(struct index_state *istate, char *name)
274293
} else {
275294
handle_path_without_trailing_slash(istate, name, pos);
276295
}
277-
278-
/*
279-
* Mark the untracked cache dirty even if it wasn't found in the index
280-
* as it could be a new untracked file. (Let the untracked cache
281-
* layer silently deal with any trailing slash.)
282-
*/
283-
untracked_cache_invalidate_trimmed_path(istate, name, 0);
284296
}
285297

286298
/*

0 commit comments

Comments
 (0)