git-count-objects: dc replacement
[git/git.git] / git-repack.sh
CommitLineData
b2d46199 1#!/bin/sh
ccf1ee32
JH
2#
3# Copyright (c) 2005 Linus Torvalds
4#
5
215a7ad1 6. git-sh-setup || die "Not a git archive"
b33e9666 7
f7aac2ea 8no_update_info= all_into_one= remove_redundant= local=
ccf1ee32
JH
9while case "$#" in 0) break ;; esac
10do
11 case "$1" in
12 -n) no_update_info=t ;;
d5acdcf1 13 -a) all_into_one=t ;;
0adb3358 14 -d) remove_redundant=t ;;
f7aac2ea 15 -l) local=t ;;
ccf1ee32
JH
16 *) break ;;
17 esac
18 shift
19done
20
5f3de58f 21rm -f .tmp-pack-*
d5acdcf1
JH
22PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
23
24# There will be more repacking strategies to come...
25case ",$all_into_one," in
26,,)
27 rev_list='--unpacked'
28 rev_parse='--all'
29 pack_objects='--incremental'
30 ;;
31,t,)
32 rev_list=
33 rev_parse='--all'
34 pack_objects=
d5acdcf1
JH
35 ;;
36esac
f7aac2ea
LT
37if [ "$local" ]; then
38 pack_objects="$pack_objects --local"
39fi
d5acdcf1
JH
40name=$(git-rev-list --objects $rev_list $(git-rev-parse $rev_parse) |
41 git-pack-objects --non-empty $pack_objects .tmp-pack) ||
b2d46199 42 exit 1
d5acdcf1
JH
43if [ -z "$name" ]; then
44 echo Nothing new to pack.
0adb3358 45 if test "$remove_redundant" = t ; then
b4ad3552
LS
46 echo "Removing redundant packs."
47 sync
1c3039e8 48 redundant=$(git-pack-redundant --all)
b4ad3552
LS
49 if test "$redundant" != "" ; then
50 echo $redundant | xargs rm
51 fi
52 fi
b2d46199
LT
53 exit 0
54fi
d5acdcf1
JH
55echo "Pack pack-$name created."
56
57mkdir -p "$PACKDIR" || exit
58
59mv .tmp-pack-$name.pack "$PACKDIR/pack-$name.pack" &&
60mv .tmp-pack-$name.idx "$PACKDIR/pack-$name.idx" ||
61exit
62
0adb3358 63if test "$remove_redundant" = t
d5acdcf1 64then
b4ad3552 65 sync
62af0b53
LS
66 if test "$all_into_one" = t
67 then
68 cd "$PACKDIR"
69 existing=`find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
70 for e in $existing
71 do
72 case "$e" in
73 ./pack-$name.pack | ./pack-$name.idx) ;;
74 *) rm -f $e ;;
75 esac
76 done
77 else
78 redundant=$(git-pack-redundant --all)
79 if test "$redundant" != "" ; then
80 echo $redundant | xargs rm
81 fi
d5acdcf1
JH
82 fi
83fi
ccf1ee32 84
ccf1ee32
JH
85case "$no_update_info" in
86t) : ;;
87*) git-update-server-info ;;
88esac