]> git.ozlabs.org Git - next-scripts/blob - import-akpm
import-akpm: make the fetch excplicit
[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 base=$(sed -n '1s/^GIT *\([^ ]*\).*$/\1/p' "$mmotm/broken-out/origin.patch")
22 nbase=$(sed -n '1s/^GIT *\([^ ]*\).*$/\1/p' "$mmotm/broken-out/linux-next.patch")
23 git rev-parse --verify "$base" >/dev/null || {
24         log "Unknown origin BASE $base"
25         exit 1
26 }
27 git rev-parse --verify "$nbase" >/dev/null || {
28         log "Unknown linux-next BASE $nbase"
29         exit 1
30 }
31 db=$(git describe "$base")
32 dnb=$(git describe --contains "$nbase")
33 log "Importing akpm based on $db/$dnb"
34
35 [ -d "../quilt-tmp" ] ||
36         execute git clone -s -l -n -q . ../quilt-tmp
37
38 log '$' cd ../quilt-tmp
39 cd ../quilt-tmp
40 execute git checkout -b akpm/master "$db"
41 git branch akpm/current-base
42
43 sed_exp='
44 /NEXT_PATCHES_START/,/NEXT_PATCHES_END/{
45         s/[ \t]*#.*NEXT_PATCHES_START[ \t]*\([^ \t]*\).*$/>\1/
46         s/[ \t]*#.*NEXT_PATCHES_END.*$/</
47         s/[ \t]*#.*$//
48         /^[ \t]*$/!p
49 }
50 /^linux-next.patch/p'
51 patches=$(sed -n "$sed_exp" "$sfile")
52
53 for f in $patches; do
54         case "$f" in
55         origin.patch)
56                 ;;
57         linux-next.patch)
58                 git branch akpm/current
59                 execute git merge --no-edit --no-stat "$dnb"
60                 git branch akpm/master-base
61                 ;;
62         \>*)
63                 cbranch="${f#>}"
64                 [ "$cbranch" ] &&
65                         cref="$(git rev-parse --verify HEAD)"
66                 ;;
67         \<)
68                 [ "$cbranch" ] && {
69                         [ "$cref" != "$(git rev-parse --verify HEAD)" ] &&
70                                 git branch -f "akpm/$cbranch"
71                         cbranch=""
72                 }
73                 ;;
74         *)
75                 execute git am --patch-format=mbox "$mmotm/broken-out/$f"
76                 ;;
77         esac
78 done
79
80 [ "$cbranch" ] &&
81         [ "$cref" != "$(git rev-parse --verify HEAD)" ] &&
82                 git branch -f "akpm/$cbranch"
83
84 log '$' cd $cpwd
85 cd $cpwd
86
87 execute git fetch --force --no-tags ../quilt-tmp \
88         refs/heads/akpm/master:refs/heads/akpm/master \
89         refs/heads/akpm/master-base:refs/heads/akpm/master-base \
90         refs/heads/akpm/current:refs/heads/akpm/current \
91         refs/heads/akpm/current-base:refs/heads/akpm/current-base
92
93 rm -rf ../quilt-tmp
94
95 exit 0