]> git.ozlabs.org Git - next-scripts/blob - import-akpm
import-akpm: use a worktree
[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"
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=$(tail -n 1 "$mmotm/.DATE")
25         base=${base#v}
26         base="v${base}"
27 }
28 nbase=$(sed -n '1s/^GIT *\([^ ]*\).*$/\1/p' "$mmotm/broken-out/linux-next.patch")
29 git rev-parse --verify "$base" >/dev/null || {
30         log "Unknown origin BASE $base"
31         exit 1
32 }
33 git rev-parse --verify "$nbase" >/dev/null || {
34         log "Unknown linux-next BASE $nbase"
35         exit 1
36 }
37 db=$(git describe "$base")
38 dnb=$(git describe --contains "$nbase")
39 log "Importing akpm based on $db/$dnb"
40
41 [ -d "../tmp-akpm" ] && {
42         log "akpm import directory already exists"
43         exit 1
44 }
45
46 execute git worktree add -b tmp-akpm/master ../tmp-akpm "$db"
47
48 log '$' cd ../tmp-akpm
49 cd ../tmp-akpm
50 execute git branch tmp-akpm/current-base
51
52 sed_exp='
53 /NEXT_PATCHES_START/,/NEXT_PATCHES_END/{
54         s/[ \t]*#.*$//
55         /^[ \t]*$/!p
56 }
57 /^linux-next.patch/p'
58 patches=$(sed -n "$sed_exp" "$sfile")
59
60 for f in $patches; do
61         case "$f" in
62         origin.patch)
63                 ;;
64         linux-next.patch)
65                 execute git branch tmp-akpm/current
66                 execute git merge --no-edit --no-stat "$dnb"
67                 execute git branch tmp-akpm/master-base
68                 ;;
69         *)
70                 execute git am -s --patch-format=mbox "$mmotm/broken-out/$f"
71                 ;;
72         esac
73 done
74
75 log '$' cd $cpwd
76 cd $cpwd
77
78 execute rm -rf ../tmp-akpm
79 execute git worktree prune
80
81 for i in akpm/current akpm/current-base akpm/master akpm/master-base; do
82         execute git branch -f $i tmp-$i
83         execute git branch -D tmp-$i
84 done
85
86 exit 0