#!/bin/sh # # Copyright (c) 2005 Linus Torvalds # setglobal OPTIONS_KEEPDASHDASH = '' setglobal OPTIONS_SPEC = '"\ git repack [options] -- a pack everything in a single pack A same as -a, and turn unreachable objects loose d remove redundant packs, and run git-prune-packed f pass --no-reuse-delta to git-pack-objects F pass --no-reuse-object to git-pack-objects n do not run git-update-server-info q,quiet be quiet l pass --local to git-pack-objects unpack-unreachable= with -A, do not loosen objects older than this Packing constraints window= size of the window used for delta compression window-memory= same as the above, but limit memory size instead of entries count depth= limits the maximum delta depth max-pack-size= maximum size of each packfile '" setglobal SUBDIRECTORY_OK = ''Yes'' source git-sh-setup setglobal no_update_info = '', all_into_one = '', remove_redundant = '', unpack_unreachable = '' setglobal local = '', no_reuse = '', extra = '' while test $# != 0 { match $1 { with -n setglobal no_update_info = 't' with -a setglobal all_into_one = 't' with -A setglobal all_into_one = 't' setglobal unpack_unreachable = '--unpack-unreachable' with --unpack-unreachable setglobal unpack_unreachable = ""--unpack-unreachable=$2""; shift with -d setglobal remove_redundant = 't' with -q setglobal GIT_QUIET = 't' with -f setglobal no_reuse = '--no-reuse-delta' with -F setglobal no_reuse = '--no-reuse-object' with -l setglobal local = '--local' with --max-pack-size|--window|--window-memory|--depth setglobal extra = ""$extra $1=$2""; shift with -- shift; break with * usage } shift } match $[git config --bool repack.usedeltabaseoffset || echo true] { with true setglobal extra = ""$extra --delta-base-offset"" } setglobal PACKDIR = ""$GIT_OBJECT_DIRECTORY/pack"" setglobal PACKTMP = ""$PACKDIR/.tmp-$Pid-pack"" rm -f "$PACKTMP"-* trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15 # There will be more repacking strategies to come... match ",$all_into_one," { with ,, setglobal args = ''--unpacked --incremental'' with ,t, setglobal args = '', existing = '' if test -d $PACKDIR { for e in [$[cd $PACKDIR && find . -type f -name '*.pack' \ | sed -e 's/^\.\///' -e 's/\.pack$//]] { if test -e "$PACKDIR/$e.keep" { : keep } else { setglobal existing = ""$existing $e"" } } if test -n $existing && test -n $unpack_unreachable && \ test -n $remove_redundant { # This may have arbitrary user arguments, so we # have to protect it against whitespace splitting # when it gets run as "pack-objects $args" later. # Fortunately, we know it's an approxidate, so we # can just use dots instead. setglobal args = ""$args $[echo $unpack_unreachable | tr ' ' .]"" } } } mkdir -p $PACKDIR || exit setglobal args = ""$args $local $(GIT_QUIET:+-q) $no_reuse$extra"" setglobal names = $[git pack-objects --keep-true-parents --honor-pack-keep --non-empty --all --reflog $args &2 "WARNING: Some packs in use have been renamed by> !2 "WARNING: Some packs in use have been renamed by" echo >&2 "WARNING: prefixing old- to their name, in order to> !2 "WARNING: prefixing old- to their name, in order to" echo >&2 "WARNING: replace them with the new version of the> !2 "WARNING: replace them with the new version of the" echo >&2 "WARNING: file. But the operation failed, and> !2 "WARNING: file. But the operation failed, and" echo >&2 "WARNING: attempt to rename them back to their> !2 "WARNING: attempt to rename them back to their" echo >&2 "WARNING: original names also failed.> !2 "WARNING: original names also failed." echo >&2 "WARNING: Please rename them in $PACKDIR manually:> !2 "WARNING: Please rename them in $PACKDIR manually:" for file in [$rollback_failure] { echo >&2 "WARNING: old-$file -> $file> !2 "WARNING: old-$file -> $file" } } exit 1 } # Now the ones with the same name are out of the way... setglobal fullbases = '' for name in [$names] { setglobal fullbases = ""$fullbases pack-$name"" chmod a-w "$PACKTMP-$name.pack" chmod a-w "$PACKTMP-$name.idx" mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" && mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" || exit } # Remove the "old-" files for name in [$names] { rm -f "$PACKDIR/old-pack-$name.idx" rm -f "$PACKDIR/old-pack-$name.pack" } # End of pack replacement. if test $remove_redundant = t { # We know $existing are all redundant. if test -n $existing { shell { cd $PACKDIR && for e in [$existing] { match " $fullbases " { with *" $e "* with * rm -f "$e.pack" "$e.idx" "$e.keep" } } } } git prune-packed $(GIT_QUIET:+-q) } match $no_update_info { with t : with * git update-server-info }