Re: [PATCH 07/12] fsmonitor: refactor untracked-cache invalidation
From: Patrick Steinhardt <hidden>
Date: 2024-02-15 09:32:39
On Tue, Feb 13, 2024 at 08:52:16PM +0000, Jeff Hostetler via GitGitGadget wrote:
From: Jeff Hostetler <redacted> Signed-off-by: Jeff Hostetler <redacted>
Junio already mentioned that this change does more than a mere refactoring, which leaves the reader puzzled a bit.
quoted hunk ↗ jump to hunk
--- fsmonitor.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-)diff --git a/fsmonitor.c b/fsmonitor.c index 754fe20cfd0..14585b6c516 100644 --- a/fsmonitor.c +++ b/fsmonitor.c@@ -183,11 +183,35 @@ static int query_fsmonitor_hook(struct repository *r, return result; } +/* + * Invalidate the untracked cache for the given pathname. Copy the + * buffer to a proper null-terminated string (since the untracked + * cache code does not use (buf, len) style argument). Also strip any + * trailing slash. + */ +static void my_invalidate_untracked_cache( + struct index_state *istate, const char *name, int len) +{ + struct strbuf work_path = STRBUF_INIT; + + if (!len) + return; + + if (name[len-1] == '/') + len--; + + strbuf_add(&work_path, name, len); + untracked_cache_invalidate_path(istate, work_path.buf, 0); + strbuf_release(&work_path); +} + static void fsmonitor_refresh_callback_unqualified( struct index_state *istate, const char *name, int len, int pos) { int i; + my_invalidate_untracked_cache(istate, name, len); + if (pos >= 0) { /* * We have an exact match for this path and can just@@ -253,6 +277,8 @@ static int fsmonitor_refresh_callback_slash( int i; int nr_in_cone = 0; + my_invalidate_untracked_cache(istate, name, len); + if (pos < 0) pos = -pos - 1;@@ -278,21 +304,9 @@ static void fsmonitor_refresh_callback(struct index_state *istate, char *name) if (name[len - 1] == '/') { fsmonitor_refresh_callback_slash(istate, name, len, pos); - - /* - * We need to remove the traling "/" from the path - * for the untracked cache. - */ - name[len - 1] = '\0'; } else { fsmonitor_refresh_callback_unqualified(istate, name, len, pos); }
We can drop the braces here as both branches are now single-line statements. Patrick
- - /* - * Mark the untracked cache dirty even if it wasn't found in the index - * as it could be a new untracked file. - */ - untracked_cache_invalidate_path(istate, name, 0); } /* -- gitgitgadget
Attachments
- signature.asc [application/pgp-signature] 833 bytes