Define FILE_NOTIFY_CHANGE_ANY to monitor all possbile changes
[Samba/vfs_proxy.git] / packaging4 / utils / make-srpm_svn
blob1f87cbd3dd7474f0f9b7311a284f48a56b43e7f1
1 #! /bin/bash
2 # make-srpm: srpm builder, helps build srpm out of rcs sources
3 # svn helper; export correct git release and patches ready to
4 # build src.rpm
6 # Copyright (C) 2008 Sam Liddicott <sam@liddicott.com>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 svn_toplevel() {
23 test -d .svn -a ! -d ../.svn
26 svn_export() {
27 mkdir -p "`dirname "$1"`"
28 svn export -q ${ORIGIN:+-r $ORIGIN} . "$1"
31 svn_archive() {
32 rm -fr "$SRC_EXPORT/$1" &&
33 svn_export "$SRC_EXPORT/$1" &&
34 ( cd "$SRC_EXPORT" && tar -cvf - "$1"; rm -fr "$1" ) > "$2"
37 prepare_svn_src() {
38 PATCH_LEVEL=0
39 # for svn HEAD means local head, or whichever is smaller of HEAD and local version
40 THIS_REV="`sed '/Revision: /!d;s/^[^:]*: *//' <( svn info )`"
41 HEAD_REV="`sed '/Revision: /!d;s/^[^:]*: *//' <( svn info -r HEAD )`"
42 # reference to the svn we want to export as pristine source
43 # and changes in current checkout will be exported as a patch
45 # base it on the latest tagged release if we can find it
46 test -z "$ORIGIN" && ORIGIN="$THIS_REV"
48 # if ORIGIN is like origin/blah then we can't use it as a filename part
49 ORIGIN_NAME="$Name-`echo "$ORIGIN" | sed -e "s/\//-/g"`"
50 ORIGIN_REV="`sed '/Revision: /!d;s/^[^:]*: *//' <( svn info -r $ORIGIN )`"
52 test $ORIGIN_REV -gt $THIS_REV && die "Head is later then checkout!"
54 : ${RELEASE:=${ORIGIN}}
55 RELEASE_REV="`sed '/Revision: /!d;s/^[^:]*: *//' <( svn info ${RELEASE:+ -r $RELEASE} )`"
56 RELEASE_NAME="$Name-`echo "$RELEASE_REV" | sed -e "s/\//-/g"`"
58 if test -z "$Version"
59 then Version="$RELEASE_REV";
60 else SPEC_RELEASE="$RELEASE_REV";
62 SPEC_VERSION="$Version"
63 VERSION="$Version"
65 # make a tar in SRC_EXPORT, where the patches will also go
66 # (should use git version from origin)
67 SVN_INFO="$RPM_GIT_INFO" \
68 TAR_PREFIX="$ORIGIN_NAME"
69 TAR_NAME="$TAR_PREFIX.tar.gz"
70 NAME="$ORIGIN_NAME"
71 DIRNAME="$NAME"
72 svn_archive "$ORIGIN_NAME" "$TMPDIR/$TAR_NAME"
74 REBASE=""
76 ( cd "$SRC_EXPORT" || die "Can't prepare srpm files in $SRC_EXPORT"
78 # make patches
79 > patches.list
81 # $REBASE must be the point at which the last rebase occurred, but it seems
82 # that something like origin/v4-0-test is good enough for a rebase tree
83 # that no-one is merging from because something won't be in the rebase tree
84 # as a rebase AND in origin
85 if test -n "$REBASE" # pure git-rebase'd linear git tree where this will work
86 then
87 # fix patch name, this doesn't bring to VERSION but whatever
88 # version $REBASE is
89 git-diff "$GIT_ORIGIN".."$REBASE" > "$VERSION.patch"
90 test -s "$VERSION.patch" && echo "Patch: $VERSION.patch" >> patches.list
92 git-format-patch -B -n --ignore-if-in-upstream \
93 --suffix=".$Name-$VERSION.patch" "$REBASE".. |\
94 sed -e "s/^.*\///" -e "s/^\(0*\)\([0-9]*\)/Patch\2: \1\2/">> patches.list
96 # we should check which of those patches is already applied but
97 # missed by --ignore-if-in-upstream.
98 # we can do this by seeing which don't apply but apply cleanly
99 # as reverse patches
100 else
101 if test "$ORIGIN_NAME" != "$RELEASE_NAME"
102 then
103 # one big git-diff
104 PATCH_NAME="$ORIGIN_NAME-$RELEASE_NAME.patch"
105 svn diff "$ORIGIN":"$RELEASE_REV" > "$PATCH_NAME"
106 test -s "$PATCH_NAME" && echo "Patch1: $PATCH_NAME" >> patches.list
110 # also uncomitted patches?
111 if test "$RELEASE" = "HEAD"
112 then
113 # also local uncomitted patches
114 set `wc -l patches.list`
115 PATCH_NO="$1"
117 # any local files in the current change set
118 # svn diff -r BASE:BASE > "local-cached.patch"
119 # if test -s local-cached.patch
120 # then PATCH_NO="`expr "${PATCH_NO:-0}" \+ 1`"
121 # echo "Patch$PATCH_NO: local-cached.patch" >> patches.list
122 # else rm local-cached.patch
123 # fi
125 # any local files NOT in the current change set
127 (cd "$TOPDIR" && svn diff) > "local.patch"
128 if test -s local.patch
129 then PATCH_NO="`expr "${PATCH_NO:-0}" \+ 1`"
130 echo "Patch$PATCH_NO: local.patch" >> patches.list
131 else rm local.patch
134 # fixup patches into the spec file
135 sed -e "s/^Patch\([0-9]*\):.*/%patch\1 -p$PATCH_LEVEL/" < patches.list > patches.apply
138 TAR_NAME="`basename "$TAR_NAME"`" make_spec