Ajout équivalent de git format-patch pour Mercurial
authorHugo Villeneuve <hugo@hugovil.com>
Fri, 21 Jun 2013 19:03:32 +0000 (15:03 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Fri, 21 Jun 2013 19:03:32 +0000 (15:03 -0400)
scripts/Makefile.am
scripts/hg-format-patch [new file with mode: 0755]

index 63baeb0..d6bd5e1 100644 (file)
@@ -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 (executable)
index 0000000..9202c5b
--- /dev/null
@@ -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