summaryrefslogtreecommitdiff
path: root/stale/make_patchlist.sh
blob: 3168b9f3e84b28ecaf243546d379bac4ffd80fa4 (plain)
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
#!/bin/bash

MBOX=/tmp/mbox
PATCH_DIR=/tmp/patches
PATCH_SERIES=/tmp/series
sources=~/sources


# Read patch series and import inside a git tree using guilt

guilt_import() {
	for i in `tac $PATCH_SERIES`; do
		echo "Importing: $i"
		echo $PATCH_DIR/$i
		guilt import $PATCH_DIR/$i
	done
}


# Open a dialog with a list based on directories under $source directory, each
# directory should be a git repository where the patches will be imported

apply_patch() {
        repolist=$(ls $sources | awk '{print $1,$1}')
	tempfile=/tmp/item_menu.$$

        dialog --clear --menu "Select repository to apply the patch" 0 0 20 $repolist 2> $tempfile
        #"Select repository to apply the patch" 30 60 20 $repolist 2> $tempfile

        repo=`cat $tempfile`

        cd $sources/$repo
	guilt init
	guilt_import
	rm -rf $tempfile
}


# Reads all files under a mailbox and its sub-directories (cur, new, tmp
# usually), and transform all emails under there in patches to be applied to a
# git tree

mkdir $PATCH_DIR
for dir in `ls $MBOX`; do
	for i in `ls $MBOX/$dir`; do
		FILE=$MBOX/$dir/$i
		SUBJ=`cat $FILE|formail -xSubject`
		TITLE=`echo $SUBJ| sed -e '{ s@\[@@g; s@\]@@g; s@[*()" \t]@_@g;s@[/:]@-@g; s@^ \+@@; s@\.\.@.@g; s@-_@_@g; s@__@_@g; s@\.$@@; }' | cut -c 1-70`.patch
		SUBJ=`echo $SUBJ | sed -e 's/\[[^]]*\]//'`
		PATCH=$PATCH_DIR/$TITLE
		echo $TITLE >> $PATCH_SERIES
		echo $SUBJ > $PATCH
		cat $FILE | formail -I "" >> $PATCH
	done
done


apply_patch
rm -rf $PATCH_SERIES
rm -rf $MBOX

#clean patches
rm -rf $PATCH_DIR