]> git.ipfire.org Git - thirdparty/git.git/blame - git-repack.sh
combine-diff: a few more finishing touches.
[thirdparty/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]'
d0b353b1 7SUBDIRECTORY_OK='Yes'
ae2b0f15 8. git-sh-setup
ccb36504 9
cec2be76 10no_update_info= all_into_one= remove_redundant=
ccb36504 11local= quiet= no_reuse_delta= extra=
ccf1ee32
JH
12while case "$#" in 0) break ;; esac
13do
14 case "$1" in
15 -n) no_update_info=t ;;
d5acdcf1 16 -a) all_into_one=t ;;
0adb3358 17 -d) remove_redundant=t ;;
cec2be76
JH
18 -q) quiet=-q ;;
19 -f) no_reuse_delta=--no-reuse-delta ;;
20 -l) local=--local ;;
ccb36504
LT
21 --window=*) extra="$extra $1" ;;
22 --depth=*) extra="$extra $1" ;;
9678faaa 23 *) usage ;;
ccf1ee32
JH
24 esac
25 shift
26done
27
d5acdcf1 28PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
0ea2582d
ML
29PACKTMP="$GIT_DIR/.tmp-$$-pack"
30rm -f "$PACKTMP"-*
31trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
d5acdcf1
JH
32
33# There will be more repacking strategies to come...
34case ",$all_into_one," in
35,,)
cd0d74d2 36 args='--unpacked --incremental'
d5acdcf1
JH
37 ;;
38,t,)
cd0d74d2 39 args=
6ed64058
JH
40
41 # Redundancy check in all-into-one case is trivial.
9e848013 42 existing=`test -d "$PACKDIR" && cd "$PACKDIR" && \
6ed64058 43 find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
d5acdcf1
JH
44 ;;
45esac
0ea2582d 46
cd0d74d2
JH
47args="$args $local $quiet $no_reuse_delta$extra"
48name=$(git-pack-objects --non-empty --all $args </dev/null "$PACKTMP") ||
b2d46199 49 exit 1
d5acdcf1
JH
50if [ -z "$name" ]; then
51 echo Nothing new to pack.
178613c7 52else
1054dcd1
ML
53 if test "$quiet" != '-q'; then
54 echo "Pack pack-$name created."
55 fi
178613c7 56 mkdir -p "$PACKDIR" || exit
d5acdcf1 57
2ad47d61
JH
58 for sfx in pack idx
59 do
60 if test -f "$PACKDIR/pack-$name.$sfx"
61 then
62 mv -f "$PACKDIR/pack-$name.$sfx" \
63 "$PACKDIR/old-pack-$name.$sfx"
64 fi
65 done &&
0ea2582d
ML
66 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
67 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
2ad47d61
JH
68 test -f "$PACKDIR/pack-$name.pack" &&
69 test -f "$PACKDIR/pack-$name.idx" || {
70 echo >&2 "Couldn't replace the existing pack with updated one."
71 echo >&2 "The original set of packs have been saved as"
72 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
73 exit 1
74 }
75 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
178613c7 76fi
d5acdcf1 77
0adb3358 78if test "$remove_redundant" = t
d5acdcf1 79then
6ed64058
JH
80 # We know $existing are all redundant only when
81 # all-into-one is used.
82 if test "$all_into_one" != '' && test "$existing" != ''
62af0b53 83 then
6ed64058
JH
84 sync
85 ( cd "$PACKDIR" &&
86 for e in $existing
87 do
62af0b53
LS
88 case "$e" in
89 ./pack-$name.pack | ./pack-$name.idx) ;;
6ed64058 90 *) rm -f $e ;;
62af0b53 91 esac
6ed64058
JH
92 done
93 )
d5acdcf1 94 fi
2d0048e6 95 git-prune-packed
d5acdcf1 96fi
ccf1ee32 97
ccf1ee32
JH
98case "$no_update_info" in
99t) : ;;
100*) git-update-server-info ;;
101esac