#!/bin/bash VCS_SUPPORTED="Mercurial" # Optional prefix before patch name PATCH_NAME_PREFIX="" # Default revision if not specified REVS=tip print_usage() { echo "$(basename $0) -- git format-patch equivalent for Mercurial" echo "Usage: $(basename $0) [OPTIONS...]" echo echo "Options:" echo " -h display this help and exit" echo " -r [a..b] or [a-b] or [a:b]: sequence of revisions" echo " [a,b,c]: specific revisions list" echo " [a]: single revision" echo " if not specified, default is tip" } while getopts "hr:" flag ;do case ${flag} in h) print_usage exit 0 ;; r) REVS=${OPTARG} ;; ?) echo "${PROG_NAME}: Invalid option: ${OPTARG}." echo "Try \`${PROG_NAME} --help' for more information." exit 1 ;; esac done shift `expr "${OPTIND}" - 1` # `$#' now represents the number of arguments after the options. # `$1' is the first argument, etc. if [ $# -ne 0 ]; then echo "${PROG_NAME}: Too many arguments." echo "Try \`${PROG_NAME} --help' for more information." exit 1 fi if echo ${REVS} | grep -F -q ':'; then SEP_CHAR=":" elif echo ${REVS} | grep -F -q '-'; then SEP_CHAR="-" elif echo ${REVS} | grep -F -q '..'; then SEP_CHAR="\.\." elif echo ${REVS} | grep -F -q ','; then SEQ="${REVS//,/ }" fi if [ -z "${SEQ}" ]; then if [ -n "${SEP_CHAR}" ]; then START=$(echo ${REVS} | sed "s/\(.*\)${SEP_CHAR}.*/\1/") END=$(echo ${REVS} | sed "s/.*${SEP_CHAR}\(.*\)/\1/") fi if [ -z "${START}" ]; then SEQ=${REVS} else SEQ=$(seq ${START} ${END}) fi fi if hg status 1> /dev/null 2>&1; then for r in ${SEQ}; do NAME=${PATCH_NAME_PREFIX}${r}.patch echo [PATCH] ${NAME} hg export -r ${r} > ${NAME} done else echo "Not a ${VCS_SUPPORTED} repository" exit 1 fi