| 1 |
#!/bin/bash
|
| 2 |
#
|
| 3 |
# This script goes with the Makefile hacks for git/branch builds.
|
| 4 |
#
|
| 5 |
|
| 6 |
nopatches=1
|
| 7 |
if [ "x$1" = "x--fedora" ]; then
|
| 8 |
nopatches=0
|
| 9 |
shift
|
| 10 |
patchcomment="plus Fedora patches"
|
| 11 |
else
|
| 12 |
patchcomment="no Fedora patches"
|
| 13 |
fi
|
| 14 |
|
| 15 |
name=
|
| 16 |
if [ "x$1" = "x--name" ]; then
|
| 17 |
shift
|
| 18 |
name="$1"
|
| 19 |
shift
|
| 20 |
fi
|
| 21 |
|
| 22 |
if [ $# -lt 2 ]; then
|
| 23 |
echo >&2 "Usage: GIT_DIR=REPO $0 [--fedora] [--name NAME]\
|
| 24 |
TARBALL-TAG [PATCH-TAG...] BRANCH..."
|
| 25 |
exit 2
|
| 26 |
fi
|
| 27 |
|
| 28 |
base=$1
|
| 29 |
shift
|
| 30 |
base_rev=`git-rev-parse "$base"` || exit
|
| 31 |
|
| 32 |
patchbase=10
|
| 33 |
nextpatch=$patchbase
|
| 34 |
usepatch()
|
| 35 |
{
|
| 36 |
patches[$nextpatch]=$1
|
| 37 |
nextpatch=$(($nextpatch + 1))
|
| 38 |
}
|
| 39 |
|
| 40 |
lasturl=:
|
| 41 |
loglines="- Experimental build from git sources ($patchcomment)\\
|
| 42 |
"
|
| 43 |
log()
|
| 44 |
{
|
| 45 |
local logrev=$1
|
| 46 |
local logbranch=$3
|
| 47 |
local ref
|
| 48 |
ref=`git-symbolic-ref -q $logbranch` && logbranch=$ref
|
| 49 |
case $logbranch in
|
| 50 |
refs/remotes/*)
|
| 51 |
logbranch=${logbranch#refs/remotes/}
|
| 52 |
local remote=${logbranch%%/*}
|
| 53 |
logbranch=${logbranch#*/}
|
| 54 |
logbranch=${logbranch//\//-}
|
| 55 |
local url
|
| 56 |
url=`git-config "remote.${remote}.url"` || {
|
| 57 |
echo >&2 "Cannot find URL for remote $remote"
|
| 58 |
exit 2
|
| 59 |
}
|
| 60 |
if [ "$url" != "$lasturl" ]; then
|
| 61 |
lasturl="$url"
|
| 62 |
loglines="${loglines}- $url\\
|
| 63 |
"
|
| 64 |
fi
|
| 65 |
logtext="$(printf %12s "remote: ")$logbranch"
|
| 66 |
;;
|
| 67 |
*)
|
| 68 |
lasturl=:
|
| 69 |
logtext="$(printf %-12s "git $2:")$logbranch"
|
| 70 |
;;
|
| 71 |
esac
|
| 72 |
loglines="${loglines}- $(printf %-35s "$logtext") ${logrev}\\
|
| 73 |
"
|
| 74 |
}
|
| 75 |
|
| 76 |
patch_headers()
|
| 77 |
{
|
| 78 |
p=$patchbase
|
| 79 |
while [ $p -lt $nextpatch ]; do
|
| 80 |
echo "Patch$p: ${patches[$p]}\\"
|
| 81 |
p=$(($p + 1))
|
| 82 |
done
|
| 83 |
}
|
| 84 |
|
| 85 |
patch_apply()
|
| 86 |
{
|
| 87 |
p=$patchbase
|
| 88 |
while [ $p -lt $nextpatch ]; do
|
| 89 |
# echo "%patch$p -p1\\"
|
| 90 |
echo "ApplyPatch ${patches[$p]}\\"
|
| 91 |
p=$(($p + 1))
|
| 92 |
done
|
| 93 |
}
|
| 94 |
|
| 95 |
base_rev()
|
| 96 |
{
|
| 97 |
local base=$1
|
| 98 |
tag_rev=`git-rev-parse --revs-only --verify "$base^{}" 2> /dev/null` &&
|
| 99 |
[ "`git-describe --tags $tag_rev`" = "$base" ] && return 0
|
| 100 |
case "$1" in
|
| 101 |
v*-git*)
|
| 102 |
local id=patch-${1#v}.id
|
| 103 |
if [ ! -r $id ]; then
|
| 104 |
make download UPSTREAM_FILES=$id UPSTREAM_CHECKS=-- > /dev/null 2>&1
|
| 105 |
fi
|
| 106 |
[ -r $id ] && tag_rev=`cat $id` && return 0
|
| 107 |
;;
|
| 108 |
v2*)
|
| 109 |
echo >&2 "Cannot find tag $base"
|
| 110 |
exit 2
|
| 111 |
;;
|
| 112 |
esac
|
| 113 |
return 1
|
| 114 |
}
|
| 115 |
|
| 116 |
log $base_rev base $base
|
| 117 |
while base_rev $1; do
|
| 118 |
base=$1
|
| 119 |
base_rev=$tag_rev
|
| 120 |
shift
|
| 121 |
patchfile=patch-${base#v}.bz2
|
| 122 |
fgrep -q $patchfile sources || usepatch $patchfile
|
| 123 |
log $tag_rev tag $base
|
| 124 |
done
|
| 125 |
version=${base#v}
|
| 126 |
|
| 127 |
now="`date +'%Y-%m-%d %H:%M %Z'`"
|
| 128 |
|
| 129 |
GIT_DIFF_OPTS=-pu
|
| 130 |
export GIT_DIFF_OPTS
|
| 131 |
|
| 132 |
i=0
|
| 133 |
last_base=$base
|
| 134 |
last_base_rev=$base_rev
|
| 135 |
for branch; do
|
| 136 |
branch_rev=`git-rev-parse "$branch^{}"` || exit 2
|
| 137 |
merge_base=`git-merge-base $last_base_rev $branch_rev` || {
|
| 138 |
echo >&2 "No common ancestor for $last_base and $branch"
|
| 139 |
exit 2
|
| 140 |
}
|
| 141 |
if ((i > 0)) && [ "x$merge_base" = "x${merge_rev[$(($i - 1))]}" ]; then
|
| 142 |
echo >&2 "$last_base is not an ancestor of $branch"
|
| 143 |
exit 2
|
| 144 |
fi
|
| 145 |
merge_rev[$i]=$merge_base
|
| 146 |
((i++))
|
| 147 |
last_base=$branch
|
| 148 |
last_base_rev=$branch_rev
|
| 149 |
done
|
| 150 |
merge_rev[$i]=$last_base_rev
|
| 151 |
|
| 152 |
test "x${merge_rev[0]}" = "x$base_rev" || {
|
| 153 |
echo >&2 "$base is not an ancestor of $branch"
|
| 154 |
exit 2
|
| 155 |
}
|
| 156 |
|
| 157 |
i=1
|
| 158 |
for branch; do
|
| 159 |
|
| 160 |
branch_rev=${merge_rev[$i]}
|
| 161 |
((i++))
|
| 162 |
|
| 163 |
case "$branch" in
|
| 164 |
refs/remotes/*/master)
|
| 165 |
branch_name=${branch#refs/remotes/}
|
| 166 |
branch_name=${branch_name%/master}
|
| 167 |
;;
|
| 168 |
refs/remotes/*)
|
| 169 |
branch_name=${branch#refs/remotes/}
|
| 170 |
branch_name=${branch_name//\//-}
|
| 171 |
;;
|
| 172 |
*/*)
|
| 173 |
branch_name=${branch_name//\//-}
|
| 174 |
;;
|
| 175 |
*)
|
| 176 |
branch_name=$branch
|
| 177 |
;;
|
| 178 |
esac
|
| 179 |
|
| 180 |
file=linux-${version}-${branch_name}.patch
|
| 181 |
git diff --no-renames --patch-with-stat \
|
| 182 |
-r "${base_rev}" -r "${branch_rev}" > $file || exit
|
| 183 |
if [ ! -s $file ]; then
|
| 184 |
rm -f $file
|
| 185 |
continue
|
| 186 |
fi
|
| 187 |
|
| 188 |
usepatch $file
|
| 189 |
log $branch_rev branch $branch
|
| 190 |
|
| 191 |
base_rev="$branch_rev"
|
| 192 |
done
|
| 193 |
name=`echo ${name:-${branch}} | sed s/-/_/g`
|
| 194 |
|
| 195 |
#upstream_branch=`date -u -d "$now" +${branch}.%Y%m%dT%H%M | sed s/-/_/g`
|
| 196 |
upstream_branch=$name
|
| 197 |
branch_rev=`git describe $base_rev | sed 's/-g[0-9a-f]*$//;s/^[^-]*//;s/-/./g'`
|
| 198 |
|
| 199 |
logdate=`date -d "$now" +'%a %b %d %Y'`
|
| 200 |
|
| 201 |
sed "/%define nopatches/c\\
|
| 202 |
%define nopatches ${nopatches}\\
|
| 203 |
%define upstream_branch ${name}\\
|
| 204 |
%define upstream_branch_tag ${branch_rev}
|
| 205 |
/^### BRANCH PATCH/a\\
|
| 206 |
`patch_headers`
|
| 207 |
###
|
| 208 |
/^### BRANCH APPLY/a\\
|
| 209 |
`patch_apply`
|
| 210 |
###
|
| 211 |
/^%changelog/a\\
|
| 212 |
* ${logdate} ${GIT_AUTHOR_NAME} <${GIT_AUTHOR_EMAIL}>\\
|
| 213 |
$loglines
|
| 214 |
|
| 215 |
"
|