Teach rev-list an option to read revs from the standard input.
[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
5f3de58f 27rm -f .tmp-pack-*
d5acdcf1
JH
28PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
29
30# There will be more repacking strategies to come...
31case ",$all_into_one," in
32,,)
33 rev_list='--unpacked'
d5acdcf1
JH
34 pack_objects='--incremental'
35 ;;
36,t,)
37 rev_list=
d5acdcf1 38 pack_objects=
6ed64058
JH
39
40 # Redundancy check in all-into-one case is trivial.
9e848013 41 existing=`test -d "$PACKDIR" && cd "$PACKDIR" && \
6ed64058 42 find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
d5acdcf1
JH
43 ;;
44esac
ccb36504 45pack_objects="$pack_objects $local $quiet $no_reuse_delta$extra"
a72f9373
JH
46name=$( { git-rev-list --objects --all $rev_list ||
47 echo "git-rev-list died with exit code $?"
48 } |
d5acdcf1 49 git-pack-objects --non-empty $pack_objects .tmp-pack) ||
b2d46199 50 exit 1
d5acdcf1
JH
51if [ -z "$name" ]; then
52 echo Nothing new to pack.
178613c7 53else
1054dcd1
ML
54 if test "$quiet" != '-q'; then
55 echo "Pack pack-$name created."
56 fi
178613c7 57 mkdir -p "$PACKDIR" || exit
d5acdcf1 58
2ad47d61
JH
59 for sfx in pack idx
60 do
61 if test -f "$PACKDIR/pack-$name.$sfx"
62 then
63 mv -f "$PACKDIR/pack-$name.$sfx" \
64 "$PACKDIR/old-pack-$name.$sfx"
65 fi
66 done &&
67 mv -f .tmp-pack-$name.pack "$PACKDIR/pack-$name.pack" &&
68 mv -f .tmp-pack-$name.idx "$PACKDIR/pack-$name.idx" &&
69 test -f "$PACKDIR/pack-$name.pack" &&
70 test -f "$PACKDIR/pack-$name.idx" || {
71 echo >&2 "Couldn't replace the existing pack with updated one."
72 echo >&2 "The original set of packs have been saved as"
73 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
74 exit 1
75 }
76 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
178613c7 77fi
d5acdcf1 78
0adb3358 79if test "$remove_redundant" = t
d5acdcf1 80then
6ed64058
JH
81 # We know $existing are all redundant only when
82 # all-into-one is used.
83 if test "$all_into_one" != '' && test "$existing" != ''
62af0b53 84 then
6ed64058
JH
85 sync
86 ( cd "$PACKDIR" &&
87 for e in $existing
88 do
62af0b53
LS
89 case "$e" in
90 ./pack-$name.pack | ./pack-$name.idx) ;;
6ed64058 91 *) rm -f $e ;;
62af0b53 92 esac
6ed64058
JH
93 done
94 )
d5acdcf1 95 fi
2d0048e6 96 git-prune-packed
d5acdcf1 97fi
ccf1ee32 98
ccf1ee32
JH
99case "$no_update_info" in
100t) : ;;
101*) git-update-server-info ;;
102esac