Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 123 lines (112 sloc) 2.81 kB
b2d4619 Add "git repack" command that does an incremental pack
Linus Torvalds authored
1 #!/bin/sh
ccf1ee3 Generate pack info file after repack.
Junio C Hamano authored
2 #
3 # Copyright (c) 2005 Linus Torvalds
4 #
5
6b94b1a git-repack --max-pack-size: add option parsing to enable feature
Dana L. How authored
6 USAGE='[-a] [-d] [-f] [-l] [-n] [-q] [--max-pack-size=N] [--window=N] [--depth=N]'
d0b353b @peff git-repack: allow git-repack to run in subdirectory
authored
7 SUBDIRECTORY_OK='Yes'
ae2b0f1 git-sh-setup: die if outside git repository.
Junio C Hamano authored
8 . git-sh-setup
ccb3650 Allow "git repack" users to specify repacking window/depth
Linus Torvalds authored
9
cec2be7 git-repack: allow passing a couple of flags to pack-objects.
Junio C Hamano authored
10 no_update_info= all_into_one= remove_redundant=
479b56b make "repack -f" imply "pack-objects --no-reuse-object"
Nicolas Pitre authored
11 local= quiet= no_reuse= extra=
ccf1ee3 Generate pack info file after repack.
Junio C Hamano authored
12 while case "$#" in 0) break ;; esac
13 do
14 case "$1" in
15 -n) no_update_info=t ;;
d5acdcf git-repack-script: Add option to repack all objects.
Junio C Hamano authored
16 -a) all_into_one=t ;;
0adb335 @ralfbaechle git-repack: Fix variable name
ralfbaechle authored
17 -d) remove_redundant=t ;;
cec2be7 git-repack: allow passing a couple of flags to pack-objects.
Junio C Hamano authored
18 -q) quiet=-q ;;
479b56b make "repack -f" imply "pack-objects --no-reuse-object"
Nicolas Pitre authored
19 -f) no_reuse=--no-reuse-object ;;
cec2be7 git-repack: allow passing a couple of flags to pack-objects.
Junio C Hamano authored
20 -l) local=--local ;;
6b94b1a git-repack --max-pack-size: add option parsing to enable feature
Dana L. How authored
21 --max-pack-size=*) extra="$extra $1" ;;
ccb3650 Allow "git repack" users to specify repacking window/depth
Linus Torvalds authored
22 --window=*) extra="$extra $1" ;;
23 --depth=*) extra="$extra $1" ;;
9678faa git-repack: Usage string clean-up, emit usage at incorrect invocation
freku045@student.liu.se authored
24 *) usage ;;
ccf1ee3 Generate pack info file after repack.
Junio C Hamano authored
25 esac
26 shift
27 done
28
b6945f5 git-repack: repo.usedeltabaseoffset
Junio C Hamano authored
29 # Later we will default repack.UseDeltaBaseOffset to true
30 default_dbo=false
31
e0d10e1 @tomprince [PATCH] Rename git-repo-config to git-config.
tomprince authored
32 case "`git config --bool repack.usedeltabaseoffset ||
b6945f5 git-repack: repo.usedeltabaseoffset
Junio C Hamano authored
33 echo $default_dbo`" in
34 true)
35 extra="$extra --delta-base-offset" ;;
36 esac
37
d5acdcf git-repack-script: Add option to repack all objects.
Junio C Hamano authored
38 PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
6b94b1a git-repack --max-pack-size: add option parsing to enable feature
Dana L. How authored
39 PACKTMP="$GIT_OBJECT_DIRECTORY/.tmp-$$-pack"
0ea2582 git-repack: create new packs inside $GIT_DIR, not cwd
Martin Langhoff authored
40 rm -f "$PACKTMP"-*
41 trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
d5acdcf git-repack-script: Add option to repack all objects.
Junio C Hamano authored
42
43 # There will be more repacking strategies to come...
44 case ",$all_into_one," in
45 ,,)
cd0d74d repack: use only pack-objects, not rev-list.
Junio C Hamano authored
46 args='--unpacked --incremental'
d5acdcf git-repack-script: Add option to repack all objects.
Junio C Hamano authored
47 ;;
48 ,t,)
ce85907 @spearce Only repack active packs by skipping over kept packs.
spearce authored
49 if [ -d "$PACKDIR" ]; then
50 for e in `cd "$PACKDIR" && find . -type f -name '*.pack' \
51 | sed -e 's/^\.\///' -e 's/\.pack$//'`
52 do
53 if [ -e "$PACKDIR/$e.keep" ]; then
54 : keep
55 else
56 args="$args --unpacked=$e.pack"
57 existing="$existing $e"
58 fi
59 done
60 fi
61 [ -z "$args" ] && args='--unpacked --incremental'
d5acdcf git-repack-script: Add option to repack all objects.
Junio C Hamano authored
62 ;;
63 esac
0ea2582 git-repack: create new packs inside $GIT_DIR, not cwd
Martin Langhoff authored
64
479b56b make "repack -f" imply "pack-objects --no-reuse-object"
Nicolas Pitre authored
65 args="$args $local $quiet $no_reuse$extra"
6b94b1a git-repack --max-pack-size: add option parsing to enable feature
Dana L. How authored
66 names=$(git-pack-objects --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
b2d4619 Add "git repack" command that does an incremental pack
Linus Torvalds authored
67 exit 1
6b94b1a git-repack --max-pack-size: add option parsing to enable feature
Dana L. How authored
68 if [ -z "$names" ]; then
d5acdcf git-repack-script: Add option to repack all objects.
Junio C Hamano authored
69 echo Nothing new to pack.
6b94b1a git-repack --max-pack-size: add option parsing to enable feature
Dana L. How authored
70 fi
71 for name in $names ; do
dca3957 Ensure git-repack -a -d --max-pack-size=N deletes correct packs
Dana How authored
72 fullbases="$fullbases pack-$name"
ad2c82c repacked packs should be read-only
Nicolas Pitre authored
73 chmod a-w "$PACKTMP-$name.pack"
74 chmod a-w "$PACKTMP-$name.idx"
1054dcd git-repack -- respect -q and be quiet
Martin Langhoff authored
75 if test "$quiet" != '-q'; then
76 echo "Pack pack-$name created."
77 fi
178613c @tali repack: honor -d even when no new pack was created
tali authored
78 mkdir -p "$PACKDIR" || exit
d5acdcf git-repack-script: Add option to repack all objects.
Junio C Hamano authored
79
2ad47d6 git-repack: Be careful when updating the same pack as an existing one.
Junio C Hamano authored
80 for sfx in pack idx
81 do
82 if test -f "$PACKDIR/pack-$name.$sfx"
83 then
84 mv -f "$PACKDIR/pack-$name.$sfx" \
85 "$PACKDIR/old-pack-$name.$sfx"
86 fi
87 done &&
0ea2582 git-repack: create new packs inside $GIT_DIR, not cwd
Martin Langhoff authored
88 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
89 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
2ad47d6 git-repack: Be careful when updating the same pack as an existing one.
Junio C Hamano authored
90 test -f "$PACKDIR/pack-$name.pack" &&
91 test -f "$PACKDIR/pack-$name.idx" || {
92 echo >&2 "Couldn't replace the existing pack with updated one."
93 echo >&2 "The original set of packs have been saved as"
94 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
95 exit 1
96 }
97 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
6b94b1a git-repack --max-pack-size: add option parsing to enable feature
Dana L. How authored
98 done
d5acdcf git-repack-script: Add option to repack all objects.
Junio C Hamano authored
99
0adb335 @ralfbaechle git-repack: Fix variable name
ralfbaechle authored
100 if test "$remove_redundant" = t
d5acdcf git-repack-script: Add option to repack all objects.
Junio C Hamano authored
101 then
ce85907 @spearce Only repack active packs by skipping over kept packs.
spearce authored
102 # We know $existing are all redundant.
103 if [ -n "$existing" ]
62af0b5 Remove all old packfiles when doing "git repack -a -d"
Lukas Sandström authored
104 then
6ed6405 git-repack: do not do complex redundancy check.
Junio C Hamano authored
105 sync
106 ( cd "$PACKDIR" &&
107 for e in $existing
108 do
dca3957 Ensure git-repack -a -d --max-pack-size=N deletes correct packs
Dana How authored
109 case " $fullbases " in
110 *" $e "*) ;;
ce85907 @spearce Only repack active packs by skipping over kept packs.
spearce authored
111 *) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
62af0b5 Remove all old packfiles when doing "git repack -a -d"
Lukas Sandström authored
112 esac
6ed6405 git-repack: do not do complex redundancy check.
Junio C Hamano authored
113 done
114 )
d5acdcf git-repack-script: Add option to repack all objects.
Junio C Hamano authored
115 fi
b60daf0 Make git-prune-packed a bit more chatty.
Junio C Hamano authored
116 git-prune-packed $quiet
d5acdcf git-repack-script: Add option to repack all objects.
Junio C Hamano authored
117 fi
ccf1ee3 Generate pack info file after repack.
Junio C Hamano authored
118
119 case "$no_update_info" in
120 t) : ;;
121 *) git-update-server-info ;;
122 esac
Something went wrong with that request. Please try again.