]> git.ozlabs.org Git - next-scripts/blob - import-akpm
import_akpm: cope if there is no linus patch
[next-scripts] / import-akpm
1 #!/bin/bash
2
3 log_file=../akpm-import.log
4
5 log()
6 {
7         echo "$@" | tee -a $log_file
8 }
9
10 execute()
11 {
12         log "$" $@
13         "$@" 2>&1 | tee -a $log_file
14         [ ${PIPESTATUS[0]} -eq 0 ] || $SHELL -i || exit 1
15 }
16
17 mmotm="../../mmotm/text"
18 sfile="$mmotm/series"
19 cpwd=$(pwd)
20
21 [ -f "$mmotm/broken-out/origin.patch" ] &&
22         base=$(sed -n '1s/^GIT *\([^ ]*\).*$/\1/p' "$mmotm/broken-out/origin.patch")
23 [ "$base" ] ||
24         base=$(git describe --abbrev=0 origin/master)
25 nbase=$(sed -n '1s/^GIT *\([^ ]*\).*$/\1/p' "$mmotm/broken-out/linux-next.patch")
26 git rev-parse --verify "$base" >/dev/null || {
27         log "Unknown origin BASE $base"
28         exit 1
29 }
30 git rev-parse --verify "$nbase" >/dev/null || {
31         log "Unknown linux-next BASE $nbase"
32         exit 1
33 }
34 db=$(git describe "$base")
35 dnb=$(git describe --contains "$nbase")
36 log "Importing akpm based on $db/$dnb"
37
38 [ -d "../quilt-tmp" ] ||
39         execute git clone -s -l -n -q . ../quilt-tmp
40
41 log '$' cd ../quilt-tmp
42 cd ../quilt-tmp
43 execute git checkout -b akpm/master "$db"
44 git branch akpm/current-base
45
46 sed_exp='
47 /NEXT_PATCHES_START/,/NEXT_PATCHES_END/{
48         s/[ \t]*#.*NEXT_PATCHES_START[ \t]*\([^ \t]*\).*$/>\1/
49         s/[ \t]*#.*NEXT_PATCHES_END.*$/</
50         s/[ \t]*#.*$//
51         /^[ \t]*$/!p
52 }
53 /^linux-next.patch/p'
54 patches=$(sed -n "$sed_exp" "$sfile")
55
56 for f in $patches; do
57         case "$f" in
58         origin.patch)
59                 ;;
60         linux-next.patch)
61                 git branch akpm/current
62                 execute git merge --no-edit --no-stat "$dnb"
63                 git branch akpm/master-base
64                 ;;
65         \>*)
66                 cbranch="${f#>}"
67                 [ "$cbranch" ] &&
68                         cref="$(git rev-parse --verify HEAD)"
69                 ;;
70         \<)
71                 [ "$cbranch" ] && {
72                         [ "$cref" != "$(git rev-parse --verify HEAD)" ] &&
73                                 git branch -f "akpm/$cbranch"
74                         cbranch=""
75                 }
76                 ;;
77         *)
78                 execute git am --patch-format=mbox "$mmotm/broken-out/$f"
79                 ;;
80         esac
81 done
82
83 [ "$cbranch" ] &&
84         [ "$cref" != "$(git rev-parse --verify HEAD)" ] &&
85                 git branch -f "akpm/$cbranch"
86
87 log '$' cd $cpwd
88 cd $cpwd
89
90 execute git fetch --force --no-tags ../quilt-tmp \
91         refs/heads/akpm/master:refs/heads/akpm/master \
92         refs/heads/akpm/master-base:refs/heads/akpm/master-base \
93         refs/heads/akpm/current:refs/heads/akpm/current \
94         refs/heads/akpm/current-base:refs/heads/akpm/current-base
95
96 rm -rf ../quilt-tmp
97
98 exit 0