patchbomb: Use munge_hash_range
[guilt.git] / guilt-patchbomb
blob958990f2c3cb41b2043e983387c82b4a5379752f
1 #!/bin/bash
3 # Copyright (c) Josef "Jeff" Sipek, 2007
6 DO_NOT_CHECK_BRANCH_EXISTENCE=1
7 source "`dirname $0`/guilt"
9 USAGE="$USAGE [-n] [<hash> | <since>..[<until>] | ..<until>]"
11 case $# in
13 r="$1"
16 r="$2"
17 do_not_send=t
19 if [ "$1" != "-n" ]; then
20 print_usage
21 exit 1
25 print_usage
26 exit 1
28 esac
30 r=`munge_hash_range $r`
32 # FIXME: allow in-reply-to
34 # find a suitable pager (this might be a good candidate for putting it into
35 # the lib)
36 pager="$PAGER"
37 if [ -z "$pager" ]; then
38 pager="more"
41 # display the list of commits to be sent as patches
42 git-log --pretty=oneline "$r" | cut -c 1-8,41- | $pager
44 echo -n "Are these what you want to send? [Y/n] "
45 read n
46 if [ "$n" = "n" -o "$n" = "N" ]; then
47 echo "Aborting..."
48 exit 0
51 dir=/tmp/patches-$RANDOM/
52 if [ -e $dir ]; then
53 echo "Conspiracy uncovered: Temporary dir '$dir' already exists" >&2
54 exit 1
56 echo "Using '$dir' as temporary directory"
58 git-format-patch -o $dir -n -s "$r"
60 # get the to/cc addresses
61 echo -n "Enter all the To: email addresses (separated by space): "
62 read rawto
63 echo -n "Enter all the Cc: email addresses (separated by space): "
64 read rawcc
66 # convert list of email addresses to command line options
67 to_opts=""
68 for rt in $rawto; do
69 to_opts="$to_opts --to $rt"
70 done
71 for rc in $rawcc; do
72 to_opts="$to_opts --cc $rc"
73 done
75 opts=""
76 # FIXME: if more than one patch:
77 opts="--no-chain-reply-to --compose"
78 # fi
79 opts="$opts $to_opts"
81 # last possible point to abort!
82 echo "About to execute 'git-send-email $opts $dir'"
83 echo -n "Proceed with patchbomb (this is the last chance to abort)? [y/N] "
84 read n
85 if [ "$n" != "y" -a "$n" != "Y" ]; then
86 echo "Aborting..."
87 exit 0
90 # ...and off they go.
91 if [ -z "$do_not_send" ]; then
92 git-send-email $opts $dir
93 else
94 echo "-n passed: not sending, command that would be executed:" >&2
95 echo git-send-email $opts $dir
98 # cleanup?
99 echo -n "Delete temporary directory? [Y/n] "
100 read n
102 [ "$n" != "n" -a "$n" != "N" ] && exit 0
103 rm -rf $dir