dir: create untracked_cache_invalidate_trimmed_path()
Create a wrapper function for untracked_cache_invalidate_path() that silently trims a trailing slash, if present, before calling the wrapped function. The untracked cache expects to be called with a pathname that does not contain a trailing slash. This can make it inconvenient for callers that have a directory path. Lets hide this complexity. This will be used by a later commit in the FSMonitor code which may receive directory pathnames from an FSEvent. Signed-off-by: Jeff Hostetler <jeffhostetler@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff Hostetler committed
Feb 26, 2024 at 21:39 UTC
3e4ffda6394082bcb7413b79cdc26fc4f8a52025
2 files changed
+27
dir.c
+20
@@ -3918,6 +3918,26 @@ void untracked_cache_invalidate_path(struct index_state *istate,
3918
path, strlen(path));
3919
}
3920
3921
+void untracked_cache_invalidate_trimmed_path(struct index_state *istate,
3922
+ const char *path,
3923
+ int safe_path)
3924
+{
3925
+ size_t len = strlen(path);
3926
+
3927
+ if (!len)
3928
+ BUG("untracked_cache_invalidate_trimmed_path given zero length path");
3929
+
3930
+ if (path[len - 1] != '/') {
3931
+ untracked_cache_invalidate_path(istate, path, safe_path);
3932
+ } else {
3933
+ struct strbuf tmp = STRBUF_INIT;
3934
+
3935
+ strbuf_add(&tmp, path, len - 1);
3936
+ untracked_cache_invalidate_path(istate, tmp.buf, safe_path);
3937
+ strbuf_release(&tmp);
3938
+ }
3939
+}
3940
+
3941
void untracked_cache_remove_from_index(struct index_state *istate,
3942
const char *path)
3943
{
dir.h
+7
@@ -576,6 +576,13 @@ int cmp_dir_entry(const void *p1, const void *p2);
576
int check_dir_entry_contains(const struct dir_entry *out, const struct dir_entry *in);
577
578
void untracked_cache_invalidate_path(struct index_state *, const char *, int safe_path);
579
+/*
580
+ * Invalidate the untracked-cache for this path, but first strip
581
+ * off a trailing slash, if present.
582
+ */
583
+void untracked_cache_invalidate_trimmed_path(struct index_state *,
584
+ const char *path,
585
+ int safe_path);
586
void untracked_cache_remove_from_index(struct index_state *, const char *);
587
void untracked_cache_add_to_index(struct index_state *, const char *);
588