gitweb: do not use 'No such directory' error message
[git/jnareb-git.git] / git-repack.sh
blobb525fc5dfd9053a6fb63a4d38517e25e75341199
1 #!/bin/sh
3 # Copyright (c) 2005 Linus Torvalds
6 USAGE='[-a] [-d] [-f] [-l] [-n] [-q]'
7 . git-sh-setup
9 no_update_info= all_into_one= remove_redundant=
10 local= quiet= no_reuse_delta= extra=
11 while case "$#" in 0) break ;; esac
13 case "$1" in
14 -n) no_update_info=t ;;
15 -a) all_into_one=t ;;
16 -d) remove_redundant=t ;;
17 -q) quiet=-q ;;
18 -f) no_reuse_delta=--no-reuse-delta ;;
19 -l) local=--local ;;
20 --window=*) extra="$extra $1" ;;
21 --depth=*) extra="$extra $1" ;;
22 *) usage ;;
23 esac
24 shift
25 done
27 PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
28 PACKTMP="$GIT_DIR/.tmp-$$-pack"
29 rm -f "$PACKTMP"-*
30 trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
32 # There will be more repacking strategies to come...
33 case ",$all_into_one," in
34 ,,)
35 rev_list='--unpacked'
36 pack_objects='--incremental'
38 ,t,)
39 rev_list=
40 pack_objects=
42 # Redundancy check in all-into-one case is trivial.
43 existing=`test -d "$PACKDIR" && cd "$PACKDIR" && \
44 find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
46 esac
48 pack_objects="$pack_objects $local $quiet $no_reuse_delta$extra"
49 name=$( { git-rev-list --objects --all $rev_list ||
50 echo "git-rev-list died with exit code $?"
51 } |
52 git-pack-objects --non-empty $pack_objects "$PACKTMP") ||
53 exit 1
54 if [ -z "$name" ]; then
55 echo Nothing new to pack.
56 else
57 if test "$quiet" != '-q'; then
58 echo "Pack pack-$name created."
60 mkdir -p "$PACKDIR" || exit
62 for sfx in pack idx
64 if test -f "$PACKDIR/pack-$name.$sfx"
65 then
66 mv -f "$PACKDIR/pack-$name.$sfx" \
67 "$PACKDIR/old-pack-$name.$sfx"
69 done &&
70 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
71 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
72 test -f "$PACKDIR/pack-$name.pack" &&
73 test -f "$PACKDIR/pack-$name.idx" || {
74 echo >&2 "Couldn't replace the existing pack with updated one."
75 echo >&2 "The original set of packs have been saved as"
76 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
77 exit 1
79 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
82 if test "$remove_redundant" = t
83 then
84 # We know $existing are all redundant only when
85 # all-into-one is used.
86 if test "$all_into_one" != '' && test "$existing" != ''
87 then
88 sync
89 ( cd "$PACKDIR" &&
90 for e in $existing
92 case "$e" in
93 ./pack-$name.pack | ./pack-$name.idx) ;;
94 *) rm -f $e ;;
95 esac
96 done
99 git-prune-packed
102 case "$no_update_info" in
103 t) : ;;
104 *) git-update-server-info ;;
105 esac