chiark / gitweb /
tg mail: new command for mailing patches
authorKirill Smelkov <kirr@landau.phys.spbu.ru>
Fri, 19 Sep 2008 09:08:21 +0000 (13:08 +0400)
committerPetr Baudis <pasky@suse.cz>
Mon, 22 Sep 2008 15:40:35 +0000 (17:40 +0200)
Petr, since you've asked for help on this, here you are:

    $ tg mail [NAME]

a simple script to send one patch over email.

All it does is

    - call `tg patch` for actual patch preparation
    - extract email addresses from whom and where to send a mail
    - boils down to `git send-email`

It is self-hosted -- this mail was send by me with

    $ tg mail t/tg-mail

P.S. I'm not a bash guy, please do not beat me too much...

Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru>
.gitignore
README
tg-mail.sh [new file with mode: 0644]

index 8fa60c723b5b8f4267e6657ec097996956e0fb82..1e90e82b202a3d022cb998c2c61049b51e7b0108 100644 (file)
@@ -5,6 +5,8 @@ tg-delete
 tg-delete.txt
 tg-info
 tg-info.txt
+tg-mail
+tg-mail.txt
 tg-patch
 tg-patch.txt
 tg-summary
diff --git a/README b/README
index 335b0cf68ca66b8c1bd1484bccdfa8dacd0a6d8b..719b919d51adf85a5ddbd56410a458870e25c006 100644 (file)
--- a/README
+++ b/README
@@ -272,6 +272,24 @@ tg patch
        TODO: tg patch -i to base at index instead of branch,
                -w for working tree
 
+tg mail
+~~~~~~~
+       Send a patch from the current or specified topic branch as
+       email.
+
+       Takes the patch given on the command line and emails it out.
+       Destination addresses such as To, Cc and Bcc are taken from the
+       patch header.
+
+       Since it actually boils down to `git send-email` please refer to
+       it's documentation for details on how to setup email for git.
+
+
+       TODO: tg mail patchfile  to mail an already exported patch
+       TODO: mailing patch series
+       TODO: specifying additional options and addresses on command
+             line
+
 tg remote
 ~~~~~~~~~
        Register given remote as TopGit-controlled. This will create
diff --git a/tg-mail.sh b/tg-mail.sh
new file mode 100644 (file)
index 0000000..f3abd2c
--- /dev/null
@@ -0,0 +1,53 @@
+#!/bin/sh
+# TopGit - A different patch queue manager
+# GPLv2
+
+name=
+
+
+## Parse options
+
+while [ -n "$1" ]; do
+       arg="$1"; shift
+       case "$arg" in
+       -*)
+               echo "Usage: tg [...] mail [NAME]" >&2
+               exit 1;;
+       *)
+               [ -z "$name" ] || die "name already specified ($name)"
+               name="$arg";;
+       esac
+done
+
+# TODO refactor me into something common?
+[ -n "$name" ] || name="$(git symbolic-ref HEAD | sed 's#^refs/heads/##')"
+base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
+       die "not a TopGit-controlled branch"
+
+
+patchfile="$(mktemp -t tg-mail.XXXXXX)"
+
+$tg patch $name >"$patchfile"
+
+hlines=$(grep -n -m 1 '^---' "$patchfile" | sed 's/:---//')
+header=$(head -$(($hlines - 1)) "$patchfile")
+
+
+
+from="$(echo "$header" | grep '^From:' | sed 's/From:\s*//')"
+to="$(echo "$header" | grep '^To:' | sed 's/To:\s*//')"
+
+
+# XXX I can't get quoting right without arrays
+[ -n "$from" ] && from=(--from "$from")
+[ -n "$to"   ] && to=(--to "$to") # FIXME there could be multimple To
+
+people=()
+[ -n "$from" ] && people=("${people[@]}" "${from[@]}")
+[ -n "$to" ]   && people=("${people[@]}" "${to[@]}")
+
+
+# NOTE git-send-email handles cc itself
+git send-email "${people[@]}" "$patchfile"
+
+rm "$patchfile"