X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=topgit.git;a=blobdiff_plain;f=tg-mail.sh;h=7b8f7ffdd61b9b9b802df04790be5d51ffa67c2a;hp=24e5f67b2742b8edf6fd6213f58d6546a27e013c;hb=4956e5734d10ac88fcca7276b402f1157644cb9b;hpb=ff2a44e9b68cfbc5f970bd07bad252607dd8179a diff --git a/tg-mail.sh b/tg-mail.sh index 24e5f67..7b8f7ff 100644 --- a/tg-mail.sh +++ b/tg-mail.sh @@ -4,6 +4,7 @@ name= send_email_args= +in_reply_to= ## Parse options @@ -13,8 +14,10 @@ while [ -n "$1" ]; do case "$arg" in -s) send_email_args="$1"; shift;; + -r) + in_reply_to="$1"; shift;; -*) - echo "Usage: tg [...] mail [-s SEND_EMAIL_ARGS] [NAME]" >&2 + echo "Usage: tg [...] mail [-s SEND_EMAIL_ARGS] [-r REFERENCE_MSGID] [NAME]" >&2 exit 1;; *) [ -z "$name" ] || die "name already specified ($name)" @@ -26,13 +29,16 @@ done base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" || die "not a TopGit-controlled branch" +if [ -n "$in_reply_to" ]; then + send_email_args="$send_email_args --in-reply-to=$in_reply_to" +fi + patchfile="$(mktemp -t tg-mail.XXXXXX)" -$tg patch $name >"$patchfile" +$tg patch "$name" >"$patchfile" -hlines=$(grep -n -m 1 '^---' "$patchfile" | sed 's/:---//') -header=$(head -n $(($hlines - 1)) "$patchfile") +header="$(sed -e '/^$/,$d' "$patchfile")" @@ -40,14 +46,12 @@ 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 -people=() -[ -n "$from" ] && people=("${people[@]}" --from "$from") +people= +[ -n "$from" ] && people="$people --from '$from'" # FIXME: there could be multimple To -[ -n "$to" ] && people=("${people[@]}" --to "$to") - +[ -n "$to" ] && people="$people --to '$to'" # NOTE: git-send-email handles cc itself -git send-email $send_email_args "${people[@]}" "$patchfile" +eval git send-email $send_email_args "$people" "$patchfile" rm "$patchfile"