From: Greg Price <price@ksplice.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Greg Price <price@ksplice.com>
Subject: [PATCH] pack-refs: remove newly empty directories
Date: Mon, 5 Jul 2010 18:27:28 -0400 [thread overview]
Message-ID: <1278368848-7037-1-git-send-email-price@ksplice.com> (raw)
In a large repository which uses directories to organize many refs,
"git pack-refs --all --prune" does not improve performance so much
as it should, unless we remove all the now-empty directories as well.
Signed-off-by: Greg Price <price@ksplice.com>
---
pack-refs.c | 8 ++++++++
t/t3210-pack-refs.sh | 6 ++++++
2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/pack-refs.c b/pack-refs.c
index 7f43f8a..33d7358 100644
--- a/pack-refs.c
+++ b/pack-refs.c
@@ -63,11 +63,19 @@ static int handle_one_ref(const char *path, const unsigned char *sha1,
/* make sure nobody touched the ref, and unlink */
static void prune_ref(struct ref_to_prune *r)
{
+ char *p, *q;
struct ref_lock *lock = lock_ref_sha1(r->name + 5, r->sha1);
if (lock) {
unlink_or_warn(git_path("%s", r->name));
unlock_ref(lock);
+
+ /* remove the directory if empty */
+ for (q = p = r->name; *p; p++)
+ if (*p == '/')
+ q = p;
+ *q = '\0';
+ rmdir(r->name);
}
}
diff --git a/t/t3210-pack-refs.sh b/t/t3210-pack-refs.sh
index 413019a..c60ede1 100755
--- a/t/t3210-pack-refs.sh
+++ b/t/t3210-pack-refs.sh
@@ -60,6 +60,12 @@ test_expect_success 'see if git pack-refs --prune remove ref files' '
! test -f .git/refs/heads/f
'
+test_expect_success 'see if git pack-refs --prune removes empty dirs' '
+ git branch r/s &&
+ git pack-refs --all --prune &&
+ ! test -e .git/refs/heads/r
+'
+
test_expect_success \
'git branch g should work when git branch g/h has been deleted' \
'git branch g/h &&
--
1.6.6.32.g6380e
next reply other threads:[~2010-07-05 23:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-05 22:27 Greg Price [this message]
2010-07-06 3:02 ` [PATCH] pack-refs: remove newly empty directories Junio C Hamano
2010-07-06 3:25 ` Greg Price
2010-07-06 23:29 ` [PATCH v2] " Greg Price
2010-07-06 6:10 ` [PATCH] " Johannes Sixt
2010-07-06 6:15 ` Junio C Hamano
2010-07-06 18:49 ` Andreas Schwab
2010-07-06 19:13 ` Greg Price
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=1278368848-7037-1-git-send-email-price@ksplice.com \
--to=price@ksplice.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).