2005-04-19 03:15:10 +08:00
|
|
|
#!/bin/sh
|
2005-07-09 01:57:21 +08:00
|
|
|
|
2005-12-14 06:30:32 +08:00
|
|
|
USAGE='[-n] [--] [<head>...]'
|
2005-11-24 16:12:11 +08:00
|
|
|
. git-sh-setup
|
2005-07-09 01:57:21 +08:00
|
|
|
|
2005-05-04 16:33:33 +08:00
|
|
|
dryrun=
|
2005-08-20 12:38:36 +08:00
|
|
|
echo=
|
2005-05-04 16:33:33 +08:00
|
|
|
while case "$#" in 0) break ;; esac
|
|
|
|
do
|
|
|
|
case "$1" in
|
2005-08-20 12:38:36 +08:00
|
|
|
-n) dryrun=-n echo=echo ;;
|
2005-05-04 16:33:33 +08:00
|
|
|
--) break ;;
|
2005-12-14 06:30:32 +08:00
|
|
|
-*) usage ;;
|
2005-05-04 16:33:33 +08: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-29 00:45:53 +08:00
|
|
|
sync
|
2005-12-09 15:18:41 +08:00
|
|
|
case "$#" in
|
|
|
|
0) git-fsck-objects --full --cache --unreachable ;;
|
|
|
|
*) git-fsck-objects --full --cache --unreachable $(git-rev-parse --all) "$@" ;;
|
|
|
|
esac |
|
|
|
|
|
2005-05-04 16:33:33 +08:00
|
|
|
sed -ne '/unreachable /{
|
|
|
|
s/unreachable [^ ][^ ]* //
|
|
|
|
s|\(..\)|\1/|p
|
|
|
|
}' | {
|
2005-05-10 13:57:58 +08:00
|
|
|
cd "$GIT_OBJECT_DIRECTORY" || exit
|
2005-08-20 12:38:36 +08:00
|
|
|
xargs $echo rm -f
|
2005-10-09 17:30:17 +08:00
|
|
|
rmdir 2>/dev/null [0-9a-f][0-9a-f]
|
2005-05-04 16:33:33 +08:00
|
|
|
}
|
2005-05-10 13:57:58 +08:00
|
|
|
|
2005-08-20 12:38:36 +08:00
|
|
|
git-prune-packed $dryrun
|
2005-11-12 02:41:53 +08:00
|
|
|
|
2006-01-07 16:29:48 +08:00
|
|
|
if redundant=$(git-pack-redundant --all 2>/dev/null) && test "" != "$redundant"
|
2005-11-12 02:41:53 +08:00
|
|
|
then
|
2005-11-19 03:15:40 +08:00
|
|
|
if test "" = "$dryrun"
|
2005-11-12 02:41:53 +08:00
|
|
|
then
|
|
|
|
echo "$redundant" | xargs rm -f
|
|
|
|
else
|
|
|
|
echo rm -f "$redundant"
|
|
|
|
fi
|
|
|
|
fi
|