Code

mergetool--lib: simplify guess_merge_tool()
[git.git] / symlinks.c
index 08ad35330f38aeec17c11223fc4c145d573f6739..7b0a86d35776e8695423c13403c9f4fa3465017d 100644 (file)
@@ -32,13 +32,7 @@ static int longest_path_match(const char *name_a, int len_a,
        return match_len;
 }
 
-static struct cache_def {
-       char path[PATH_MAX + 1];
-       int len;
-       int flags;
-       int track_flags;
-       int prefix_len_stat_func;
-} default_cache;
+static struct cache_def default_cache;
 
 static inline void reset_lstat_cache(struct cache_def *cache)
 {
@@ -97,6 +91,10 @@ static int lstat_cache(struct cache_def *cache, const char *name, int len,
                        longest_path_match(name, len, cache->path, cache->len,
                                           &previous_slash);
                match_flags = cache->flags & track_flags & (FL_NOENT|FL_SYMLINK);
+
+               if (!(track_flags & FL_FULLPATH) && match_len == len)
+                       match_len = last_slash = previous_slash;
+
                if (match_flags && match_len == cache->len)
                        return match_flags;
                /*
@@ -214,15 +212,20 @@ void clear_lstat_cache(void)
 
 #define USE_ONLY_LSTAT  0
 
+/*
+ * Return non-zero if path 'name' has a leading symlink component
+ */
+int threaded_has_symlink_leading_path(struct cache_def *cache, const char *name, int len)
+{
+       return lstat_cache(cache, name, len, FL_SYMLINK|FL_DIR, USE_ONLY_LSTAT) & FL_SYMLINK;
+}
+
 /*
  * Return non-zero if path 'name' has a leading symlink component
  */
 int has_symlink_leading_path(const char *name, int len)
 {
-       struct cache_def *cache = &default_cache;       /* FIXME */
-       return lstat_cache(cache, name, len,
-                          FL_SYMLINK|FL_DIR, USE_ONLY_LSTAT) &
-               FL_SYMLINK;
+       return threaded_has_symlink_leading_path(&default_cache, name, len);
 }
 
 /*