forked from qemu/qemu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush_new_series.sh
executable file
·90 lines (79 loc) · 2.47 KB
/
push_new_series.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
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
set -euo pipefail
die()
{
echo 1>&2 "$@"
exit 1
}
# return URL for mailboxes for previous, current and next month. This way, we
# don't miss any email, even with different timezones.
mailbox_archives()
{
current_date=$1
current_month=$(date +%m --date "$current_date")
current_year=$(date +%Y --date "$current_date")
if [ $current_month == "01" ]; then
previous_month=12
previous_year=$((current_year - 1))
elif [ $current_month == "12" ]; then
next_month=01
next_year=$((current_year + 1))
else
previous_year=$current_year
next_year=$current_year
previous_month=$(printf "%02d" $((current_month - 1)))
next_month=$(printf "%02d" $((current_month + 1)))
fi
qemu_archive="https://lists.gnu.org/archive/mbox/qemu-devel/"
echo $qemu_archive$previous_year-$previous_month \
$qemu_archive$current_year-$current_month \
$qemu_archive$next_year-$next_month
}
# download all emails for previous, current and next month.
fetch_mails()
{
out=$1
rm -rf $out
mkdir -p $out
mkdir -p $out.mailbox
pushd $out.mailbox
archives=$(mailbox_archives "$(date)")
# we can have missing current or next mailbox
wget --no-clobber $archives || true
popd
git mailsplit -o$out $out.mailbox/*
}
find_series()
{
mail_dir=$1
# find all message id, for mails without a reference (i.e. first in series).
# we reverse sort to bring newest series first.
grep -Lri '^References:' $mail_dir | sort -r | while read m
do
msg_id=$(grep -i '^message-id: ' $m | head -n1 | sed -e 's/.*<//' -e 's/>$//')
date=$(grep -i '^date: ' $m | head -n1 | sed -e 's/^date: //I')
echo "$msg_id|$date"
done
}
git remote remove upstream || true
git remote add upstream -f https://gitlab.com/qemu-project/qemu
fetch_mails mails
find_series mails | while read s
do
msg_id=$(echo "$s" | cut -f 1 -d '|')
date=$(echo "$s" | cut -f 2 -d '|')
echo $msg_id
echo $date
base_git_revision=$(git log -n1 --format=format:%H --before="$date" --first-parent upstream/master)
echo $base_git_revision
git checkout "$base_git_revision"
git branch -D $msg_id || true
if git checkout -b $msg_id; then
if ! b4 shazam $msg_id |& tee apply.log; then
git am --abort
git add apply.log
git commit -m 'am failed'
fi
git push --set-upstream origin $msg_id
fi
done