-
Notifications
You must be signed in to change notification settings - Fork 7
/
tg-mail.sh
77 lines (60 loc) · 1.71 KB
/
tg-mail.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh
# TopGit - A different patch queue manager
# GPLv2
USAGE="\
Usage: ${tgname:-tg} [...] mail [-s <send-email-args>] [-r <reference-msgid>] [-i | -w] [<name>]
Options:
-i use TopGit metadata from index instead of HEAD branch
-w use metadata from working directory instead of branch"
usage()
{
if [ "${1:-0}" != 0 ]; then
printf '%s\n' "$USAGE" >&2
else
printf '%s\n' "$USAGE"
fi
exit ${1:-0}
}
name=
head_from=
send_email_args=
in_reply_to=
## Parse options
while [ -n "$1" ]; do
arg="$1"; shift
case "$arg" in
-h|--help)
usage;;
-i|-w)
[ -z "$head_from" ] || die "-i and -w are mutually exclusive"
head_from="$arg";;
-s)
send_email_args="$1"; shift;;
-r)
in_reply_to="$1"; shift;;
-*)
usage 1;;
*)
[ -z "$name" ] || die "name already specified ($name)"
name="$arg";;
esac
done
v_verify_topgit_branch name "${name:-HEAD}"
base_rev="$(git rev-parse --short --verify "refs/$topbases/$name^0" -- 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="$(get_temp tg-mail)"
[ -z "$head_from" ] || ensure_work_tree
# let tg patch sort out whether $head_from makes sense for $name
tg patch "$name" $head_from >"$patchfile"
header="$(sed -e '/^$/,$d' -e "s,','\\\\'',g" "$patchfile")"
from="$(echol "$header" | grep '^From:' | sed 's/From:\s*//')"
to="$(echol "$header" | grep '^To:' | sed 's/To:\s*//')"
people=
[ -n "$from" ] && people="$people --from '$from'"
# FIXME: there could be multiple To
[ -n "$to" ] && people="$people --to '$to'"
# NOTE: git-send-email handles cc itself
eval git send-email $send_email_args "$people" '"$patchfile"'