From 48a944a21b629ce72d2008a18900e8ab626ea969 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Fri, 21 Jun 2013 15:03:32 -0400 Subject: [PATCH] =?utf8?q?Ajout=20=C3=A9quivalent=20de=20git=20format-patc?= =?utf8?q?h=20pour=20Mercurial?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- scripts/Makefile.am | 2 +- scripts/hg-format-patch | 82 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100755 scripts/hg-format-patch diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 63baeb0..d6bd5e1 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -18,7 +18,7 @@ dist_bin_SCRIPTS = \ setdate \ strip-debug-symbols \ tildes-clean \ - vb vd vl vs \ + vb vd vl vs hg-format-patch \ flac2ogg flac2mp3 \ hv-scan \ tape-backup tape-backup-mult tape-list tape-restore diff --git a/scripts/hg-format-patch b/scripts/hg-format-patch new file mode 100755 index 0000000..9202c5b --- /dev/null +++ b/scripts/hg-format-patch @@ -0,0 +1,82 @@ +#!/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 -- 2.20.1