show-branch: optionally use unique prefix as name.
[git/dkf.git] / git-repack.sh
blobb395d0ef34758f2e3e3129a5131832e932ab7875
1 #!/bin/sh
3 # Copyright (c) 2005 Linus Torvalds
6 . git-sh-setup || die "Not a git archive"
8 no_update_info= all_into_one= remove_redundant=
9 while case "$#" in 0) break ;; esac
11 case "$1" in
12 -n) no_update_info=t ;;
13 -a) all_into_one=t ;;
14 -d) remove_redandant=t ;;
15 *) break ;;
16 esac
17 shift
18 done
20 rm -f .tmp-pack-*
21 PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
23 # There will be more repacking strategies to come...
24 case ",$all_into_one," in
25 ,,)
26 rev_list='--unpacked'
27 rev_parse='--all'
28 pack_objects='--incremental'
30 ,t,)
31 rev_list=
32 rev_parse='--all'
33 pack_objects=
34 # This part is a stop-gap until we have proper pack redundancy
35 # checker.
36 existing=`cd "$PACKDIR" && \
37 find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
39 esac
40 name=$(git-rev-list --objects $rev_list $(git-rev-parse $rev_parse) |
41 git-pack-objects --non-empty $pack_objects .tmp-pack) ||
42 exit 1
43 if [ -z "$name" ]; then
44 echo Nothing new to pack.
45 exit 0
47 echo "Pack pack-$name created."
49 mkdir -p "$PACKDIR" || exit
51 mv .tmp-pack-$name.pack "$PACKDIR/pack-$name.pack" &&
52 mv .tmp-pack-$name.idx "$PACKDIR/pack-$name.idx" ||
53 exit
55 if test "$remove_redandant" = t
56 then
57 # We know $existing are all redandant only when
58 # all-into-one is used.
59 if test "$all_into_one" != '' && test "$existing" != ''
60 then
61 ( cd "$PACKDIR" &&
62 for e in $existing
64 case "$e" in
65 ./pack-$name.pack | ./pack-$name.idx) ;;
66 *) rm -f $e ;;
67 esac
68 done
73 case "$no_update_info" in
74 t) : ;;
75 *) git-update-server-info ;;
76 esac