41f222e87a
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>
30 lines
541 B
Bash
Executable File
30 lines
541 B
Bash
Executable File
#!/bin/sh
|
|
|
|
. git-sh-setup || die "Not a git archive"
|
|
|
|
dryrun=
|
|
echo=
|
|
while case "$#" in 0) break ;; esac
|
|
do
|
|
case "$1" in
|
|
-n) dryrun=-n echo=echo ;;
|
|
--) break ;;
|
|
-*) echo >&2 "usage: git-prune [ -n ] [ heads... ]"; exit 1 ;;
|
|
*) break ;;
|
|
esac
|
|
shift;
|
|
done
|
|
|
|
sync
|
|
git-fsck-objects --full --cache --unreachable "$@" |
|
|
sed -ne '/unreachable /{
|
|
s/unreachable [^ ][^ ]* //
|
|
s|\(..\)|\1/|p
|
|
}' | {
|
|
cd "$GIT_OBJECT_DIRECTORY" || exit
|
|
xargs $echo rm -f
|
|
rmdir 2>/dev/null [0-9a-f][0-9a-f]
|
|
}
|
|
|
|
git-prune-packed $dryrun
|