Signed-off-by: Nguyễn Thái Ngọc Duy <pclo...@gmail.com>
---
 Documentation/git-repack.txt |  6 +++++-
 git-repack.sh                |  8 +++++++-
 t/t7700-repack.sh            | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-repack.txt b/Documentation/git-repack.txt
index 4c1aff6..c43eb4a 100644
--- a/Documentation/git-repack.txt
+++ b/Documentation/git-repack.txt
@@ -9,7 +9,7 @@ git-repack - Pack unpacked objects in a repository
 SYNOPSIS
 --------
 [verse]
-'git repack' [-a] [-A] [-d] [-f] [-F] [-l] [-n] [-q] [--window=<n>] 
[--depth=<n>]
+'git repack' [options]
 
 DESCRIPTION
 -----------
@@ -110,6 +110,10 @@ other objects in that pack they already have locally.
        The default is unlimited, unless the config variable
        `pack.packSizeLimit` is set.
 
+--pack-version=<version>::
+       Force the version for the generated pack.
+       Valid values are 2 and 4. Default value is specified by
+       core.preferredPackVersion setting. See linkgit:git-config[1].
 
 Configuration
 -------------
diff --git a/git-repack.sh b/git-repack.sh
index 7579331..0d898eb 100755
--- a/git-repack.sh
+++ b/git-repack.sh
@@ -21,12 +21,13 @@ 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
+pack-version=   format version of the output pack
 "
 SUBDIRECTORY_OK='Yes'
 . git-sh-setup
 
 no_update_info= all_into_one= remove_redundant= unpack_unreachable=
-local= no_reuse= extra=
+local= no_reuse= extra= packver=
 while test $# != 0
 do
        case "$1" in
@@ -43,6 +44,8 @@ do
        -l)     local=--local ;;
        --max-pack-size|--window|--window-memory|--depth)
                extra="$extra $1=$2"; shift ;;
+       --pack-version)
+               packver="$2"; shift ;;
        --) shift; break;;
        *)      usage ;;
        esac
@@ -92,6 +95,9 @@ esac
 
 mkdir -p "$PACKDIR" || exit
 
+[ -n "$packver" ] || packver="`git config --int core.preferredPackVersion`"
+[ -n "$packver" ] && args="$args --version=$packver"
+
 args="$args $local ${GIT_QUIET:+-q} $no_reuse$extra"
 names=$(git pack-objects --keep-true-parents --honor-pack-keep --non-empty 
--all --reflog $args </dev/null "$PACKTMP") ||
        exit 1
diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index d954b84..8383e1b 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -164,5 +164,40 @@ test_expect_success 'objects made unreachable by grafts 
only are kept' '
        git cat-file -t $H1
        '
 
+test_expect_success 'repack respects core.preferredPackVersion' '
+       git init pv4 &&
+       (
+               unset GIT_TEST_PACKV4 &&
+               cd pv4 &&
+               test_commit one &&
+               test_commit two &&
+               test_commit three &&
+               git config core.preferredPackVersion 4 &&
+               git repack -ad &&
+               P=`ls .git/objects/pack/pack-*.pack` &&
+               # Offset 4 is pack version
+               test-dump ntohl "$P" 4 >ver.actual &&
+               echo 4 >ver.expected &&
+               test_cmp ver.expected ver.actual
+       )
+'
+
+test_expect_success 'repack --pack-version=4' '
+       git init pv4.2 &&
+       (
+               unset GIT_TEST_PACKV4 &&
+               cd pv4.2 &&
+               test_commit one &&
+               test_commit two &&
+               test_commit three &&
+               git repack -ad --pack-version=4 &&
+               P=`ls .git/objects/pack/pack-*.pack` &&
+               # Offset 4 is pack version
+               test-dump ntohl "$P" 4 >ver.actual &&
+               echo 4 >ver.expected &&
+               test_cmp ver.expected ver.actual
+       )
+'
+
 test_done
 
-- 
1.8.2.82.gc24b958

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to