Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Barvik <barvik@broadpark.no>2009-02-09 23:54:07 +0300
committerJunio C Hamano <gitster@pobox.com>2009-02-10 07:59:26 +0300
commit7847892716a3c9a7b8facc076fc056ac425bcfe6 (patch)
tree623746d79fbe18a0e2d32f67dfe6bb523ca8e8be /symlinks.c
parent571998921d8fd4ee674545406aabb86987921252 (diff)
unlink_entry(): introduce schedule_dir_for_removal()
Currently inside unlink_entry() if we get a successful removal of one file with unlink(), we try to remove the leading directories each and every time. So if one directory containing 200 files is moved to an other location we get 199 failed calls to rmdir() and 1 successful call. To fix this and avoid some unnecessary calls to rmdir(), we schedule each directory for removal and wait much longer before we do the real call to rmdir(). Since the unlink_entry() function is called with alphabetically sorted names, this new function end up being very effective to avoid unnecessary calls to rmdir(). In some cases over 95% of all calls to rmdir() is removed with this patch. Signed-off-by: Kjetil Barvik <barvik@broadpark.no> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'symlinks.c')
-rw-r--r--symlinks.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/symlinks.c b/symlinks.c
index 51672868d1..1d6b35b858 100644
--- a/symlinks.c
+++ b/symlinks.c
@@ -245,3 +245,62 @@ int has_dirs_only_path(const char *name, int len, int prefix_len)
FL_DIR|FL_FULLPATH, prefix_len) &
FL_DIR;
}
+
+static struct removal_def {
+ char path[PATH_MAX];
+ int len;
+} removal;
+
+static void do_remove_scheduled_dirs(int new_len)
+{
+ while (removal.len > new_len) {
+ removal.path[removal.len] = '\0';
+ if (rmdir(removal.path))
+ break;
+ do {
+ removal.len--;
+ } while (removal.len > new_len &&
+ removal.path[removal.len] != '/');
+ }
+ removal.len = new_len;
+ return;
+}
+
+void schedule_dir_for_removal(const char *name, int len)
+{
+ int match_len, last_slash, i, previous_slash;
+
+ match_len = last_slash = i =
+ longest_path_match(name, len, removal.path, removal.len,
+ &previous_slash);
+ /* Find last slash inside 'name' */
+ while (i < len) {
+ if (name[i] == '/')
+ last_slash = i;
+ i++;
+ }
+
+ /*
+ * If we are about to go down the directory tree, we check if
+ * we must first go upwards the tree, such that we then can
+ * remove possible empty directories as we go upwards.
+ */
+ if (match_len < last_slash && match_len < removal.len)
+ do_remove_scheduled_dirs(match_len);
+ /*
+ * If we go deeper down the directory tree, we only need to
+ * save the new path components as we go down.
+ */
+ if (match_len < last_slash) {
+ memcpy(&removal.path[match_len], &name[match_len],
+ last_slash - match_len);
+ removal.len = last_slash;
+ }
+ return;
+}
+
+void remove_scheduled_dirs(void)
+{
+ do_remove_scheduled_dirs(0);
+ return;
+}