From 09c9306658f793f2cad1ed7856b55a7c4e758703 Mon Sep 17 00:00:00 2001 From: Kjetil Barvik Date: Sun, 18 Jan 2009 16:14:51 +0100 Subject: lstat_cache(): introduce has_symlink_or_noent_leading_path() function In some cases, especially inside the unpack-trees.c file, and inside the verify_absent() function, we can avoid some unnecessary calls to lstat(), if the lstat_cache() function can also be told to keep track of non-existing directories. So we update the lstat_cache() function to handle this new fact, introduce a new wrapper function, and the result is that we save lots of lstat() calls for a removed directory which previously contained lots of files, when we call this new wrapper of lstat_cache() instead of the old one. We do similar changes inside the unlink_entry() function, since if we can already say that the leading directory component of a pathname does not exist, it is not necessary to try to remove a pathname below it! Thanks to Junio C Hamano, Linus Torvalds and Rene Scharfe for valuable comments to this patch! Signed-off-by: Kjetil Barvik Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 231c06d772..11181aa007 100644 --- a/cache.h +++ b/cache.h @@ -720,6 +720,7 @@ struct checkout { extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath); 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 struct alternate_object_database { struct alternate_object_database *next; -- cgit v1.2.1 From bad4a54fa6fe8a9bbdfb5c3e413268eefde69b75 Mon Sep 17 00:00:00 2001 From: Kjetil Barvik Date: Sun, 18 Jan 2009 16:14:52 +0100 Subject: lstat_cache(): introduce has_dirs_only_path() function The create_directories() function in entry.c currently calls stat() or lstat() for each path component of the pathname 'path' each and every time. For the 'git checkout' command, this function is called on each file for which we must do an update (ce->ce_flags & CE_UPDATE), so we get lots and lots of calls. To fix this, we make a new wrapper to the lstat_cache() function, and call the wrapper function instead of the calls to the stat() or the lstat() functions. Since the paths given to the create_directories() function, is sorted alphabetically, the new wrapper would be very cache effective in this situation. To support it we must update the lstat_cache() function to be able to say that "please test the complete length of 'name'", and also to give it the length of a prefix, where the cache should use the stat() function instead of the lstat() function to test each path component. Thanks to Junio C Hamano, Linus Torvalds and Rene Scharfe for valuable comments to this patch! Signed-off-by: Kjetil Barvik Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 11181aa007..7c8c8e4842 100644 --- a/cache.h +++ b/cache.h @@ -721,6 +721,7 @@ struct checkout { extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath); 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 struct alternate_object_database { struct alternate_object_database *next; -- cgit v1.2.1 From aeabab5c712d5acae4a2836272d641acbb87b893 Mon Sep 17 00:00:00 2001 From: Kjetil Barvik Date: Sun, 18 Jan 2009 16:14:53 +0100 Subject: lstat_cache(): introduce invalidate_lstat_cache() function 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 Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 7c8c8e4842..f4452a89a7 100644 --- a/cache.h +++ b/cache.h @@ -722,6 +722,7 @@ extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, 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; -- cgit v1.2.1 From bda6eb0da9b4e4e763b531c83cab9fd9f85934ff Mon Sep 17 00:00:00 2001 From: Kjetil Barvik Date: Sun, 18 Jan 2009 16:14:54 +0100 Subject: lstat_cache(): introduce clear_lstat_cache() function If you want to completely clear the contents of the lstat_cache(), then call this new function. Signed-off-by: Kjetil Barvik Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index f4452a89a7..468daf6a43 100644 --- a/cache.h +++ b/cache.h @@ -723,6 +723,7 @@ 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 void clear_lstat_cache(void); extern struct alternate_object_database { struct alternate_object_database *next; -- cgit v1.2.1