From: Christian Couder <chriscool@tuxfamily.org>
To: Junio Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: [PATCH 2/2] When packing and pruning refs, remove "deleted-refs".
Date: Sat, 14 Oct 2006 15:41:09 +0200 [thread overview]
Message-ID: <20061014154109.9a093319.chriscool@tuxfamily.org> (raw)
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
reply other threads:[~2006-10-14 13:34 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061014154109.9a093319.chriscool@tuxfamily.org \
--to=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).