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 -- 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