8059101: unshuffle_patch.sh should be able to deal with stdin/stdout

Reviewed-by: dfuchs, chegar
This commit is contained in:
Ivan Gerasimov 2014-09-25 21:16:00 +04:00
parent ce3d3f5632
commit ea278f4b22

View File

@ -35,11 +35,11 @@ usage() {
exit 1 exit 1
} }
SCRIPT_DIR=`pwd`/`dirname $0` SCRIPT_DIR=`dirname $0`
UNSHUFFLE_LIST=$SCRIPT_DIR"/unshuffle_list.txt" UNSHUFFLE_LIST=$SCRIPT_DIR"/unshuffle_list.txt"
if [ ! -f "$UNSHUFFLE_LIST" ] ; then if [ ! -f "$UNSHUFFLE_LIST" ] ; then
echo "FATAL: cannot find $UNSHUFFLE_LIST" echo "FATAL: cannot find $UNSHUFFLE_LIST" >&2
exit 1 exit 1
fi fi
@ -68,7 +68,7 @@ done
# Make sure we have the right number of arguments # Make sure we have the right number of arguments
if [ ! $# -eq 3 ] ; then if [ ! $# -eq 3 ] ; then
echo "ERROR: Invalid number of arguments." echo "ERROR: Invalid number of arguments." >&2
usage usage
fi fi
@ -83,21 +83,28 @@ for r in $repos ; do
fi fi
done done
if [ $found = "false" ] ; then if [ $found = "false" ] ; then
echo "ERROR: Unknown repo: $repo. Should be one of [$repos]." echo "ERROR: Unknown repo: $repo. Should be one of [$repos]." >&2
usage usage
fi fi
# Check given input/output files # Check given input/output files
input="$2" input="$2"
output="$3" if [ "x$input" = "x-" ] ; then
input="/dev/stdin"
fi
if [ ! -f $input ] ; then if [ ! -f $input -a "x$input" != "x/dev/stdin" ] ; then
echo "ERROR: Cannot find input patch file: $input" echo "ERROR: Cannot find input patch file: $input" >&2
exit 1 exit 1
fi fi
if [ -f $output ] ; then output="$3"
echo "ERROR: Output patch already exists: $output" if [ "x$output" = "x-" ] ; then
output="/dev/stdout"
fi
if [ -f $output -a "x$output" != "x/dev/stdout" ] ; then
echo "ERROR: Output patch already exists: $output" >&2
exit 1 exit 1
fi fi
@ -105,7 +112,7 @@ what="" ## shuffle or unshuffle
verbose() { verbose() {
if [ ${vflag} = "true" ] ; then if [ ${vflag} = "true" ] ; then
echo "$@" echo "$@" >&2
fi fi
} }
@ -117,7 +124,7 @@ unshuffle() {
path= path=
if echo "$line" | egrep '^diff' > /dev/null ; then if echo "$line" | egrep '^diff' > /dev/null ; then
if ! echo "$line" | egrep '\-\-git' > /dev/null ; then if ! echo "$line" | egrep '\-\-git' > /dev/null ; then
echo "ERROR: Only git patches supported. Please use 'hg export --git ...'." echo "ERROR: Only git patches supported. Please use 'hg export --git ...'." >&2
exit 1 exit 1
fi fi
path="`echo "$line" | sed -e s@'diff --git a/'@@ -e s@' b/.*$'@@`" path="`echo "$line" | sed -e s@'diff --git a/'@@ -e s@' b/.*$'@@`"