chiark / gitweb /
adapt debian/changelog for 0.8-1.1
[topgit.git] / tg-mail.sh
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # GPLv2
4
5 name=
6 send_email_args=
7 in_reply_to=
8
9
10 ## Parse options
11
12 while [ -n "$1" ]; do
13         arg="$1"; shift
14         case "$arg" in
15         -s)
16                 send_email_args="$1"; shift;;
17         -r)
18                 in_reply_to="$1"; shift;;
19         -*)
20                 echo "Usage: tg [...] mail [-s SEND_EMAIL_ARGS] [-r REFERENCE_MSGID] [NAME]" >&2
21                 exit 1;;
22         *)
23                 [ -z "$name" ] || die "name already specified ($name)"
24                 name="$arg";;
25         esac
26 done
27
28 [ -n "$name" ] || name="$(git symbolic-ref HEAD | sed 's#^refs/heads/##')"
29 base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
30         die "not a TopGit-controlled branch"
31
32 if [ -n "$in_reply_to" ]; then
33         send_email_args="$send_email_args --in-reply-to=$in_reply_to"
34 fi
35
36
37 patchfile="$(mktemp -t tg-mail.XXXXXX)"
38
39 $tg patch "$name" >"$patchfile"
40
41 header="$(sed -e '/^$/,$d' "$patchfile")"
42
43
44
45 from="$(echo "$header" | grep '^From:' | sed 's/From:\s*//')"
46 to="$(echo "$header" | grep '^To:' | sed 's/To:\s*//')"
47
48
49 people=
50 [ -n "$from" ] && people="$people --from '$from'"
51 # FIXME: there could be multimple To
52 [ -n "$to" ] && people="$people --to '$to'"
53
54 # NOTE: git-send-email handles cc itself
55 eval git send-email $send_email_args "$people" "$patchfile"
56
57 rm "$patchfile"
58
59 # vim:noet