blob: e18eb3f5dcf42abfbd125594877ececf92c3d9b6 [file] [log] [blame]
Linus Torvaldsb2d46192005-07-03 13:38:01 -07001#!/bin/sh
Junio C Hamanoccf1ee32005-08-24 10:40:58 -07002#
3# Copyright (c) 2005 Linus Torvalds
4#
5
Pierre Habouzit5715d0b2007-11-04 11:31:02 +01006OPTIONS_KEEPDASHDASH=
7OPTIONS_SPEC="\
8git-repack [options]
9--
10a pack everything in a single pack
11A same as -a, and keep unreachable objects too
12d remove redundant packs, and run git-prune-packed
13f pass --no-reuse-delta to git-pack-objects
14q,quiet be quiet
15l pass --local to git-pack-objects
16 Packing constraints
17window= size of the window used for delta compression
18window-memory= same as the above, but limit memory size instead of entries count
19depth= limits the maximum delta depth
20max-pack-size= maximum size of each packfile
21"
Jeff Kingd0b353b2006-09-24 22:31:11 -040022SUBDIRECTORY_OK='Yes'
Junio C Hamanoae2b0f12005-11-24 00:12:11 -080023. git-sh-setup
Linus Torvaldsccb36502006-04-19 10:05:12 -070024
Junio C Hamano65aa5302007-09-16 23:24:07 -070025no_update_info= all_into_one= remove_redundant= keep_unreachable=
Nicolas Pitre479b56b2007-05-09 12:59:40 -040026local= quiet= no_reuse= extra=
David Kastrup822f7c72007-09-23 22:42:08 +020027while test $# != 0
Junio C Hamanoccf1ee32005-08-24 10:40:58 -070028do
29 case "$1" in
30 -n) no_update_info=t ;;
Junio C Hamanod5acdcf2005-08-29 10:29:53 -070031 -a) all_into_one=t ;;
Junio C Hamano65aa5302007-09-16 23:24:07 -070032 -A) all_into_one=t
33 keep_unreachable=--keep-unreachable ;;
Ralf Baechle0adb3352005-11-17 14:34:47 +000034 -d) remove_redundant=t ;;
Junio C Hamanocec2be72006-02-16 11:57:18 -080035 -q) quiet=-q ;;
Nicolas Pitre479b56b2007-05-09 12:59:40 -040036 -f) no_reuse=--no-reuse-object ;;
Junio C Hamanocec2be72006-02-16 11:57:18 -080037 -l) local=--local ;;
Pierre Habouzit5715d0b2007-11-04 11:31:02 +010038 --max-pack-size|--window|--window-memory|--depth)
39 extra="$extra $1=$2"; shift ;;
40 --) shift; break;;
freku045@student.liu.se9678faa2005-12-13 23:30:32 +010041 *) usage ;;
Junio C Hamanoccf1ee32005-08-24 10:40:58 -070042 esac
43 shift
44done
45
Junio C Hamanob6945f52006-10-13 21:28:58 -070046# Later we will default repack.UseDeltaBaseOffset to true
47default_dbo=false
48
Tom Princee0d10e12007-01-28 16:16:53 -080049case "`git config --bool repack.usedeltabaseoffset ||
Junio C Hamanob6945f52006-10-13 21:28:58 -070050 echo $default_dbo`" in
51true)
52 extra="$extra --delta-base-offset" ;;
53esac
54
Junio C Hamanod5acdcf2005-08-29 10:29:53 -070055PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
Dana L. How6b94b1a2007-05-13 12:47:09 -070056PACKTMP="$GIT_OBJECT_DIRECTORY/.tmp-$$-pack"
Martin Langhoff0ea25822006-09-04 17:42:32 +120057rm -f "$PACKTMP"-*
58trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
Junio C Hamanod5acdcf2005-08-29 10:29:53 -070059
60# There will be more repacking strategies to come...
61case ",$all_into_one," in
62,,)
Junio C Hamanocd0d74d2006-09-18 02:29:01 -070063 args='--unpacked --incremental'
Junio C Hamanod5acdcf2005-08-29 10:29:53 -070064 ;;
65,t,)
Shawn Pearcece859072006-10-29 04:37:54 -050066 if [ -d "$PACKDIR" ]; then
67 for e in `cd "$PACKDIR" && find . -type f -name '*.pack' \
68 | sed -e 's/^\.\///' -e 's/\.pack$//'`
69 do
70 if [ -e "$PACKDIR/$e.keep" ]; then
71 : keep
72 else
73 args="$args --unpacked=$e.pack"
74 existing="$existing $e"
75 fi
76 done
77 fi
Junio C Hamano65aa5302007-09-16 23:24:07 -070078 if test -z "$args"
79 then
80 args='--unpacked --incremental'
81 elif test -n "$keep_unreachable"
82 then
83 args="$args $keep_unreachable"
84 fi
Junio C Hamanod5acdcf2005-08-29 10:29:53 -070085 ;;
86esac
Martin Langhoff0ea25822006-09-04 17:42:32 +120087
Nicolas Pitre479b56b2007-05-09 12:59:40 -040088args="$args $local $quiet $no_reuse$extra"
Junio C Hamano5be60072007-07-02 22:52:14 -070089names=$(git pack-objects --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
Linus Torvaldsb2d46192005-07-03 13:38:01 -070090 exit 1
Dana L. How6b94b1a2007-05-13 12:47:09 -070091if [ -z "$names" ]; then
Uwe Kleine-Königd9fb3952007-07-03 10:47:58 +020092 if test -z "$quiet"; then
93 echo Nothing new to pack.
94 fi
Dana L. How6b94b1a2007-05-13 12:47:09 -070095fi
96for name in $names ; do
Dana Howdca39572007-05-24 19:06:42 -070097 fullbases="$fullbases pack-$name"
Nicolas Pitread2c82c2006-12-13 16:25:26 -050098 chmod a-w "$PACKTMP-$name.pack"
99 chmod a-w "$PACKTMP-$name.idx"
Martin Waitz178613c2006-05-07 20:18:53 +0200100 mkdir -p "$PACKDIR" || exit
101
Junio C Hamano2ad47d62006-06-25 05:28:58 -0700102 for sfx in pack idx
103 do
104 if test -f "$PACKDIR/pack-$name.$sfx"
105 then
106 mv -f "$PACKDIR/pack-$name.$sfx" \
107 "$PACKDIR/old-pack-$name.$sfx"
108 fi
109 done &&
Martin Langhoff0ea25822006-09-04 17:42:32 +1200110 mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
111 mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
Junio C Hamano2ad47d62006-06-25 05:28:58 -0700112 test -f "$PACKDIR/pack-$name.pack" &&
113 test -f "$PACKDIR/pack-$name.idx" || {
114 echo >&2 "Couldn't replace the existing pack with updated one."
115 echo >&2 "The original set of packs have been saved as"
116 echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
117 exit 1
118 }
119 rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
Dana L. How6b94b1a2007-05-13 12:47:09 -0700120done
Junio C Hamanod5acdcf2005-08-29 10:29:53 -0700121
Ralf Baechle0adb3352005-11-17 14:34:47 +0000122if test "$remove_redundant" = t
Junio C Hamanod5acdcf2005-08-29 10:29:53 -0700123then
Shawn Pearcece859072006-10-29 04:37:54 -0500124 # We know $existing are all redundant.
125 if [ -n "$existing" ]
Lukas Sandström62af0b52005-11-18 21:36:12 +0100126 then
Junio C Hamano6ed64052005-11-19 12:13:53 -0800127 sync
128 ( cd "$PACKDIR" &&
129 for e in $existing
130 do
Dana Howdca39572007-05-24 19:06:42 -0700131 case " $fullbases " in
132 *" $e "*) ;;
Shawn Pearcece859072006-10-29 04:37:54 -0500133 *) rm -f "$e.pack" "$e.idx" "$e.keep" ;;
Lukas Sandström62af0b52005-11-18 21:36:12 +0100134 esac
Junio C Hamano6ed64052005-11-19 12:13:53 -0800135 done
136 )
Junio C Hamanod5acdcf2005-08-29 10:29:53 -0700137 fi
Junio C Hamano5be60072007-07-02 22:52:14 -0700138 git prune-packed $quiet
Junio C Hamanod5acdcf2005-08-29 10:29:53 -0700139fi
140
Junio C Hamanoccf1ee32005-08-24 10:40:58 -0700141case "$no_update_info" in
142t) : ;;
143*) git-update-server-info ;;
144esac