* [PATCH 2/2] When packing and pruning refs, remove "deleted-refs".
@ 2006-10-14 13:41 Christian Couder
0 siblings, 0 replies; only message in thread
From: Christian Couder @ 2006-10-14 13:41 UTC (permalink / raw)
To: Junio Hamano; +Cc: git
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@tuxfamily.org>
---
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2006-10-14 13:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-14 13:41 [PATCH 2/2] When packing and pruning refs, remove "deleted-refs" Christian Couder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).