make-tar add -v and -d arguments
Add -d developer mode to permit export of branches and raw revisions. Switch to bash for builtin getopts
This commit is contained in:
@@ -1,22 +1,26 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
#
|
||||
# Make tar for git repo w/ one level of sub modules.
|
||||
#
|
||||
set -e
|
||||
set -e -u
|
||||
|
||||
die() {
|
||||
echo "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
TOPREV="$1"
|
||||
FINALTAR="$2"
|
||||
PREFIX="$3"
|
||||
maybedie() {
|
||||
if [ "$DEVMODE" ]; then
|
||||
echo "Warning: $1" >&2
|
||||
else
|
||||
echo "Error: $1" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
if ! [ "$TOPREV" ]
|
||||
then
|
||||
usage() {
|
||||
cat <<EOF >&2
|
||||
usage: $0 <rev> [<outfile> [<prefix>]]
|
||||
usage: $0 [-v] [-s] <rev> [<outfile> [<prefix>]]
|
||||
|
||||
<rev> may be any git revision spec. (tag, branch, or commit id).
|
||||
|
||||
@@ -24,9 +28,33 @@ usage: $0 <rev> [<outfile> [<prefix>]]
|
||||
If <outfile> is omitted, "base-<rev>.tar.gz" will be used.
|
||||
If provided, <prefix> must end with "/". If <prefix> is omitted,
|
||||
the default is "base-<rev>/".
|
||||
|
||||
Options:
|
||||
|
||||
-v Enable verbose prints
|
||||
-d Enable permissive developer mode
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
export DEVMODE=
|
||||
|
||||
while getopts "vd" OPT
|
||||
do
|
||||
case "$OPT" in
|
||||
v) set -x;;
|
||||
d) DEVMODE=1;;
|
||||
?) echo "Unknown option"
|
||||
usage;;
|
||||
esac
|
||||
done
|
||||
shift $(($OPTIND - 1))
|
||||
|
||||
TOPREV="$1"
|
||||
FINALTAR="$2"
|
||||
PREFIX="${3:-}"
|
||||
|
||||
[ "$TOPREV" ] || usage
|
||||
|
||||
case "$FINALTAR" in
|
||||
"")
|
||||
@@ -59,16 +87,13 @@ case "$PREFIX" in
|
||||
esac
|
||||
|
||||
# Check for both <tag> and R<tag>
|
||||
if [ "$TOPREV" = "HEAD" ]
|
||||
then
|
||||
true
|
||||
elif ! [ `git tag -l $TOPREV` ]
|
||||
if ! [ `git tag -l $TOPREV` ]
|
||||
then
|
||||
if [ `git tag -l R$TOPREV` ]
|
||||
then
|
||||
TOPREV="R$TOPREV"
|
||||
else
|
||||
die "No tags exist '$TOPREV' or 'R$TOPREV'"
|
||||
maybedie "No tags exist '$TOPREV' or 'R$TOPREV'"
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -94,7 +119,12 @@ git ls-tree -r $TOPREV | \
|
||||
while read HASH MODDIR
|
||||
do
|
||||
echo "Visiting $HASH $MODDIR"
|
||||
git -C $MODDIR archive --prefix=${PREFIX}${MODDIR}/ $HASH | tar -C "$TDIR"/tar -x
|
||||
if [ -e $MODDIR/.git ]
|
||||
then
|
||||
git -C $MODDIR archive --prefix=${PREFIX}${MODDIR}/ $HASH | tar -C "$TDIR"/tar -x
|
||||
else
|
||||
maybedie " Submodule not checked out."
|
||||
fi
|
||||
done
|
||||
|
||||
# make a list of files copied and filter out undesirables
|
||||
@@ -134,5 +164,5 @@ tar -t $TAROPT -f "$FINALTAR" > "$TDIR"/list.3
|
||||
# make sure we haven't picked up anything extra
|
||||
if ! diff -u "$TDIR"/list.2 "$TDIR"/list.3
|
||||
then
|
||||
echo "Oops! Tarfile diff against plan shown above"
|
||||
die "Oops! Tarfile diff against plan shown above"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user