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

[PATCH] Make git-prune-script a bit more careful.

From
Junio C Hamano <junkio@cox.net>
Date
May 1, 2005, 21:27 UTC
Message-ID
<7vk6miskl4.fsf_-_@assigned-by-dhcp.cox.net>
In-Reply-To
<7vwtqismpn.fsf@assigned-by-dhcp.cox.net>

As discussed on the git list, this patch makes the sample script git-prune-script a bit more careful by keeping the objects referenced from the current cache from being reclaimed.

At the same time it also fixes and enhances the following:
 - Optional command line parameters can specify which commit
   heads to start reachablity test from.  Earlier we had a
   hardcoded .git/HEAD.  It now defaults to the contents of
   .git/HEAD and .git/refs/*/* files.
 - It does not assume SHA1_FILE_DIRECTORY is .git/objects/ but
   uses the value from the environment if there is one.
 - It runs xargs with "-r" option to prevent it from making "rm"
   command barf if there is nothing to remove.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---

git-prune-script | 32 +++++++++++++++++++++++++++++++- 1 files changed, 31 insertions(+), 1 deletion(-)

# - date handling: handle "AM"/"PM" on time # + [PATCH] Make git-prune-script a bit more careful. --- k/git-prune-script +++ l/git-prune-script

@@ -1,2 +1,32 @@
 #!/bin/sh
-git-fsck-cache --unreachable $(cat .git/HEAD ) | grep unreachable | cut -d' ' -f3 | sed 's:^\(..\):.git/objects/\1/:' | xargs rm
+
+tmp=.git-prune-script-$$
+trap 'rm -f $tmp-*' 0 1 2 3 15 
+
+# Defaulting to include .git/refs/*/* may be debatable from the
+# purist POV but power users can always give explicit parameters
+# to the script anyway.
+case "$#" in
+0) set x $(cat .git/HEAD .git/refs/*/*); shift ;;
+esac
+
+git-fsck-cache --unreachable "$@" |
+sed -ne 's/unreachable [^ ][^ ]* //p' |
+sort >$tmp-unreachable
+
+# This makes extra objects to be kept if the cache has an entry
+# with an unusual name like "this\n0 0123...abcdef 0 file", but
+# we are trying not to discard information and keeping extra in
+# an unusual situation would be OK.
+git-ls-files --stage |
+sed -ne 's|^[0-7][0-7]* \([0-9a-f][0-9a-f]*\) [0-3] .*|\1|p' |
+sort >$tmp-keep
+
+comm -23 $tmp-unreachable $tmp-keep |
+sed -e 's|\(..\)|\1/|' | {
+	case "$SHA1_FILE_DIRECTORY" in
+	'') cd .git/objects/ ;;
+	*) cd "$SHA1_FILE_DIRECTORY" ;;
+	esac || exit
+	xargs -r echo rm -f
+}
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 6 in “Should git-prune-script warn about dircache?”
  1. Junio C HamanoMay 1, 2005
  2. Linus TorvaldsMay 1, 2005
  3. Junio C HamanoMay 1, 2005
  4. Junio C HamanoMay 1, 2005
  5. Make git-prune-script a bit more careful.Junio C Hamano, May 1, 2005
  6. Make git-update-cache --refresh fail if update/merge needed.Junio C Hamano, May 1, 2005

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.