From dd8b18dabe03f286d1afd11c362fce3ae6e5ee14 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 3 Oct 2015 12:34:03 -0700 Subject: [PATCH] tg-patch.sh: allow git diff-tree options to be passed through This works just like the extra options for the tg log command do. Signed-off-by: Kyle J. McKay --- README | 14 +++++++++++++- tg-patch.sh | 47 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/README b/README index 1f60920..dd5d224 100644 --- a/README +++ b/README @@ -365,7 +365,19 @@ tg patch Options: -i base patch generation on index instead of branch -w base patch generation on working tree instead of branch - --binary pass --binary to ``git diff-tree`` to enable binary patches + --binary pass --binary to ``git diff-tree`` to enable generation + of binary patches + --diff-opt options after the branch name (and an optional ``--``) + are passed directly to ``git diff-tree`` + + In order to pass a sole explicit ``-w`` through to ``git diff-tree`` it + must be separated from the ``tg`` options by an explicit ``--``. + Or it can be spelled as ``--ignore-all-space`` to distinguuish it from + ``tg``'s ``-w`` option. + + If additional non-``tg`` options are passed through to + ``git diff-tree`` (other than ``--binary`` which is fully supported) + the resulting ``tg patch`` output may not be appliable. tg mail ~~~~~~~ diff --git a/tg-patch.sh b/tg-patch.sh index be8e74e..f82f709 100644 --- a/tg-patch.sh +++ b/tg-patch.sh @@ -10,22 +10,41 @@ binary= ## Parse options while [ -n "$1" ]; do - arg="$1"; shift + arg="$1" case "$arg" in + --) + case "$2" in + -*) + shift; break;; + *) + break;; + esac;; + -|-h|--help) + echo "Usage: ${tgname:-tg} [...] patch [-i | -w] [--binary] [] [--] [...]" >&2 + exit 1;; -i|-w) [ -z "$head_from" ] || die "-i and -w are mutually exclusive" head_from="$arg";; --binary) binary=1;; - -*) - echo "Usage: ${tgname:-tg} [...] patch [-i | -w] [--binary] []" >&2 - exit 1;; + -?*) + if test="$(verify_topgit_branch "$arg" -f)"; then + [ -z "$name" ] || die "name already specified ($name)" + name="$arg" + else + break + fi;; *) [ -z "$name" ] || die "name already specified ($name)" name="$arg";; esac + shift done +quotearg() { + printf '%s' "$1" | sed 's/\(['\''!]\)/'\'\\\\\\1\''/g' +} + head="$(git symbolic-ref HEAD)" head="${head#refs/heads/}" @@ -75,7 +94,25 @@ t_tree=$(pretty_tree "$name" $head_from) if [ $b_tree = $t_tree ]; then echo "No changes." else - git diff-tree -p --stat ${binary:+--binary} $b_tree $t_tree + hasdd= + for a; do + [ "$a" != "--" ] || { hasdd=1; break; } + done + if [ -z "$hasdd" ]; then + git diff-tree -p --stat --summary ${binary:+--binary} "$@" $b_tree $t_tree + else + cmd="git diff-tree -p --stat --summary ${binary:+--binary}" + while [ $# -gt 0 -a "$1" != "--" ]; do + cmd="$cmd '$(quotearg "$1")'" + shift + done + cmd="$cmd '$(quotearg "$b_tree")' '$(quotearg "$t_tree")'" + while [ $# -gt 0 ]; do + cmd="$cmd '$(quotearg "$1")'" + shift + done + eval "$cmd" + fi fi echo '-- ' -- 2.11.4.GIT