git-repack.shon commit gitweb: Uniquify version info output, add meta generator in page header (d4baf9e)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Linus Torvalds
   4#
   5
   6USAGE='[-a] [-d] [-f] [-l] [-n] [-q]'
   7. git-sh-setup
   8
   9no_update_info= all_into_one= remove_redundant=
  10local= quiet= no_reuse_delta= extra=
  11while case "$#" in 0) break ;; esac
  12do
  13        case "$1" in
  14        -n)     no_update_info=t ;;
  15        -a)     all_into_one=t ;;
  16        -d)     remove_redundant=t ;;
  17        -q)     quiet=-q ;;
  18        -f)     no_reuse_delta=--no-reuse-delta ;;
  19        -l)     local=--local ;;
  20        --window=*) extra="$extra $1" ;;
  21        --depth=*) extra="$extra $1" ;;
  22        *)      usage ;;
  23        esac
  24        shift
  25done
  26
  27rm -f .tmp-pack-*
  28PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
  29
  30# There will be more repacking strategies to come...
  31case ",$all_into_one," in
  32,,)
  33        rev_list='--unpacked'
  34        pack_objects='--incremental'
  35        ;;
  36,t,)
  37        rev_list=
  38        pack_objects=
  39
  40        # Redundancy check in all-into-one case is trivial.
  41        existing=`cd "$PACKDIR" && \
  42            find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
  43        ;;
  44esac
  45pack_objects="$pack_objects $local $quiet $no_reuse_delta$extra"
  46name=$( { git-rev-list --objects --all $rev_list ||
  47          echo "git-rev-list died with exit code $?"
  48        } |
  49        git-pack-objects --non-empty $pack_objects .tmp-pack) ||
  50        exit 1
  51if [ -z "$name" ]; then
  52        echo Nothing new to pack.
  53else
  54        if test "$quiet" != '-q'; then
  55            echo "Pack pack-$name created."
  56        fi
  57        mkdir -p "$PACKDIR" || exit
  58
  59        for sfx in pack idx
  60        do
  61                if test -f "$PACKDIR/pack-$name.$sfx"
  62                then
  63                        mv -f "$PACKDIR/pack-$name.$sfx" \
  64                                "$PACKDIR/old-pack-$name.$sfx"
  65                fi
  66        done &&
  67        mv -f .tmp-pack-$name.pack "$PACKDIR/pack-$name.pack" &&
  68        mv -f .tmp-pack-$name.idx  "$PACKDIR/pack-$name.idx" &&
  69        test -f "$PACKDIR/pack-$name.pack" &&
  70        test -f "$PACKDIR/pack-$name.idx" || {
  71                echo >&2 "Couldn't replace the existing pack with updated one."
  72                echo >&2 "The original set of packs have been saved as"
  73                echo >&2 "old-pack-$name.{pack,idx} in $PACKDIR."
  74                exit 1
  75        }
  76        rm -f "$PACKDIR/old-pack-$name.pack" "$PACKDIR/old-pack-$name.idx"
  77fi
  78
  79if test "$remove_redundant" = t
  80then
  81        # We know $existing are all redundant only when
  82        # all-into-one is used.
  83        if test "$all_into_one" != '' && test "$existing" != ''
  84        then
  85                sync
  86                ( cd "$PACKDIR" &&
  87                  for e in $existing
  88                  do
  89                        case "$e" in
  90                        ./pack-$name.pack | ./pack-$name.idx) ;;
  91                        *)      rm -f $e ;;
  92                        esac
  93                  done
  94                )
  95        fi
  96        git-prune-packed
  97fi
  98
  99case "$no_update_info" in
 100t) : ;;
 101*) git-update-server-info ;;
 102esac