2005-04-18 19:15:10 +00:00
|
|
|
#!/bin/sh
|
2005-07-08 17:57:21 +00:00
|
|
|
|
2005-09-08 00:26:23 +00:00
|
|
|
. git-sh-setup || die "Not a git archive"
|
2005-07-08 17:57:21 +00:00
|
|
|
|
2005-05-04 08:33:33 +00:00
|
|
|
dryrun=
|
2005-08-20 04:38:36 +00:00
|
|
|
echo=
|
2005-05-04 08:33:33 +00:00
|
|
|
while case "$#" in 0) break ;; esac
|
|
|
|
do
|
|
|
|
case "$1" in
|
2005-08-20 04:38:36 +00:00
|
|
|
-n) dryrun=-n echo=echo ;;
|
2005-05-04 08:33:33 +00:00
|
|
|
--) break ;;
|
2005-09-08 00:26:23 +00:00
|
|
|
-*) echo >&2 "usage: git-prune [ -n ] [ heads... ]"; exit 1 ;;
|
2005-05-04 08:33:33 +00:00
|
|
|
*) break ;;
|
|
|
|
esac
|
|
|
|
shift;
|
|
|
|
done
|
|
|
|
|
Be marginally more careful about removing objects
The git philosophy when it comes to disk accesses is "Laugh in the face of
danger".
Notably, since we never modify an existing object, we don't really care
that deeply about flushing things to disk, since even if the machine
crashes in the middle of a git operation, you can never really have lost
any old work. At most, you'd need to figure out the proper heads (which
git-fsck-objects can do for you) and re-do the operation.
However, there's two exceptions to this: pruning and repacking. Those
operations will actually _delete_ old objects that they know about in
other ways (ie that they just repacked, or that they have found in other
places).
However, since they actually modify old state, we should thus be a bit
more careful about them. If the machine crashes and the duplicate new
objects haven't been flushed to disk, you can actually be in trouble.
This is trivially stupid about it by calling "sync" before removing the
objects. Not very smart, but we're talking about special operations than
are usually done once a week if that.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-10-28 16:45:53 +00:00
|
|
|
sync
|
2005-09-08 00:26:23 +00:00
|
|
|
git-fsck-objects --full --cache --unreachable "$@" |
|
2005-05-04 08:33:33 +00:00
|
|
|
sed -ne '/unreachable /{
|
|
|
|
s/unreachable [^ ][^ ]* //
|
|
|
|
s|\(..\)|\1/|p
|
|
|
|
}' | {
|
2005-05-10 05:57:58 +00:00
|
|
|
cd "$GIT_OBJECT_DIRECTORY" || exit
|
2005-08-20 04:38:36 +00:00
|
|
|
xargs $echo rm -f
|
2005-10-09 09:30:17 +00:00
|
|
|
rmdir 2>/dev/null [0-9a-f][0-9a-f]
|
2005-05-04 08:33:33 +00:00
|
|
|
}
|
2005-05-10 05:57:58 +00:00
|
|
|
|
2005-08-20 04:38:36 +00:00
|
|
|
git-prune-packed $dryrun
|
2005-11-11 18:41:53 +00:00
|
|
|
|
|
|
|
redundant=$(git-pack-redundant --all)
|
|
|
|
if test "" != "$redundant"
|
|
|
|
then
|
2005-11-18 19:15:40 +00:00
|
|
|
if test "" = "$dryrun"
|
2005-11-11 18:41:53 +00:00
|
|
|
then
|
|
|
|
echo "$redundant" | xargs rm -f
|
|
|
|
else
|
|
|
|
echo rm -f "$redundant"
|
|
|
|
fi
|
|
|
|
fi
|