When running "git pack-refs --prune" we have to also prune deleted ref files. To do this, remove recusively everything under "$GIT_DIR/deleted-refs". The new "remove_all_recursive" function has been copied from "remove_empty_dir_recursive" in "refs.c". Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx> --- builtin-pack-refs.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-) diff --git a/builtin-pack-refs.c b/builtin-pack-refs.c index 1087657..84ca170 100644 --- a/builtin-pack-refs.c +++ b/builtin-pack-refs.c @@ -54,12 +54,54 @@ static void prune_ref(struct ref_to_prun } } +static int remove_all_recursive(char *path) +{ + DIR *dir = opendir(path); + struct dirent *e; + int ret = 0; + int len = strlen(path); + + if (!dir) + return unlink(path); + if (path[len-1] != '/') + path[len++] = '/'; + while ((e = readdir(dir)) != NULL) { + struct stat st; + int namlen; + if ((e->d_name[0] == '.') && + ((e->d_name[1] == 0) || + ((e->d_name[1] == '.') && e->d_name[2] == 0))) + continue; /* "." and ".." */ + + namlen = strlen(e->d_name); + if ((len + namlen < PATH_MAX) && + strcpy(path + len, e->d_name) && + !lstat(path, &st) && + (S_ISDIR(st.st_mode) ? + !remove_all_recursive(path) : + !unlink(path))) + continue; /* happy */ + + /* path too long, stat, rmdir or unlink fails */ + ret = -1; + break; + } + closedir(dir); + if (!ret) { + path[len] = 0; + ret = rmdir(path); + } + return ret; +} + static void prune_refs(struct ref_to_prune *r) { while (r) { prune_ref(r); r = r->next; } + + remove_all_recursive(git_path("deleted-refs")); } static struct lock_file packed; -- 1.4.3.rc2.gbcf275-dirty - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html