git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCH 2/2] repack: Remove stale .keep files before repacking

From
Johan Herland <johan@herland.net>
Date
Apr 1, 2011, 01:34 UTC
Message-ID
<201104010334.28048.johan@herland.net>
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:
Show 7 quoted lines
> 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
Previous: Johan HerlandNext: Jeff King
Message 12 of 14 in “Problems with stale .keep files on git server”
  1. Johan HerlandMar 31, 2011
  2. Jeff KingMar 31, 2011
  3. 1/2 index-pack: Create .keep files with same permissions and .pack/.idxJohan Herland, Apr 1, 2011
  4. Junio C HamanoApr 1, 2011
  5. Jeff KingApr 1, 2011
  6. Shawn PearceApr 1, 2011
  7. Junio C HamanoApr 1, 2011
  8. Johan HerlandApr 1, 2011
  9. Junio C HamanoApr 2, 2011
  10. Johan HerlandApr 3, 2011
  11. Johan HerlandApr 1, 2011
  12. 2/2 repack: Remove stale .keep files before repackingJohan Herland, Apr 1, 2011
  13. Jeff KingApr 1, 2011
  14. Johan HerlandApr 1, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.