From 3d5e3bffaf5a0acbee085c1f3d3f93f882ffd469 Mon Sep 17 00:00:00 2001 From: Sam Liddicott Date: Tue, 4 Nov 2008 08:53:46 +0000 Subject: [PATCH] SRPM builder helpers make-srpm helps build an from a source control system repository. It can exported a certain tagged version as the source and produce some patches which can be applied to make the desired version. It modifies a supplied spec file to account for this, and then builds an srpm --- packaging4/utils/make-srpm | 235 +++++++++++++++++++++++++++++++++++ packaging4/utils/make-srpm_git | 274 +++++++++++++++++++++++++++++++++++++++++ packaging4/utils/make-srpm_svn | 139 +++++++++++++++++++++ 3 files changed, 648 insertions(+) create mode 100644 packaging4/utils/make-srpm create mode 100644 packaging4/utils/make-srpm_git create mode 100644 packaging4/utils/make-srpm_svn diff --git a/packaging4/utils/make-srpm b/packaging4/utils/make-srpm new file mode 100644 index 00000000000..3a37a2d4b6c --- /dev/null +++ b/packaging4/utils/make-srpm @@ -0,0 +1,235 @@ +#! /bin/bash +# make-srpm: srpm builder, helps build srpm out of rcs sources + +# Copyright (C) 2008 Sam Liddicott +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# make-srpm will export from git or subversion and produce a src.rpm +# +# It will try and pick a recent tagged release for the "pristine source" and +# then produce patches up to the selected release as part of the rpm. +# +# It requires a .spec or .spec.in specfile template, from which it can also +# read some configuration, but this can be overridden on the command line + +# arguments can be specified in the template spec file, or in the environment +# or as name=value pairs on the command line. (Once a non name=value argument +# is found, others are not looked for). + +# $1 should be a spec file template + +# arguments are: +# ORIGIN - an rcs reference to the revision that should be tar'd +# ORIGIN_PATTERN - a glob or regex used to look for rcs tags to guess ORIGIN +# RELEASE - an rcs reference to the revision you want to build. Patches +# are generated from ORIGIN to RELEASE. RELEASE can be: +# - HEAD whatever os checked out +# - LOCAL means whatever is checked out + local changes + +#include svn and git helpers + +PATH="$PATH:`dirname $0`" . make-srpm_git +PATH="$PATH:`dirname $0`" . make-srpm_svn + +die() { + echo "!! $@" >&2 + exit 1 +} + +report() { + echo "-- $@" >&2 +} + +# try to find a checked-out project src dir +find_topdir() { + # stop when we find the git folder or the top level svn folder + while : + do + echo "Checking for top level source directory in $PWD" >&2 + git_toplevel && break # found top level git + svn_toplevel && break # found top level svn + + if ! cd .. || test "$PWD" = "/" + then + report "Can't find top level repository directory, using $BASED" + cd "$BASED" + break + fi + done + echo "$PWD" +} + +# read a config item from a file and set environment variables. +# e.g. +# get_config Version +# sep="=" get_config PATH +# prefix="#mksrpm-" RELEASE +get_config() { + for g in "$@" + do + if test -z "${!g}" + then export $g="`sed "/^$prefix$g *${sep:-:} */!d;s/^[^${sep:-:}]*${sep:-:} *//;" "$SPEC_SRC"`" + fi + done +} + +# generate the $SPEC spec file from $SPEC.in +make_spec() { + _SPEC="$SRC_EXPORT/`basename "$SPECIN" .in`" + + cat "$SPEC_SRC" > "$_SPEC" || die "Can't copy $SPECIN to $_SPEC" + + report "Updating $_SPEC" + sed -i -e "1i%define makesrpm_tarname $TAR_NAME" \ + -e "1i%define makesrpm_tarprefix $TAR_PREFIX" \ + -e "s/^\(Version: *\).*/\1$SPEC_VERSION/" \ + -e "s/^\(Release: *\).*/\1${SPEC_RELEASE:-0}/" \ + -e "s/^\(Source: *\).*/\1$TAR_NAME/" \ + -e "/^Source: /r$SRC_EXPORT/patches.list" \ + -e "/^%setup/r$SRC_EXPORT/patches.apply" \ + "$_SPEC" + for define in "${defines[@]}" + do + if grep "^%define ${define%%=*} " 2>/dev/null "$_SPEC" + then sed -i -e "/^%define[ \t][ \t]*${define%%=*}[ \t]/c%define ${define%%=*} ${define#*=}" "$_SPEC" + else sed -i -e "1i%define ${define%%=*} ${define#*=}" "$_SPEC" + fi + done + # _defines are like defines except subject to variable interpolation so + # that inner values like TAR_NAME can be accessed + for define in "${_defines[@]}" + do + eval "define=$define" + if grep "^%define ${define%%=*} " 2>/dev/null "$_SPEC" + then sed -i -e "/^%define[ \t][ \t]*${define%%=*}[ \t]/c%define ${define%%=*} ${define#*=}" "$_SPEC" + else sed -i -e "1i%define ${define%%=*} ${define#*=}" "$_SPEC" + fi + done +} + +# export current checked out source to file "$2" with tar path prefix of $1 +source_export() { + mkdir -p "$1" + # we want to specify the top-level folder name so we use a ghastly + # cpio hard-link trick to avoid copying the whole tree before tar-ing it + find ${SOURCE_PATHS:-.} '(' -wholename "$SRC_EXPORT*" -o -wholename "./.git*" -o -name '*.o' \ + -o -name '*.a' -o -name '*.so' -o -name '.svn' \ + -o -name "$Name-*gz" -o -name "$Name-*src.rpm" \ + ')' -prune -o -print |\ + cpio -p -d -l "$1" >/dev/null +} +source_archive() { + source_export "$SRC_EXPORT/$1" && + ( cd "$SRC_EXPORT" && tar -czf - "1"; rm -fr "$1") > "$2" +} + +# export_archive exports some "clean" source tree to $TAR_NAME +archive_version() { + report "Writing $SOURCE_TYPE to $TAR_NAME" + case "$SOURCE_TYPE" in + git) git_archive "$DIRNAME" "$TAR_NAME" ;; + svn) svn_archive "$DIRNAME" "$TAR_NAME" ;; + source) source_archive "$DIRNAME" "$TAR_NAME" ;; + *) die "Can't export from unknown source type $SOURCE_TYPE";; + esac +} + +# export_src exports some "clean" source tree to $SRC_EXPORT +export_version() { + report "Exporting $SOURCE_TYPE to $1" + case "$SOURCE_TYPE" in + git) git_export "$1" ;; + svn) svn_export "$1" ;; + source) source_export "$1";; + *) die "Can't export from unknown source type $SOURCE_TYPE";; + esac +} + +make_srpm() { + rm -fr "$SRC_EXPORT" + mkdir -p "$SRC_EXPORT" + + # copy any local dependancies + cp `dirname "$SPEC_SRC"`/* "$SRC_EXPORT" + + # what number should our patches start at? + START_PATCH_NO=$(( 1 + 0`sed -n 's/^\(%\|\)\(patch\)//i;T;s/[: ].*//;T;p' "$SPEC_SRC" | sort -nr | head -1` )) + + # get patches ready according to rebase, origin etc + case "$SOURCE_TYPE" in + git) prepare_git_src;; + svn) prepare_svn_src;; + *);; + esac + + # make spec file and calculate START_PATCH_NO + TAR_NAME="`basename "$TAR_NAME"`" make_spec + + rpmbuild --define "_sourcedir $SRC_EXPORT" --define "_srcrpmdir ." -bs "$SRC_EXPORT/`basename "$SPEC"`" >&2 || "Failed to build src.rpm" +} + +# set environment from args of style var=value +while test -n "$*" +do + case "$1" in + define_*=*) defines[${#defines[@]}]="${1#define_}"; shift;; + _define_*=*) _defines[${#_defines[@]}]="${1#_define_}"; shift;; + *=*) export "${1%%=*}"="${1#*=}"; shift;; + *) break;; + esac +done + +VERSION=${VERSION%%-*} + +# get to the top level project folder +BASED="$PWD" +test -n "$TOPDIR" || TOPDIR="`find_topdir`" +cd "$TOPDIR" || die "Can't cd to $TOPDIR from $BASED" + +if [ "$SOURCE_TYPE" = "" ] +then + pwd + SOURCE_TYPE="source" + test -d .svn && SOURCE_TYPE="svn" + test -d .git && SOURCE_TYPE="git" +fi + +echo "Source type: $SOURCE_TYPE" + +SRC_EXPORT="./dist_export" +TMPDIR="$SRC_EXPORT" +rm -fr "$TMPDIR" +mkdir -p "$TMPDIR" + +for spec in "$@" +do ( + # find a spec file if one is not specified + case "$spec" in + *.spec.in) test -z "$SPECIN" && SPECIN="$spec";; + *.spec) test -z "$SPEC" && SPEC="$spec";; + esac + + test -z "$SPECIN" -a -n "$SPEC" && SPECIN="$SPEC.in" + test -z "$SPECIN" && SPECIN="`set -- *spec.in && echo $spec`" + test -z "$SPEC" && SPEC="`dirname "$SPECIN"`/`basename "$SPECIN" .in`" + test -r "$SPECIN" -o -r "$SPEC" || die "Can't find spec file to work with" + # find the project parameters + test -r "$SPECIN" && SPEC_SRC="$SPECIN" || SPEC_SRC="$SPEC" + + CASE="i" get_config Name Version + prefix="#makesrpm-" get_config SOURCE_PATHS ORIGIN ORIGIN_PATTERN RELEASE + + make_srpm +) ; done diff --git a/packaging4/utils/make-srpm_git b/packaging4/utils/make-srpm_git new file mode 100644 index 00000000000..89c76b5077d --- /dev/null +++ b/packaging4/utils/make-srpm_git @@ -0,0 +1,274 @@ +#! /bin/bash +# make-srpm: srpm builder, helps build srpm out of rcs sources +# git helper; export correct git release and patches ready to +# build src.rpm + +# Copyright (C) 2008 Sam Liddicott +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +git_toplevel() { + test -d .git +} + +# git checkout $ORIGIN (or HEAD) as a tarfile $2 with path prefix $1 +# but only checkout $SOURCE_PATHS if specified +git_archive() { + # by HEAD here we mean to select current checkout of current branch + git archive --format=tar --prefix="$1/" "${ORIGIN:-HEAD}" ${SOURCE_PATHS} |\ + gzip > "$2" +} + +# git checkout $ORIGIN (or HEAD) as directory $1 +# but only checkout $SOURCE_PATHS if specified +git_export() { +exit 9 + mkdir -p "$1" && \ + git archive --format=tar "${ORIGIN:-HEAD}" ${SOURCE_PATHS} |\ + ( if cd "$1" + then tar -xf - + fi ) +} + +git_linearize() { +awk -f /dev/stdin "$@" <<'#AWK' +#! /usr/bin/awk -f + +# find-longest-path PARENT CHILD +# outputs the set of commits, choosing branches that result in the most number +# of commits (longest path) between PARENT and CHILD in that order +# Uses git rev-parse and git rev-list + +# recursively find longest path from $child to $parent +# return answer in $path. +# There are no branches that dont lead to parent because of input filtering +function paths(rev, branches, branch, best_path, best_path_len, path, n) { + if (rev == _parent) return _parent; + + if (rev in seen) return seen[rev]; + + split(nodes[rev], branches); + for(n=1; (n) in branches; n++) { + branch=branches[n]; + path=paths(branch); + if (length(path) > best_path_len) { + best_path_len=length(path); + best_path=path; + } + } + + # remember best answer for next time if we try this branch again as we + # may if branches re-merge + if (best_path_len) { + seen[rev]=best_path "\n" rev; + } else { + seen[rev]=""; + } + return seen[rev]; +} + + +BEGIN { + ("git rev-parse " ARGV[1] "^{commit}") | getline _parent; + ARGV[1]=""; + + ("git rev-parse " ARGV[2] "^{commit}") | getline _child; + ARGV[2]=""; + + # initialize parent to exist so we dont filter it out + nodes[_parent]=""; + + # read in a --topo-order --reverse tree but filter out anything whose + # parent is not already in (nodes) which will be primed by our top parent + while(("git rev-list --topo-order --reverse --parents ^" _parent " " _child) | getline) { + for(i=2; i<=NF; i++) { + if ($i in nodes) { + nodes[$1]=nodes[$1] " " $i; + } + } + } + printf("%s",paths(_child)); + exit; +} +#AWK + +} + +# thanks to thiago and pasky (#git 19th August 2008) for this: +# output tags that are parent-ish to $1 (or HEAD). +# restrict to tags matching glob ORIGINAL_PATTERN if specified +git_parent_tags() { + # sed presumes that multiple tags are like (tag: ...) (tag: ...) +# git log --decorate --reverse --pretty=oneline "${1:-$RELEASE}" |\ +# sed -ne 'There;:here;s/^(tag: refs\/tags\///;Tlook;{s/)/\n/;P;D};:look;s/\((tag: refs\/tags\/\)/\n\1/;D;' + + # more reliable but slower + git tag -l ${ORIGIN_PATTERN:+"$ORIGIN_PATTERN"} | sort | while read tag + do + test "$(git merge-base "$tag" "${1:-HEAD}")" = "$(git rev-parse "$tag^{commit}")" && echo $tag; + done +} + +# do a diff between two git revisions, also output the log of the commits included +# output to stdout, return true unless the patch was empty +# probably invoke as: +# git_rev_diff old_tag..new_tag -- file/path other/file/path +git_diff_rev() { + git log --pretty=fuller "$@" + echo + echo "Combined summary" + echo + # pgas on irc #bash isn't sure how he helped, but grep is great at passing + # text verbatim while showing in the exit code if the text was empty! + git diff -p --stat --summary "$@" | grep '^' +} + +# like git format-patch except iterates a revision path between $1 and $2 and +# outputs diff's between all trees. Takes extra -- file/path arguments too, +# or in fact any argument accepted by git diff AND git log, but must appear +# after $1 and $2 +git_format_diff() { + OPTIND=1 + local OUTDIR="." + local SUFFIX=".patch" + while getopts "o:s:" OPT + do + case "$OPT" in + o) OUTDIR="$OPTARG";; + s) SUFFIX="$OPTARG";; + esac + done + shift $(($OPTIND - 1)) + + local sha + local PATCH_NO + local REV="`git rev-parse "$1^{commit}"`" + local END="`git rev-parse "$2^{commit}"`" + shift 2 + + PATCH_NO=${START_PATCH_NO:-0} + while read sha + do + printf -v _PATCH_NO "%04d" $PATCH_NO + if git_diff_rev "$REV".."$sha" "$@" > "$OUTDIR/$_PATCH_NO-$sha.$SUFFIX" + then + echo "$OUTDIR/$_PATCH_NO-$sha.$SUFFIX" + PATCH_NO=$(( PATCH_NO + 1 )) + else rm -f "$OUTDIR/$_PATCH_NO-$sha.$SUFFIX" + fi + REV="$sha" + done < <( git_linearize "$REV" "$END" ) +} + +# output: +# 1. a source tar, +# 2. and some patches, +# 3. and patches.list and patches.apply +# based on: +# ORIGIN which we will try and guess at using +# ORIGIN_PATTERN if we don't know ORIGIN and can't guess from RELEASE +# RELEASE which will default to THIS+ + +prepare_git_src() { + PATCH_LEVEL=1 + NAME="${1:-$Name}" + VERSION="${2:-${VERSION:-$Version}}" + : ${TMPDIR:=$SRC_EXPORT} + + case "$RELEASE" in + THIS|LOCAL|"") _RELEASE=HEAD; LOCAL=1;; + ?*) _RELEASE="$RELEASE"; LOCAL="";; + esac + RELEASE_COMMIT="$(git rev-parse "$_RELEASE^{commit}")" + + # remember this and provide it during rpm config and build time + VERSION_INFO="`git show --pretty=format:"%h %ct %H %cd" $_RELEASE 2>/dev/null | head -1`" + + : ${ORIGIN:="`git_parent_tags "$_RELEASE" | sort | tail -n 1`"} + ORIGIN_COMMIT="`git rev-parse $ORIGIN^{commit}`" + test -z "$ORIGIN" -o "$(git merge-base "$ORIGIN_COMMIT" "$RELEASE_COMMIT")" != "$ORIGIN_COMMIT" && \ + die "Can't find origin $ORIGIN to use as pristine source for $_RELEASE" + + # try and find a tag for $_RELEASE. If RELEASE is not tagged, then append + # the git hash to the name of the previous tag + if test "$(git rev-parse "$RELEASE_COMMIT")" != "$(git rev-parse "$ORIGIN_COMMIT")" + then + RELEASE_SUFFIX="GIT_`git show --pretty=format:"%h" "$_RELEASE" | head -n 1`" + fi + + # append date if we are including uncomitted files + if test -n "$LOCAL" + then + RELEASE_SUFFIX="`date +%Y%m%d`_${RELEASE_SUFFIX:+${RELEASE_SUFFIX}_}local" + fi + + # remove a "release-" prefix from the name + RELEASE_NAME="$NAME-${ORIGIN/#release-}${RELEASE_SUFFIX:+_$RELEASE_SUFFIX}" + + # if GIT_ORIGIN is like origin/blah then we can't use it as a filename part + ORIGIN_NAME="$NAME-${ORIGIN//\//-}" + + TAR_PREFIX="$ORIGIN_NAME" + TAR_NAME="$TAR_PREFIX.tar.gz" + + SPEC_VERSION="$VERSION" + git_archive "$ORIGIN_NAME" "$TMPDIR/$TAR_NAME" + + # generate patches, also restrict patches to $SOURCE_PATHS + test -d "$TMPDIR" || die "Can't prepare srpm files in $TMPDIR" + + # make patches + > "$TMPDIR/patches.list" + +# if [ "$ORIGIN_COMMIT" != "$RELEASE_COMMIT" ] +# then + git_format_diff -o "$TMPDIR" -s "$Name-$VERSION.patch" \ + $ORIGIN $_RELEASE ${SOURCE_PATHS:+-- $SOURCE_PATHS} |\ + sed -e "s/^.*\///" -e "s/^\(0*\)\([0-9]*\)/Patch\2: \1\2/">> "$TMPDIR/patches.list" +# fi + + # also uncomitted changes? + if test -n "$LOCAL" + then + # also local uncomitted patches + set `wc -l "$TMPDIR/patches.list"` + PATCH_NO="$(( $1 + ${START_PATCH_NO:-0} ))" + + # any local files in the current change set + PATCH_NAME="git-local-cached.patch" + git diff --cached ${SOURCE_PATHS:+-- $SOURCE_PATHS} > "$TMPDIR/$PATCH_NAME" + if test -s "$TMPDIR/$PATCH_NAME" + then + PATCH_NO="`expr "${PATCH_NO:-0}" \+ 1`" + echo "Patch$PATCH_NO: $PATCH_NAME" >> "$TMPDIR/patches.list" + else + rm "$TMPDIR/$PATCH_NAME" + fi + + # any local files NOT in the current change set + PATCH_NAME="git-local.patch" + git diff ${SOURCE_PATHS:+-- $SOURCE_PATHS} > "$TMPDIR/$PATCH_NAME" + if test -s "$TMPDIR/$PATCH_NAME" + then + PATCH_NO="`expr "${PATCH_NO:-0}" \+ 1`" + echo "Patch$PATCH_NO: $PATCH_NAME" >> "$TMPDIR/patches.list" + else + rm "$TMPDIR/$PATCH_NAME" + fi + fi + + # generate patches.apply + sed -e "s/^Patch\([0-9]*\):.*/%patch\1 -p$PATCH_LEVEL/" < "$TMPDIR/patches.list" > "$TMPDIR/patches.apply" + + SPEC_RELEASE="$RELEASE_SUFFIX" +} diff --git a/packaging4/utils/make-srpm_svn b/packaging4/utils/make-srpm_svn new file mode 100644 index 00000000000..1f87cbd3dd7 --- /dev/null +++ b/packaging4/utils/make-srpm_svn @@ -0,0 +1,139 @@ +#! /bin/bash +# make-srpm: srpm builder, helps build srpm out of rcs sources +# svn helper; export correct git release and patches ready to +# build src.rpm + +# Copyright (C) 2008 Sam Liddicott +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +svn_toplevel() { + test -d .svn -a ! -d ../.svn +} + +svn_export() { + mkdir -p "`dirname "$1"`" + svn export -q ${ORIGIN:+-r $ORIGIN} . "$1" +} + +svn_archive() { + rm -fr "$SRC_EXPORT/$1" && + svn_export "$SRC_EXPORT/$1" && + ( cd "$SRC_EXPORT" && tar -cvf - "$1"; rm -fr "$1" ) > "$2" +} + +prepare_svn_src() { + PATCH_LEVEL=0 + # for svn HEAD means local head, or whichever is smaller of HEAD and local version + THIS_REV="`sed '/Revision: /!d;s/^[^:]*: *//' <( svn info )`" + HEAD_REV="`sed '/Revision: /!d;s/^[^:]*: *//' <( svn info -r HEAD )`" + # reference to the svn we want to export as pristine source + # and changes in current checkout will be exported as a patch + + # base it on the latest tagged release if we can find it + test -z "$ORIGIN" && ORIGIN="$THIS_REV" + + # if ORIGIN is like origin/blah then we can't use it as a filename part + ORIGIN_NAME="$Name-`echo "$ORIGIN" | sed -e "s/\//-/g"`" + ORIGIN_REV="`sed '/Revision: /!d;s/^[^:]*: *//' <( svn info -r $ORIGIN )`" + + test $ORIGIN_REV -gt $THIS_REV && die "Head is later then checkout!" + + : ${RELEASE:=${ORIGIN}} + RELEASE_REV="`sed '/Revision: /!d;s/^[^:]*: *//' <( svn info ${RELEASE:+ -r $RELEASE} )`" + RELEASE_NAME="$Name-`echo "$RELEASE_REV" | sed -e "s/\//-/g"`" + + if test -z "$Version" + then Version="$RELEASE_REV"; + else SPEC_RELEASE="$RELEASE_REV"; + fi + SPEC_VERSION="$Version" + VERSION="$Version" + + # make a tar in SRC_EXPORT, where the patches will also go + # (should use git version from origin) + SVN_INFO="$RPM_GIT_INFO" \ + TAR_PREFIX="$ORIGIN_NAME" + TAR_NAME="$TAR_PREFIX.tar.gz" + NAME="$ORIGIN_NAME" + DIRNAME="$NAME" + svn_archive "$ORIGIN_NAME" "$TMPDIR/$TAR_NAME" + + REBASE="" + + ( cd "$SRC_EXPORT" || die "Can't prepare srpm files in $SRC_EXPORT" + + # make patches + > patches.list + + # $REBASE must be the point at which the last rebase occurred, but it seems + # that something like origin/v4-0-test is good enough for a rebase tree + # that no-one is merging from because something won't be in the rebase tree + # as a rebase AND in origin + if test -n "$REBASE" # pure git-rebase'd linear git tree where this will work + then + # fix patch name, this doesn't bring to VERSION but whatever + # version $REBASE is + git-diff "$GIT_ORIGIN".."$REBASE" > "$VERSION.patch" + test -s "$VERSION.patch" && echo "Patch: $VERSION.patch" >> patches.list + + git-format-patch -B -n --ignore-if-in-upstream \ + --suffix=".$Name-$VERSION.patch" "$REBASE".. |\ + sed -e "s/^.*\///" -e "s/^\(0*\)\([0-9]*\)/Patch\2: \1\2/">> patches.list + + # we should check which of those patches is already applied but + # missed by --ignore-if-in-upstream. + # we can do this by seeing which don't apply but apply cleanly + # as reverse patches + else + if test "$ORIGIN_NAME" != "$RELEASE_NAME" + then + # one big git-diff + PATCH_NAME="$ORIGIN_NAME-$RELEASE_NAME.patch" + svn diff "$ORIGIN":"$RELEASE_REV" > "$PATCH_NAME" + test -s "$PATCH_NAME" && echo "Patch1: $PATCH_NAME" >> patches.list + fi + fi + + # also uncomitted patches? + if test "$RELEASE" = "HEAD" + then + # also local uncomitted patches + set `wc -l patches.list` + PATCH_NO="$1" + + # any local files in the current change set +# svn diff -r BASE:BASE > "local-cached.patch" +# if test -s local-cached.patch +# then PATCH_NO="`expr "${PATCH_NO:-0}" \+ 1`" +# echo "Patch$PATCH_NO: local-cached.patch" >> patches.list +# else rm local-cached.patch +# fi + + # any local files NOT in the current change set + pwd + (cd "$TOPDIR" && svn diff) > "local.patch" + if test -s local.patch + then PATCH_NO="`expr "${PATCH_NO:-0}" \+ 1`" + echo "Patch$PATCH_NO: local.patch" >> patches.list + else rm local.patch + fi + fi + # fixup patches into the spec file + sed -e "s/^Patch\([0-9]*\):.*/%patch\1 -p$PATCH_LEVEL/" < patches.list > patches.apply + ) + + TAR_NAME="`basename "$TAR_NAME"`" make_spec +} -- 2.11.4.GIT