pack-objects: document --delta-base-offset option
[git/git.git] / git-repack.sh
CommitLineData
b2d46199 1#!/bin/sh
ccf1ee32
JH
2#
3# Copyright (c) 2005 Linus Torvalds
4#
5
cec2be76 6USAGE='[-a] [-d] [-f] [-l] [-n] [-q]'
ae2b0f15 7. git-sh-setup
ccb36504 8
cec2be76 9no_update_info= all_into_one= remove_redundant=
ccb36504 10local= quiet= no_reuse_delta= extra=
ccf1ee32
JH
11while case "$#" in 0) break ;; esac
12do
13 case "$1" in
14 -n) no_update_info=t ;;
d5acdcf1 15 -a) all_into_one=t ;;
0adb3358 16 -d) remove_redundant=t ;;
cec2be76
JH
17 -q) quiet=-q ;;
18 -f) no_reuse_delta=--no-reuse-delta ;;
19 -l) local=--local ;;
ccb36504
LT
20 --window=*) extra="$extra $1" ;;
21 --depth=*) extra="$extra $1" ;;
9678faaa 22 *) usage ;;
ccf1ee32
JH
23 esac
24 shift
25done
26
d5acdcf1 27PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
0ea2582d
ML
28PACKTMP="$GIT_DIR/.tmp-$$-pack"
29rm -f "$PACKTMP"-*
30trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
d5acdcf1
JH
31
32# There will be more repacking strategies to come...
33case ",$all_into_one," in
34,,)
35 rev_list='--unpacked'
d5acdcf1
JH
36 pack_objects='--incremental'
37 ;;
38,t,)
39 rev_list=
d5acdcf1 40 pack_objects=
6ed64058
JH
41
42 # Redundancy check in all-into-one case is trivial.
9e848013 43 existing=`test -d "$PACKDIR" && cd "$PACKDIR" && \
6ed64058 44 find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
d5acdcf1
JH
45 ;;
46esac
0ea2582d 47
ccb36504 48pack_objects="$pack_objects $local $quiet $no_reuse_delta$extra"
a72f9373
JH
49name=$( { git-rev-list --objects --all $rev_list ||
50 echo "git-rev-list died with exit code $?"
51 } |
0ea2582d 52 git-pack-objects --non-empty $pack_objects "$PACKTMP") ||
b2d46199 53 exit 1
d5acdcf1
JH
54if [ -z "$name" ]; then
55 echo Nothing new to pack.
178613c7 56else
1054dcd1
ML
57 if test "$quiet" != '-q'; then
58 echo "Pack pack-$name created."
59 fi
178613c7 60 mkdir -p "$PACKDIR" || exit
d5acdcf1 61
2ad47d61
JH
62 for sfx in pack idx
63 do
64 if test -f "$PACKDIR/pack-$name.$sfx"
65 then
66 mv -f "$PACKDIR/pack-$name.$sfx" \
67 "$PACKDIR/old-pack-$name.$sfx"
68 fi
69 done &&
0ea2582d
ML
70 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
71 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
2ad47d61
JH
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
78 }
79 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
178613c7 80fi
d5acdcf1 81
0adb3358 82if test "$remove_redundant" = t
d5acdcf1 83then
6ed64058
JH
84 # We know $existing are all redundant only when
85 # all-into-one is used.
86 if test "$all_into_one" != '' && test "$existing" != ''
62af0b53 87 then
6ed64058
JH
88 sync
89 ( cd "$PACKDIR" &&
90 for e in $existing
91 do
62af0b53
LS
92 case "$e" in
93 ./pack-$name.pack | ./pack-$name.idx) ;;
6ed64058 94 *) rm -f $e ;;
62af0b53 95 esac
6ed64058
JH
96 done
97 )
d5acdcf1 98 fi
2d0048e6 99 git-prune-packed
d5acdcf1 100fi
ccf1ee32 101
ccf1ee32
JH
102case "$no_update_info" in
103t) : ;;
104*) git-update-server-info ;;
105esac