[PATCH] guilt-header: Add -e option for editing
[guilt.git] / guilt-header
blob496cb5b7d5cdf3fb4581580c937b186d9d705765
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
6 USAGE="[-e] [<patchname>]"
7 . `dirname $0`/guilt
9 if [ $# -gt 2 ]; then
10 usage
13 if [ "$1" = "-e" ]; then
14 edit=t
15 shift
18 patch="$1"
20 if [ -z "$patch" ]; then
21 # use the patch that's on the top of the stack
23 eidx=`wc -l < $applied`
24 if [ $eidx -eq 0 ]; then
25 die "Status file is empty"
27 else
28 # use the specified patch
30 eidx=`get_series | grep -ne "^$patch\$" | cut -d: -f1`
31 if [ $eidx -eq 0 ]; then
32 die "Patch $patch is not in the series"
36 idx=0
37 for p in `get_series`; do
38 idx=`expr $idx + 1`
39 [ $idx -lt $eidx ] && continue
40 [ $idx -gt $eidx ] && break
42 if [ -z "$edit" ]; then
43 do_get_header $GUILT_DIR/$branch/$p
44 else
45 do_get_full_header $GUILT_DIR/$branch/$p > /tmp/guilt.msg.$$
46 do_get_patch $GUILT_DIR/$branch/$p > /tmp/guilt.diff.$$
47 $editor "/tmp/guilt.msg.$$"
48 mv $GUILT_DIR/$branch/$p $GUILT_DIR/$branch/$p~
49 cat /tmp/guilt.msg.$$ > $GUILT_DIR/$branch/$p
50 cat /tmp/guilt.diff.$$ >> $GUILT_DIR/$branch/$p
52 done