This applies the same treatment to tg-patch like tg-files got in v2. Signed-off-by: Bert Wesarg <bert.wesarg@xxxxxxxxxxxxxx> --- tg-patch.sh | 56 ++++++++++++++++++++++++++++++++------------------------ 1 files changed, 32 insertions(+), 24 deletions(-) diff --git a/tg-patch.sh b/tg-patch.sh index 7bafdfe..0ebef7a 100644 --- a/tg-patch.sh +++ b/tg-patch.sh @@ -4,11 +4,8 @@ # GPLv2 name= - topic= -diff_opts= -diff_committed_only=yes # will be unset for index/worktree - +topic_for_pretty_tree= ## Parse options @@ -16,12 +13,13 @@ while [ -n "$1" ]; do arg="$1"; shift case "$arg" in -i) + [ -z "$topic" ] || die "-i and -w are mutually exclusive" topic='(i)' - diff_opts="$diff_opts --cached"; - diff_committed_only=;; + topic_for_pretty_tree=-i;; -w) + [ -z "$topic" ] || die "-i and -w are mutually exclusive" topic='(w)' - diff_committed_only=;; + topic_for_pretty_tree=-w;; -*) echo "Usage: tg [...] patch [-i | -w] [NAME]" >&2 exit 1;; @@ -32,7 +30,7 @@ while [ -n "$1" ]; do done -[ -n "$name" -a -z "$diff_committed_only" ] && +[ -n "$name" -a -n "$topic" ] && die "-i/-w are mutually exclusive with NAME" [ -n "$name" ] || name="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')" @@ -46,22 +44,32 @@ base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" setup_pager -cat_file "$topic:.topmsg" -echo -[ -n "$(git grep $diff_opts '^[-]--' ${diff_committed_only:+"$name"} -- ".topmsg")" ] || echo '---' - -# Evil obnoxious hack to work around the lack of git diff --exclude -git_is_stupid="$(mktemp -t tg-patch-changes.XXXXXX)" -git diff --name-only $diff_opts "$base_rev" ${diff_committed_only:+"$name"} -- | - fgrep -vx ".topdeps" | - fgrep -vx ".topmsg" >"$git_is_stupid" || : # fgrep likes to fail randomly? -if [ -s "$git_is_stupid" ]; then - cd "$root_dir" - cat "$git_is_stupid" | xargs git diff -a --patch-with-stat $diff_opts "$base_rev" ${diff_committed_only:+"$name"} -- -else - echo "No changes." -fi -rm "$git_is_stupid" +# put out the commit message +# and put an empty line out, if the last one in the message was not an empty line +# and put out "---" if the commit message does not have one yet +cat_file "$topic:.topmsg" | + awk ' +/^---/ { + has_3dash=1; +} + { + need_empty = 1; + if ($0 == "") + need_empty = 0; + print; +} +END { + if (need_empty) + print ""; + if (!has_3dash) + print "---"; +} +' + +b_tree=$(pretty_tree "$name" -b) +t_tree=$(pretty_tree "$name" $topic_for_pretty_tree) + +git diff-tree -p --stat -r $b_tree $t_tree echo '-- ' echo "tg: ($base_rev..) $name (depends on: $(cat_file "$topic:.topdeps" | paste -s -d' '))" -- tg: (c9ca19b..) bw/tg-patch-pretty_tree (depends on: bw/files) -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html