Accepting request 105386 from home:aspiers:branches:openSUSE:Tools

- add new 'versionformat' option to determine how version is
  extracted via git show --pretty=... (and similar for svn /
  hg / bzr)
- support caching of cloned repositories to speed up fetch
  from upstream
- use mktemp -u because git/hg refuse to clone into an empty 
  directory on SLES11

OBS-URL: https://build.opensuse.org/request/show/105386
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-tar_scm?expand=0&rev=33
This commit is contained in:
Adrian Schröter 2012-02-16 11:06:33 +00:00 committed by Git OBS Bridge
parent e7fbd5920f
commit 6e55d7df19
12 changed files with 539 additions and 266 deletions

View File

@ -13,3 +13,17 @@ class BzrTests(CommonTests):
def default_version(self):
return self.rev(2)
def test_versionformat_rev(self):
self.tar_scm_std('--versionformat', 'myrev%r.svn')
self.assertTarOnly(self.basename(version = 'myrev2.svn'))
def test_version_versionformat(self):
self.tar_scm_std('--version', '3.0', '--versionformat', 'myrev%r.svn')
self.assertTarOnly(self.basename(version = 'myrev2.svn'))
def test_versionformat_revision(self):
self.fixtures.create_commits(4)
self.tar_scm_std('--versionformat', 'foo%r', '--revision', self.rev(2))
basename = self.basename(version = 'foo2')
th = self.assertTarOnly(basename)
self.assertTarMemberContains(th, basename + '/a', '2')

View File

@ -57,14 +57,14 @@ class CommonTests(TestEnvironment, TestAssertions):
self.assertTarMemberContains(th, self.basename() + '/a', '2')
def test_revision(self):
self.fixtures.create_commits(2)
self.tar_scm_std('--revision', self.rev(2))
th = self.assertTarOnly(self.basename())
self.assertTarMemberContains(th, self.basename() + '/a', '2')
self._revision()
def test_revision_no_cache(self):
self._revision(use_cache=False)
def test_revision_subdir(self):
self._revision(use_subdir=True)
def test_revision_subdir_no_cache(self):
self._revision(use_cache=False, use_subdir=True)
@ -89,9 +89,15 @@ class CommonTests(TestEnvironment, TestAssertions):
use_cache
)
def test_revision_master_alternating(self):
self._revision_master_alternating()
def test_revision_master_alternating_no_cache(self):
self._revision_master_alternating(use_cache=False)
def test_revision_master_alternating_subdir(self):
self._revision_master_alternating(use_subdir=True)
def test_revision_master_alternating_subdir_no_cache(self):
self._revision_master_alternating(use_cache=False, use_subdir=True)
@ -150,6 +156,9 @@ class CommonTests(TestEnvironment, TestAssertions):
self.scmlogs.next()
self.postRun()
def test_switch_revision_and_subdir(self):
self._switch_revision_and_subdir()
def test_switch_revision_and_subdir_no_cache(self):
self._switch_revision_and_subdir(use_cache=False)

38
githgtests.py Normal file
View File

@ -0,0 +1,38 @@
#!/usr/bin/python
import os
from commontests import CommonTests
from utils import run_hg
class GitHgTests(CommonTests):
mixed_version_template = '%s.master.%s'
def test_versionformat_abbrevhash(self):
self.tar_scm_std('--versionformat', self.abbrev_hash_format)
self.assertTarOnly(self.basename(version = self.sha1s(self.rev(2))))
def test_versionformat_timestamp(self):
self.tar_scm_std('--versionformat', self.timestamp_format)
self.assertTarOnly(self.basename(version = self.timestamps(self.rev(2))))
def _mixed_version_format(self):
return self.mixed_version_template % (self.timestamp_format, self.abbrev_hash_format)
def _mixed_version(self):
return self.mixed_version_template % (self.timestamps(self.rev(2)), self.sha1s(self.rev(2)))
def test_versionformat_mixed(self):
self.tar_scm_std('--versionformat', self._mixed_version_format())
self.assertTarOnly(self.basename(version = self._mixed_version()))
def test_version_versionformat(self):
self.tar_scm_std('--version', '3.0', '--versionformat', self._mixed_version_format())
self.assertTarOnly(self.basename(version = self._mixed_version()))
def test_versionformat_revision(self):
self.fixtures.create_commits(4)
self.tar_scm_std('--versionformat', self.abbrev_hash_format, '--revision', self.rev(2))
basename = self.basename(version = self.sha1s(self.rev(2)))
th = self.assertTarOnly(basename)
self.assertTarMemberContains(th, basename + '/a', '2')

