Add threaded versions of functions in symlinks.c.
check_leading_path() and has_dirs_only_path() both always use the default cache, which could be a caveat for adding parallelism (which is a concern and even a GSoC proposal). Reimplement these two in terms of new threaded_check_leading_path() and threaded_has_dirs_only_path() that take their own copy of the cache. Signed-off-by: Jared Hance <jaredhance@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jared Hance committed
Mar 2, 2012 at 21:31 UTC
15438d5a56acfd08545a11630821179334eb6979
2 files changed
+28
-2
cache.h
+2
@@ -950,7 +950,9 @@ struct cache_def {
950
extern int has_symlink_leading_path(const char *name, int len);
951
extern int threaded_has_symlink_leading_path(struct cache_def *, const char *, int);
952
extern int check_leading_path(const char *name, int len);
953
+extern int threaded_check_leading_path(struct cache_def *cache, const char *name, int len);
954
extern int has_dirs_only_path(const char *name, int len, int prefix_len);
955
+extern int threaded_has_dirs_only_path(struct cache_def *cache, const char *name, int len, int prefix_len);
956
extern void schedule_dir_for_removal(const char *name, int len);
957
extern void remove_scheduled_dirs(void);
958
symlinks.c
+26
-2
@@ -219,7 +219,20 @@ int has_symlink_leading_path(const char *name, int len)
219
*/
220
int check_leading_path(const char *name, int len)
221
{
222
- struct cache_def *cache = &default_cache; /* FIXME */
222
+ return threaded_check_leading_path(&default_cache, name, len);
223
+}
224
+
225
+/*
226
+ * Return zero if path 'name' has a leading symlink component or
227
+ * if some leading path component does not exists.
228
+ *
229
+ * Return -1 if leading path exists and is a directory.
230
+ *
231
+ * Return path length if leading path exists and is neither a
232
+ * directory nor a symlink.
233
+ */
234
+int threaded_check_leading_path(struct cache_def *cache, const char *name, int len)
235
+{
236
int flags;
237
int match_len = lstat_cache_matchlen(cache, name, len, &flags,
238
FL_SYMLINK|FL_NOENT|FL_DIR, USE_ONLY_LSTAT);
@@ -240,7 +253,18 @@ int check_leading_path(const char *name, int len)
253
*/
254
int has_dirs_only_path(const char *name, int len, int prefix_len)
255
{
243
- struct cache_def *cache = &default_cache; /* FIXME */
256
+ return threaded_has_dirs_only_path(&default_cache, name, len, prefix_len);
257
+}
258
+
259
+/*
260
+ * Return non-zero if all path components of 'name' exists as a
261
+ * directory. If prefix_len > 0, we will test with the stat()
262
+ * function instead of the lstat() function for a prefix length of
263
+ * 'prefix_len', thus we then allow for symlinks in the prefix part as
264
+ * long as those points to real existing directories.
265
+ */
266
+int threaded_has_dirs_only_path(struct cache_def *cache, const char *name, int len, int prefix_len)
267
+{
268
return lstat_cache(cache, name, len,
269
FL_DIR|FL_FULLPATH, prefix_len) &
270
FL_DIR;