summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bad4a54)
raw | patch | inline | side by side (parent: bad4a54)
author | Kjetil Barvik <barvik@broadpark.no> | |
Sun, 18 Jan 2009 15:14:53 +0000 (16:14 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 18 Jan 2009 21:58:31 +0000 (13:58 -0800) |
In some cases it could maybe be necessary to say to the cache that
"Hey, I deleted/changed the type of this pathname and if you currently
have it inside your cache, you should deleted it".
This patch introduce a function which support this.
Signed-off-by: Kjetil Barvik <barvik@broadpark.no>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
"Hey, I deleted/changed the type of this pathname and if you currently
have it inside your cache, you should deleted it".
This patch introduce a function which support this.
Signed-off-by: Kjetil Barvik <barvik@broadpark.no>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h | patch | blob | history | |
symlinks.c | patch | blob | history |
index 7c8c8e484259a69bdc2c75e9e820247b0df04d01..f4452a89a7cf8929e816319b04bb00323991a064 100644 (file)
--- a/cache.h
+++ b/cache.h
extern int has_symlink_leading_path(int len, const char *name);
extern int has_symlink_or_noent_leading_path(int len, const char *name);
extern int has_dirs_only_path(int len, const char *name, int prefix_len);
+extern void invalidate_lstat_cache(int len, const char *name);
extern struct alternate_object_database {
struct alternate_object_database *next;
diff --git a/symlinks.c b/symlinks.c
index 918e24ad9e76454a34ba0d958630558d55b56517..31ddbc9e9654994b8a779cc76fe3f16b717f029a 100644 (file)
--- a/symlinks.c
+++ b/symlinks.c
* Returns the length (on a path component basis) of the longest
* common prefix match of 'name' and the cached path string.
*/
-static inline int longest_match_lstat_cache(int len, const char *name)
+static inline int longest_match_lstat_cache(int len, const char *name,
+ int *previous_slash)
{
- int max_len, match_len = 0, i = 0;
+ int max_len, match_len = 0, match_len_prev = 0, i = 0;
max_len = len < cache.len ? len : cache.len;
while (i < max_len && name[i] == cache.path[i]) {
- if (name[i] == '/')
+ if (name[i] == '/') {
+ match_len_prev = match_len;
match_len = i;
+ }
i++;
}
/* Is the cached path string a substring of 'name'? */
- if (i == cache.len && cache.len < len && name[cache.len] == '/')
+ if (i == cache.len && cache.len < len && name[cache.len] == '/') {
+ match_len_prev = match_len;
match_len = cache.len;
/* Is 'name' a substring of the cached path string? */
- else if ((i == len && len < cache.len && cache.path[len] == '/') ||
- (i == len && len == cache.len))
+ } else if ((i == len && len < cache.len && cache.path[len] == '/') ||
+ (i == len && len == cache.len)) {
+ match_len_prev = match_len;
match_len = len;
+ }
+ *previous_slash = match_len_prev;
return match_len;
}
static int lstat_cache(int len, const char *name,
int track_flags, int prefix_len_stat_func)
{
- int match_len, last_slash, last_slash_dir;
+ int match_len, last_slash, last_slash_dir, previous_slash;
int match_flags, ret_flags, save_flags, max_len, ret;
struct stat st;
* Check to see if we have a match from the cache for
* the 2 "excluding" path types.
*/
- match_len = last_slash = longest_match_lstat_cache(len, name);
+ match_len = last_slash =
+ longest_match_lstat_cache(len, name, &previous_slash);
match_flags = cache.flags & track_flags & (FL_NOENT|FL_SYMLINK);
if (match_flags && match_len == cache.len)
return match_flags;
return ret_flags;
}
+/*
+ * Invalidate the given 'name' from the cache, if 'name' matches
+ * completely with the cache.
+ */
+void invalidate_lstat_cache(int len, const char *name)
+{
+ int match_len, previous_slash;
+
+ match_len = longest_match_lstat_cache(len, name, &previous_slash);
+ if (len == match_len) {
+ if ((cache.track_flags & FL_DIR) && previous_slash > 0) {
+ cache.path[previous_slash] = '\0';
+ cache.len = previous_slash;
+ cache.flags = FL_DIR;
+ } else
+ reset_lstat_cache(cache.track_flags,
+ cache.prefix_len_stat_func);
+ }
+}
+
#define USE_ONLY_LSTAT 0
/*