View File

@ -1,15 +1,17 @@
#!/usr/bin/python
from commontests import CommonTests
from githgtests import GitHgTests
from gitfixtures import GitFixtures
from utils import run_git
class GitTests(CommonTests):
class GitTests(GitHgTests):
scm = 'git'
initial_clone_command = 'git clone'
update_cache_command = 'git fetch'
fixtures_class = GitFixtures
abbrev_hash_format = '%h'
timestamp_format = '%at'
def default_version(self):
return self.timestamps(self.rev(2))

View File

@ -1,14 +1,17 @@
#!/usr/bin/python
from commontests import CommonTests
from hgfixtures import HgFixtures
from githgtests import GitHgTests
from hgfixtures import HgFixtures
from utils import run_hg
class HgTests(CommonTests):
class HgTests(GitHgTests):
scm = 'hg'
initial_clone_command = 'hg clone'
update_cache_command = 'hg pull'
fixtures_class = HgFixtures
abbrev_hash_format = '{node|short}'
timestamp_format = '{date}'
def default_version(self):
return self.rev(2)

View File

@ -1,3 +1,11 @@
-------------------------------------------------------------------
Tue Feb 14 16:52:19 GMT 2012 - aspiers@suse.com
- add new 'versionformat' option to determine how version is
extracted via git show --pretty=...
- support caching of cloned repositories to speed up fetch
from upstream
-------------------------------------------------------------------
Mon Feb 13 15:52:19 GMT 2012 - aspiers@suse.com

View File

