From: Johan Herland <johan@herland.net>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>
Subject: [RFC/PATCH 2/2] repack: Remove stale .keep files before repacking
Date: Fri, 01 Apr 2011 03:34:27 +0200 [thread overview]
Message-ID: <201104010334.28048.johan@herland.net> (raw)
In-Reply-To: <20110331190429.GC16981@sigill.intra.peff.net>
When a push is aborted, receive-pack sometimes leave stale .keep files in the
objects/pack/ directory. Fortunately, these files are easily identified by
looking at their contents, which is of the form:
receive-pack $pid on $host
By recognizing this format we can determine whether the .keep file is stale,
and can be safely deleted: If the $host part matches the current hostname,
and there is currently no process with $pid, we can safely assume that the
.keep file no longer refers to a running receive-pack process, and deleting
it should be perfectly safe.
---
On Thursday 31 March 2011, Jeff King wrote:
> On Thu, Mar 31, 2011 at 12:46:25PM +0200, Johan Herland wrote:
> > 3. Do I need to scan for and remove stale .keep files in a cron job
> >
> > in order to keep repos healthy and clonable?
>
> If we fix (1), then hopefully it is not as much of an issue. But
> probably "git gc" should clean up stale ones after a while.
This patch tries to automatically remove stale .keep files. However,
it's still work-in-progress, as I don't know how to portably (a) ask
for the current hostname (so that I can compare it to the one in the
.keep file), or (b) test for whether a given PID is running on the
system (to determine whether the receive-pack process that wrote the
.keep file is still alive).
Feedback appreciated.
...Johan
git-repack.sh | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/git-repack.sh b/git-repack.sh
index 624feec..f59e4c4 100755
--- a/git-repack.sh
+++ b/git-repack.sh
@@ -56,6 +56,18 @@ PACKTMP="$PACKDIR/.tmp-$$-pack"
rm -f "$PACKTMP"-*
trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
+HOST=`hostname || echo "localhost"` # FIXME: Portability?
+for e in `cd "$PACKDIR" && find . -type f -name '*.keep' | sed -e 's/^\.\///'`
+do
+ cat "$PACKDIR/$e" | if read word pid on host
+ then
+ test "$word" = "receive-pack" -a "$on" = "on" -a "$host" = "$HOST" || continue
+ ps -p "$pid" > /dev/null && continue # FIXME: Portability?
+ rm -f "$PACKDIR/$e"
+ say Removed stale keep file $PACKDIR/$e.
+ fi
+done
+
# There will be more repacking strategies to come...
case ",$all_into_one," in
,,)
--
1.7.4
next prev parent reply other threads:[~2011-04-01 1:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-31 10:46 Problems with stale .keep files on git server Johan Herland
2011-03-31 19:04 ` Jeff King
2011-04-01 1:29 ` [PATCH 1/2] index-pack: Create .keep files with same permissions and .pack/.idx Johan Herland
2011-04-01 21:39 ` Junio C Hamano
2011-04-01 21:41 ` Jeff King
2011-04-01 21:49 ` Shawn Pearce
2011-04-01 22:21 ` Junio C Hamano
2011-04-01 23:27 ` Johan Herland
2011-04-02 4:21 ` Junio C Hamano
2011-04-03 1:01 ` Johan Herland
2011-04-01 23:37 ` Johan Herland
2011-04-01 1:34 ` Johan Herland [this message]
2011-04-01 1:41 ` [RFC/PATCH 2/2] repack: Remove stale .keep files before repacking Jeff King
2011-04-01 8:12 ` Johan Herland
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=201104010334.28048.johan@herland.net \
--to=johan@herland.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.