chiark / gitweb /
New contrib scripts: stg-dispatch and stg-show.
authorYann Dirson <yann.dirson@sagem.com>
Mon, 20 Aug 2007 21:35:59 +0000 (22:35 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Mon, 20 Aug 2007 21:36:31 +0000 (22:36 +0100)
Signed-off-by: Yann Dirson <ydirson@altern.org>
contrib/stg-dispatch [new file with mode: 0755]
contrib/stg-show [new file with mode: 0755]

diff --git a/contrib/stg-dispatch b/contrib/stg-dispatch
new file mode 100755 (executable)
index 0000000..8911946
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/sh
+set -e
+
+# stg-dispatch - percollates files matching a pattern down to another patch.
+# It does the same job as stg-fold-files-from (and makes use of it to
+# do so), but from the patch containing the changes to migrate,
+# instead of doing so from the target patch.
+
+# usage: stg-dispatch <topatch> [-#<n>[-<n>][,<n>]...] <file-pattern>
+
+# Copyright (c) 2007 Yann Dirson <ydirson@altern.org>
+# Subject to the GNU GPL, version 2.
+
+die()
+{
+    echo >&2 "$(basename $0) error: $*"
+    exit 1
+}
+
+TOPATCH="$1"
+shift
+
+stg applied | grep "^$TOPATCH\$" >/dev/null ||
+    die "cannot dispatch to unapplied patch '$TOPATCH'"
+
+CURRENTPATCH=$(stg top)
+
+[ "x$TOPATCH" != "x$CURRENTPATCH" ] ||
+    die "dispatching to current patch ($CURRENTPATCH) makes no sense"
+
+stg goto "$TOPATCH"
+stg-fold-files-from "$CURRENTPATCH" "$@"
+stg refresh
+stg goto "$CURRENTPATCH"
diff --git a/contrib/stg-show b/contrib/stg-show
new file mode 100755 (executable)
index 0000000..8c61540
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/bash
+set -e
+
+# stg-show - unlike "stg show", just "git show" with knowledge of stg refs
+
+# Ex:
+# stg-show --color-words -- files
+
+# Copyright (c) 2007 Yann Dirson <ydirson@altern.org>
+# Subject to the GNU GPL, version 2.
+
+command=(git show)
+
+# subsitute git id's for stg ones until --
+endofpatches=0
+while [ "$#" -gt 0 ]; do
+    case "$1" in
+       --) endofpatches=1; break ;;
+       -*) command+=("$1"); shift ;;
+       *) command+=( $(stg id "$1" 2>/dev/null || echo "$1") ); shift ;;
+    esac
+done
+
+# append remaining args
+command+=("$@")
+
+eval "${command[@]}"