@ -23,10 +23,11 @@ Summary: An OBS source service: checkout or update a tar ball from svn/gi
License: GPL-2.0+
Group: Development/Tools/Building
Url: https://build.opensuse.org/package/show?package=obs-service-%{service}&project=openSUSE%3ATools
Version: 0.2.2
Version: 0.2.3
Release: 0
Source: %{service}
Source1: %{service}.service
Source2: %{service}.rc
Requires: bzr git mercurial subversion
BuildRequires: bzr git mercurial subversion
BuildRequires: python >= 2.6
@ -49,6 +50,9 @@ mkdir -p $RPM_BUILD_ROOT/usr/lib/obs/service
install -m 0755 %{SOURCE0} $RPM_BUILD_ROOT/usr/lib/obs/service
install -m 0644 %{SOURCE1} $RPM_BUILD_ROOT/usr/lib/obs/service
mkdir -p $RPM_BUILD_ROOT/etc/obs/services
install -m 0644 %{SOURCE2} $RPM_BUILD_ROOT/etc/obs/services/%{service}
%check
chmod +x $RPM_SOURCE_DIR/scm-wrapper
: Running the test suite. Please be patient - this takes a few minutes ...
@ -58,5 +62,8 @@ python $RPM_SOURCE_DIR/test.py
%defattr(-,root,root)
%dir /usr/lib/obs
/usr/lib/obs/service
%dir /etc/obs
%dir /etc/obs/services
%config(noreplace) /etc/obs/services/*
%changelog

View File

@ -12,3 +12,18 @@ class SvnTests(CommonTests):
def default_version(self):
return self.rev(2)
def test_versionformat_rev(self):
self.tar_scm_std('--versionformat', 'myrev%r.svn')
self.assertTarOnly(self.basename(version = 'myrev2.svn'))
def test_version_versionformat(self):
self.tar_scm_std('--version', '3.0', '--versionformat', 'myrev%r.svn')
self.assertTarOnly(self.basename(version = 'myrev2.svn'))
def test_versionformat_revision(self):
self.fixtures.create_commits(4)
self.tar_scm_std('--versionformat', 'foo%r', '--revision', self.rev(2))
basename = self.basename(version = 'foo2')
th = self.assertTarOnly(basename)
self.assertTarMemberContains(th, basename + '/a', '2')

664
tar_scm
View File

@ -10,103 +10,140 @@
# of the License, or (at your option) any later version.
# See http://www.gnu.org/licenses/gpl-2.0.html for full license text.
# defaults
MYSCM=""
MYURL=""
MYVERSION="_auto_"
MYPREFIX=""
MYFILENAME=""
MYREVISION=""
MYPACKAGEMETA=""
MYGITARGS="--depth 1"
INCLUDES=""
SERVICE='tar_scm'
while test $# -gt 0; do
case $1 in
*-scm)
MYSCM="$2"
shift
;;
*-url)
MYURL="$2"
shift
;;
*-subdir)
MYSUBDIR="$2"
shift
;;
*-revision)
MYREVISION="$2"
shift
;;
*-version)
MYVERSION="$2"
shift
;;
*-include)
INCLUDES="$INCLUDES $2"
shift
;;
*-versionprefix)
MYPREFIX="$2"
shift
;;
*-exclude)
EXCLUDES="$EXCLUDES --exclude=${2#/}"
shift
;;
*-filename)
MYFILENAME="${2#/}"
shift
;;
*-package-meta)
MYPACKAGEMETA="${2#/}"
shift
;;
*-outdir)
MYOUTDIR="$2"
shift
;;
*-history-depth)
if [ "$2" == "full" ]; then
MYGITARGS="--depth 999999999"
else
MYGITARGS="--depth $2"
fi
shift
;;
*)
echo Unknown parameter $1.
echo 'Usage: tar_scm --scm $SCM --url $URL --outdir $OUT'
exit 1
;;
esac
shift
done
set_default_params () {
MYSCM=""
MYURL=""
MYVERSION="_auto_"
MYFORMAT=""
MYPREFIX=""
MYFILENAME=""
MYREVISION=""
MYPACKAGEMETA=""
# MYHISTORYDEPTH=""
INCLUDES=""
}
FILE="$MYFILENAME"
VERSION="$MYVERSION"
if [ -z "$MYPACKAGEMETA" ]; then
EXCLUDES="$EXCLUDES --exclude=.$MYSCM"
fi
get_config_options () {
# config options for this host ?
if [ -f /etc/obs/services/$SERVICE ]; then
. /etc/obs/services/$SERVICE
fi
# config options for this user ?
if [ -f "$HOME"/.obs/$SERVICE ]; then
. "$HOME"/.obs/$SERVICE
fi
}
if [ -z "$MYSCM" ]; then
echo "ERROR: no scm is given via --scm parameter (git/svn/hg/bzr)!"
parse_params () {
while test $# -gt 0; do
case $1 in
*-scm)
MYSCM="$2"
shift
;;
*-url)
MYURL="$2"
shift
;;
*-subdir)
MYSUBDIR="$2"
shift
;;
*-revision)
MYREVISION="$2"
shift
;;
*-version)
MYVERSION="$2"
shift
;;
*-include)
INCLUDES="$INCLUDES $2"
shift
;;
*-versionformat)
MYFORMAT="$2"
shift
;;
*-versionprefix)
MYPREFIX="$2"
shift
;;
*-exclude)
EXCLUDES="$EXCLUDES --exclude=${2#/}"
shift
;;
*-filename)
MYFILENAME="${2#/}"
shift
;;
*-package-meta)
MYPACKAGEMETA="${2#/}"
shift
;;
*-outdir)
MYOUTDIR="$2"
shift
;;
*-history-depth)
echo "history-depth parameter is obsolete and will be ignored"
shift
;;
*)
echo "Unknown parameter: $1"
echo 'Usage: $SERVICE --scm $SCM --url $URL [--subdir $SUBDIR] [--revision $REVISION] [--version $VERSION] [--include $INCLUDE]* [--exclude $EXCLUDE]* [--versionformat $FORMAT] [--versionprefix $PREFIX] [--filename $FILENAME] [--package-meta $META] --outdir $OUT'
exit 1
;;
esac
shift
done
}
error () {
echo "ERROR: $*"
exit 1
fi
if [ -z "$MYURL" ]; then
echo "ERROR: no checkout URL is given via --url parameter!"
exit 1
fi
if [ -z "$MYOUTDIR" ]; then
echo "ERROR: no output directory is given via --outdir parameter!"
exit 1
fi
}
SRCDIR=$(pwd)
cd "$MYOUTDIR"
debug () {
[ -n "$DEBUG_TAR_SCM" ] && echo "$*"
}
safe_run () {
if ! "$@"; then
error "$* failed; aborting!"
fi
}
sanitise_params () {
TAR_VERSION="$MYVERSION"
if [ -z "$MYSCM" ]; then
error "no scm is given via --scm parameter (git/svn/hg/bzr)!"
fi
if [ -z "$MYURL" ]; then
error "no checkout URL is given via --url parameter!"
fi
if [ -z "$MYOUTDIR" ]; then
error "no output directory is given via --outdir parameter!"
fi
FILE="$MYFILENAME"
WD_VERSION="$MYVERSION"
if [ -z "$MYPACKAGEMETA" ]; then
EXCLUDES="$EXCLUDES --exclude=.$MYSCM"
fi
# if [ "$MYHISTORYDEPTH" == "full" ]; then
# MYHISTORYDEPTH="999999999"
# fi
}
detect_default_filename_param () {
if [ -n "$FILE" ]; then
return
fi
if [ -z "$FILE" ]; then
case "$MYSCM" in
git)
FILE="${MYURL%/}"
@ -118,187 +155,312 @@ if [ -z "$FILE" ]; then
FILE="${MYURL%/}"
FILE="${FILE##*/}"
;;
*)
error "unknown SCM '$MYSCM'"
esac
fi
}
# Try to find an existing tar ball, which can be upgraded instead of complete full download.
existing_tar=$(echo $SRCDIR/.old/_service:*tar_scm:${FILE}-*.tar*)
if [ ! -e "$existing_tar" ]; then
# for OBS < 2.3
existing_tar=$(echo $SRCDIR/_service:*tar_scm:${FILE}-*.tar*)
fi
if [ -e "$existing_tar" ]; then
UNCOMPRESS="cat"
if [ "${existing_tar%.tar.gz}" != "$existing_tar" ]; then
UNCOMPRESS="gunzip -c"
elif [ "${existing_tar%.tar.bz2}" != "$existing_tar" ]; then
UNCOMPRESS="bunzip2 -c"
elif [ "${existing_tar%.tar.xz}" != "$existing_tar" ]; then
UNCOMPRESS="xz -dc"
fetch_upstream () {
TOHASH="$MYURL"
[ "$MYSCM" = 'svn' ] && TOHASH="$TOHASH/$MYSUBDIR"
HASH=`echo "$TOHASH" | sha256sum | cut -d\ -f 1`
REPOCACHE=
if [ -n "$CACHEDIRECTORY" ]; then
REPOCACHEINCOMING="$CACHEDIRECTORY/incoming"
REPOCACHEROOT="$CACHEDIRECTORY/repo"
REPOCACHE="$REPOCACHEROOT/$HASH"
REPOURLCACHE="$CACHEDIRECTORY/repourl/$HASH"
fi
if $UNCOMPRESS "$existing_tar" | tar xf -; then
TAR_DIRECTORY=`find * -maxdepth 0 -a -type d`
else
existing_tar=""
fi
else
existing_tar=""
fi
if [ "$MYSCM" == "svn" ]; then
if [[ $(svn --version --quiet) > "1.5.99" ]]; then
TRUST_SERVER_CERT="--trust-server-cert";
fi
if [ -z "$MYSUBDIR" -a -d "$TAR_DIRECTORY/.svn" ]; then
# update existing content for speed/bandwidth reasons
cd "$TAR_DIRECTORY"
OLDVERSION=`LC_ALL=C svn info | sed -n 's,^Last Changed Rev: \(.*\),\1,p'` || exit 1
if [ -z "$MYREVISION" ]; then
case "$MYSCM" in
git)
MYREVISION=master
;;
hg)
MYREVISION=tip
;;
# bzr)
# MYREVISION=HEAD
# ;;
esac
if [ -n "$MYREVISION" ]; then
svn up -r"$MYREVISION" || exit 1
else
svn up || exit 1
debug "no revision specified; defaulting to $MYREVISION"
fi
NEWVERSION=`LC_ALL=C svn info | sed -n 's,^Last Changed Rev: \(.*\),\1,p'` || exit 1
cd -
mv "$TAR_DIRECTORY" "${FILE}" || exit 1
fi
debug "check local cache if configured"
if [ -n "$CACHEDIRECTORY" -a -d "$REPOCACHE/.$MYSCM" ]; then
debug "cache hit: $REPOCACHE/.$MYSCM"
check_cache
update_cache
REPOPATH="$REPOCACHE"
else
# new checkout
if [ -n "$MYSUBDIR" ]; then
# just checkout the subdir
mkdir -p "$FILE"
cd "$FILE"
if [ "$MYSUBDIR" != "${MYSUBDIR#/}" ]; then
echo "ERROR: Absolute paths not permitted for --subdir"
exit 1
if [ -n "$CACHEDIRECTORY" ]; then
debug "cache miss: $REPOCACHE/.$MYSCM"
else
debug "cache not enabled"
fi
calc_dir_to_clone_to
debug "new $MYSCM checkout to $CLONE_TO"
initial_clone
if [ -n "$CACHEDIRECTORY" ]; then
cache_repo
REPOPATH="$REPOCACHE"
else
REPOPATH="$MYOUTDIR/$FILE"
fi
fi
safe_run cd "$REPOPATH"
switch_to_revision
if [ "$TAR_VERSION" == "_auto_" -o -n "$MYFORMAT" ]; then
detect_version
fi
}
calc_dir_to_clone_to () {
if [ -n "$CACHEDIRECTORY" ]; then
safe_run cd "$REPOCACHEINCOMING"
# Use dry-run mode because git/hg refuse to clone into
# an empty directory on SLES11
debug mktemp -u -d "tmp.XXXXXXXXXX"
CLONE_TO=`mktemp -u -d "tmp.XXXXXXXXXX"`
else
CLONE_TO="$FILE"
fi
}
initial_clone () {
case "$MYSCM" in
git)
# Clone with full depth; so that the revision can be found if specified
safe_run git clone "$MYURL" "$CLONE_TO"
;;
svn)
args=
[ -n "$MYREVISION" ] && args="-r$MYREVISION"
if [[ $(svn --version --quiet) > "1.5.99" ]]; then
TRUST_SERVER_CERT="--trust-server-cert"
fi
fi
if [ -n "$MYREVISION" ]; then
svn co --non-interactive $TRUST_SERVER_CERT -r"$MYREVISION" "$MYURL/$MYSUBDIR" "${MYSUBDIR:-$FILE}" || exit 1
else
svn co --non-interactive $TRUST_SERVER_CERT "$MYURL/$MYSUBDIR" "${MYSUBDIR:-$FILE}" || exit 1
fi
if [ -n "$MYSUBDIR" ]; then
cd -
fi
fi
if [ "$VERSION" == "_auto_" ]; then
cd "$FILE/$MYSUBDIR"
[ -n "$MYPREFIX" ] && MYPREFIX="$MYPREFIX.rev"
VERSION="$MYPREFIX"`LC_ALL=C svn info | sed -n 's,^Last Changed Rev: \(.*\),\1,p'` || exit 1
cd -
fi
elif [ "$MYSCM" == "git" ]; then
if [ -z "$MYSUBDIR" -a -d "$TAR_DIRECTORY/.git" ]; then
# update existing content for speed/bandwidth reasons
cd "$TAR_DIRECTORY"
OLDVERSION=`git show --pretty=format:%at | head -n 1`
git pull $MYGITARGS || exit 1
if [ -n "$MYREVISION" ]; then
git checkout "$MYREVISION" || exit 1
fi
NEWVERSION=`git show --pretty=format:%at | head -n 1`
cd -
mv "$TAR_DIRECTORY" "${FILE}" || exit 1
safe_run svn checkout --non-interactive $TRUST_SERVER_CERT \
$args "$MYURL/$MYSUBDIR" "$CLONE_TO"
MYSUBDIR= # repo root is subdir
;;
hg)
safe_run hg clone "$MYURL" "$CLONE_TO"
;;
bzr)
args=
[ -n "$MYREVISION" ] && args="-r $MYREVISION"
safe_run bzr checkout $args "$MYURL" "$CLONE_TO"
;;
*)
error "unknown SCM '$MYSCM'"
esac
}
cache_repo () {
if [ -e "$REPOCACHE" ]; then
error "Somebody else beat us to populating the cache for $MYURL ($REPOCACHE)"
else
# new checkout
if [ -n "$MYREVISION" ]; then
#Clone with full depth; so that the revision can be found
git clone "$MYURL" "${FILE}" || exit 1
cd "$FILE"
git checkout "$MYREVISION" || exit 1
cd -
else
#Clone only the latest revision
git clone --depth 1 "$MYURL" "${FILE}" || exit 1
fi
# FIXME: small race window here; do source services need to be thread-safe?
debug mv2 "$CLONE_TO" "$REPOCACHE"
safe_run mv "$CLONE_TO" "$REPOCACHE"
echo "$MYURL" > "$REPOURLCACHE"
echo "cached $MYURL at $REPOCACHE"
fi
if [ "$VERSION" == "_auto_" ]; then
cd "$FILE"
[ -n "$MYPREFIX" ] && MYPREFIX="$MYPREFIX."
VERSION="$MYPREFIX"`git show --pretty=format:%at | head -n 1`
cd -
}
check_cache () {
CACHEDURL=`cat "$REPOURLCACHE"`
[ -z "$CACHEDURL" ] && CACHEDURL='<unknown URL>'
if [ "$MYURL" != "$CACHEDURL" ]; then
error "Corrupt cache: cache for repo $MYURL was recorded as being from $CACHEDURL"
fi
elif [ "$MYSCM" == "hg" ]; then
if [ -z "$MYSUBDIR" -a -d "$TAR_DIRECTORY/.hg" ]; then
# update existing content for speed/bandwidth reasons
cd "$TAR_DIRECTORY"
OLDVERSION=`hg id -i -rtip`
hg pull || exit 1
NEWVERSION=`hg id -i -rtip`
cd -
mv "$TAR_DIRECTORY" "${FILE}" || exit 1
}
update_cache () {
safe_run cd "$REPOCACHE"
case "$MYSCM" in
git)
safe_run git fetch
;;
svn)
args=
[ -n "$MYREVISION" ] && args="-r$MYREVISION"
safe_run svn update $args
MYSUBDIR= # repo root is subdir
;;
hg)
if ! out=`hg pull`; then
if [[ "$out" == *'no changes found'* ]]; then
# Contrary to the docs, hg pull returns exit code 1 when
# there are no changes to pull, but we don't want to treat
# this as an error.
:
else
error "hg pull failed; aborting!"
fi
fi
;;
bzr)
args=
[ -n "$MYREVISION" ] && args="-r$MYREVISION"
safe_run bzr update $args
;;
*)
error "unknown SCM '$MYSCM'"
esac
}
switch_to_revision () {
case "$MYSCM" in
git)
safe_run git checkout "$MYREVISION"
if git branch | grep -q '^\* (no branch)$'; then
echo "$MYREVISION does not refer to a branch, not attempting git pull"
else
git pull
fi
;;
svn|bzr)
: # should have already happened via checkout or update
;;
hg)
safe_run hg update "$MYREVISION"
;;
# bzr)
# safe_run bzr update
# if [ -n "$MYREVISION" ]; then
# safe_run bzr revert -r "$MYREVISION"
# fi
# ;;
*)
error "unknown SCM '$MYSCM'"
esac
}
detect_version () {
if [ -z "$MYFORMAT" ]; then
case "$MYSCM" in
git)
MYFORMAT="%at"
;;
hg)
MYFORMAT="{rev}"
;;
svn|bzr)
MYFORMAT="%r"
;;
*)
error "unknown SCM '$MYSCM'"
;;
esac
fi
safe_run cd "$REPOPATH"
[ -n "$MYPREFIX" ] && MYPREFIX="$MYPREFIX."
get_version
TAR_VERSION="$MYPREFIX$version"
}
get_version () {
case "$MYSCM" in
git)
#version=`safe_run git show --pretty=format:"$MYFORMAT" | head -n 1`
version=`safe_run git log -n1 --pretty=format:"$MYFORMAT"`
;;
svn)
#rev=`LC_ALL=C safe_run svn info | awk '/^Revision:/ { print $2 }'`
rev=`LC_ALL=C safe_run svn info | sed -n 's,^Last Changed Rev: \(.*\),\1,p'`
version="${MYFORMAT//%r/$rev}"
;;
hg)
rev=`safe_run hg id -n`
version=`safe_run hg log -l1 -r$rev --template "$MYFORMAT"`
;;
bzr)
#safe_run bzr log -l1 ...
rev=`safe_run bzr revno`
version="${MYFORMAT//%r/$rev}"
;;
*)
error "unknown SCM '$MYSCM'"
esac
}
prep_tree_for_tar () {
if [ ! -e "$REPOPATH/$MYSUBDIR" ]; then
error "directory does not exist: $REPOPATH/$MYSUBDIR"
fi
if [ -z "$TAR_VERSION" ]; then
TAR_BASENAME="$FILE"
else
# new checkout
hg clone "$MYURL" "${FILE}" || exit 1
TAR_BASENAME="${FILE}-${TAR_VERSION}"
fi
if [ -n "$MYREVISION" ]; then
cd "$FILE"
hg update "$MYREVISION" || exit 1
cd -
MYINCLUDES=""
for INC in $INCLUDES; do
MYINCLUDES="$MYINCLUDES $TAR_BASENAME/$INC"
done
if [ -z "$MYINCLUDES" ]; then
MYINCLUDES="$TAR_BASENAME"
fi
if [ "$VERSION" == "_auto_" ]; then
cd "$FILE"
[ -n "$MYPREFIX" ] && MYPREFIX="$MYPREFIX."
# current working revision
VERSION="$MYPREFIX"`hg id -n`
cd -
fi
elif [ "$MYSCM" == "bzr" ]; then
if [ -z "$MYSUBDIR" -a -d "$TAR_DIRECTORY/.bzr" ]; then
# update existing content for speed/bandwidth reasons
cd "$TAR_DIRECTORY"
OLDVERSION=`bzr revno`
bzr update || exit 1
if [ -n "$MYREVISION" ]; then
bzr revert -r "$MYREVISION" || exit 1
fi
NEWVERSION=`bzr revno`
cd -
mv "$TAR_DIRECTORY" "${FILE}" || exit 1
safe_run cd "$MYOUTDIR"
if [ -n "$CACHEDIRECTORY" ]; then
debug cp -a "$REPOPATH/$MYSUBDIR" "$TAR_BASENAME"
safe_run cp -a "$REPOPATH/$MYSUBDIR" "$TAR_BASENAME"
else
# new checkout
if [ -n "$MYREVISION" ]; then
bzr checkout -r "$MYREVISION" "$MYURL" "${FILE}" || exit 1
else
bzr checkout "$MYURL" "${FILE}" || exit 1
fi
debug mv3 "$REPOPATH/$MYSUBDIR" "$TAR_BASENAME"
safe_run mv "$REPOPATH/$MYSUBDIR" "$TAR_BASENAME"
fi
if [ "$VERSION" == "_auto_" ]; then
cd "$FILE"
[ -n "$MYPREFIX" ] && MYPREFIX="$MYPREFIX."
VERSION="$MYPREFIX"`bzr revno`
cd -
}
create_tar () {
TARFILE="${TAR_BASENAME}.tar"
TARPATH="$MYOUTDIR/$TARFILE"
debug tar cf "$TARPATH" $EXCLUDES $MYINCLUDES
safe_run tar cf "$TARPATH" $EXCLUDES $MYINCLUDES
echo "Created $TARFILE"
}
cleanup () {
debug rm -rf "$TAR_BASENAME" "$FILE"
rm -rf "$TAR_BASENAME" "$FILE"
}
main () {
set_default_params
if [ -z "$DEBUG_TAR_SCM" ]; then
get_config_options
else
# We're in test-mode, so don't let any local site-wide
# or per-user config impact the test suite.
:
fi
else
echo "ERROR: unknown scm $MYSCM"
exit 1
fi
parse_params "$@"
sanitise_params
if [ ! -e "$FILE/$MYSUBDIR" ]; then
echo "Directory does not exist: $FILE/$MYSUBDIR"
exit 1
fi
SRCDIR=$(pwd)
cd "$MYOUTDIR"
detect_default_filename_param
if [ -z "$VERSION" ]; then
FILENAME="$FILE"
else
FILENAME="${FILE}-${VERSION}"
fi
fetch_upstream
MYINCLUDES=""
prep_tree_for_tar
create_tar
for INC in $INCLUDES; do
MYINCLUDES="$MYINCLUDES $FILENAME/$INC"
done
if [ -z "$MYINCLUDES" ]; then
MYINCLUDES="$FILENAME"
fi
cleanup
}
if [ "$FILE" != "$FILENAME" ]; then
mv "$FILE/$MYSUBDIR" "${FILENAME}" || exit 1
fi
tar cf "$MYOUTDIR/${FILENAME}.tar" $EXCLUDES $MYINCLUDES || exit 1
rm -rf "${FILENAME}" "$FILE"
main "$@"
exit 0

11
tar_scm.rc Normal file
View File

@ -0,0 +1,11 @@
#
# Define a cache directory here to avoid repeating downloads of the
# same file. This works on the server and on the client side.
#
# Note that this file can be overridden with per-user config placed
# in ~/.obs/tar_scm
#
# WARNING: you need to create three directories inside, when changing from default:
# mkdir -p repo{,url} incoming
#
#CACHEDIRECTORY="/var/cache/obs/tar_scm"

View File

@ -16,6 +16,12 @@
<parameter name="subdir">
<description>package just a sub directory</description>
</parameter>
<parameter name="version">
<description>Specify version to be used in tarball. Defaults to automatically detected value formatted by versionformat parameter. If using keep-source, you should set this to a fixed constant which will be used to name the checked out directory.</description>
</parameter>
<parameter name="versionformat">
<description>Auto-generate version from checked out source using this format string. For git, value is passed via git show --pretty=format:... (default '%at'); for hg, via hg log --template=... (default '{rev}'); for bzr and svn, %r is revision (default '%r'). Overrides tarball name defined by version parameter.</description>
</parameter>
<parameter name="versionprefix">
<description>specify a base version as prefix.</description>
</parameter>
@ -23,7 +29,7 @@
<description>specify a revision</description>
</parameter>
<parameter name="filename">
<description>base file name to be created</description>
<description>name of package - used together with version to determine tarball name</description>
</parameter>
<parameter name="exclude">
<description>for specifying excludes when creating the tar ball</description>
@ -31,9 +37,6 @@
<parameter name="include">
<description>for specifying subset of files/subdirectories to pack in the tar ball</description>
</parameter>
<parameter name="version">
<description>version to be used in tar. Setting it to an empty string is disabling the version tag.</description>
</parameter>
<parameter name="package-meta">
<description>Package the meta data of SCM to allow the user or OBS to update after un-tar</description>
<allowedvalue>yes</allowedvalue>

View File

@ -25,6 +25,7 @@ class TestEnvironment:
return
print "++++++ setupClass ++++++"
ScmInvocationLogs.setup_bin_wrapper(cls.scm, cls.tmp_dir)
os.putenv('DEBUG_TAR_SCM', 'yes')
cls.is_setup = True
def calcPaths(self):