[jhbuild] [bzr] Improvements in Bzr support (GNOME bug 617114)
- From: Frederic Peters <fpeters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [jhbuild] [bzr] Improvements in Bzr support (GNOME bug 617114)
- Date: Fri, 11 Jun 2010 18:40:49 +0000 (UTC)
commit 6bb6439fa76a3dadc9bdb5c0828322c6c7dd6015
Author: Dmitrijs Ledkovs <dmitrij ledkov ubuntu com>
Date: Mon Apr 19 19:02:37 2010 +0100
[bzr] Improvements in Bzr support (GNOME bug 617114)
This adds support copy/export mode & sticky date; new branch attributes user,
branch & revspec; new repository template user_template; deprecate tag,
revision.
1) Fixes copy mode, adds support for export mode and dvcs_mirror submode.
2) New attributes user, branch & user_template are used similar to svn
templates. The defaults are now launchpad friendly while staying backwards
compatible and allowing full flexibility for laying out all modules on other
hostring sites. The intention is to use "lp:" as repository href for launchpad.
With these tags all branches are mapped e.g. lp:project (trunk),
lp:project/series (branch), lp:~user/project/series (user).
3) Obsoletes revision & tag, replaced by branch & revspec. Revision comes from
the svn.py where it used to specify exact revision or branch. And doesn't allow
to specify exact revision on a branch. So revision is now replaced by branch
attribute which is used only to specify a branch name. Revspec is used to
specify exact revision, sticky-date, tag or any other wacky stuff revspec
supports. This will allow svn.py to pass e.g. "svn:45" revspec to specify svn
revision 45, if svn_program == 'bzr'. Also via revspec sticky_date is
supported, e.g. "-rdate:%(sticky_date)s" and obsolete tag attribute
"-rtag:%(tag)".
4) Everything is backwards compatible. Users of undocumented (tag, revision)
should migrate to (revspec, (branch, revspec)).
5) checkout branch-id is now "revision-id --tree" which is unique reference of
the tree used in the build.
jhbuild/versioncontrol/bzr.py | 127 ++++++++++++++++++++++++++++-------------
1 files changed, 88 insertions(+), 39 deletions(-)
---
diff --git a/jhbuild/versioncontrol/bzr.py b/jhbuild/versioncontrol/bzr.py
index bf26520..0dad6d5 100644
--- a/jhbuild/versioncontrol/bzr.py
+++ b/jhbuild/versioncontrol/bzr.py
@@ -23,6 +23,7 @@ __metaclass__ = type
import os
import errno
import urlparse
+import logging
from jhbuild.errors import FatalError, CommandError
from jhbuild.utils.cmds import get_output
@@ -55,17 +56,17 @@ class BzrRepository(Repository):
init_xml_attrs = ['href', 'trunk-template', 'branches-template']
- def __init__(self, config, name, href, trunk_template='%(module)s', branches_template=''):
+ def __init__(self, config, name, href, trunk_template='%(module)s', branches_template='%(module)s/%(branch)s'):
Repository.__init__(self, config, name)
# allow user to adjust location of branch.
self.href = config.repos.get(name, href)
self.trunk_template = trunk_template
self.branches_template = branches_template
- branch_xml_attrs = ['module', 'checkoutdir', 'revision', 'tag']
+ branch_xml_attrs = ['module', 'checkoutdir', 'revision', 'tag', 'user', 'revspec', 'branch']
- def branch(self, name, module=None, checkoutdir=None, revision=None, tag=None):
- module_href = None
+ def branch(self, name, module=None, checkoutdir=None, revision=None,
+ tag=None, user=None, revspec=None, branch=None, module_href=None):
if name in self.config.branches:
module_href = self.config.branches[name]
if not module_href:
@@ -74,7 +75,7 @@ class BzrRepository(Repository):
if module is None:
module = name
- if revision and not revision.isdigit():
+ if revision or branch:
template = urlparse.urljoin(self.href, self.branches_template)
else:
template = urlparse.urljoin(self.href, self.trunk_template)
@@ -83,33 +84,52 @@ class BzrRepository(Repository):
module_href = template % {
'module': module,
'revision': revision,
- 'branch': revision,
- 'tag': tag
+ 'branch': branch,
+ 'tag' : tag,
+ 'user': user,
}
if checkoutdir is None:
checkoutdir = name
- return BzrBranch(self, module_href, checkoutdir, tag)
-
+ return BzrBranch(self, module_href, checkoutdir, tag, revspec)
class BzrBranch(Branch):
"""A class representing a Bazaar branch."""
- def __init__(self, repository, module_href, checkoutdir, tag):
+ def __init__(self, repository, module_href, checkoutdir, tag, revspec):
Branch.__init__(self, repository, module_href, checkoutdir)
- self.tag = tag
+ self._revspec = None
+ self.revspec = (tag, revspec)
+
+ def get_revspec(self):
+ return self._revspec
+
+ def set_revspec(self, (tag, revspec)):
+ if revspec:
+ self._revspec = ['-r%s' % revspec]
+ elif tag:
+ logging.info('tag ' + _('attribute is deprecated. Use revspec instead.'))
+ self._revspec = ['-rtag:%s' % tag]
+ elif self.config.sticky_date:
+ self._revspec = ['-rdate:%s' % self.config.sticky_date]
+ else:
+ self._revspec = []
+ revspec = property(get_revspec, set_revspec)
def srcdir(self):
- if self.checkoutdir:
- return os.path.join(self.checkoutroot, self.checkoutdir)
- else:
- return os.path.join(self.checkoutroot,
- os.path.basename(self.module))
+ return Branch.get_checkoutdir(self)
+
srcdir = property(srcdir)
+ def get_module_basename(self):
+ return self.checkoutdir
+
def branchname(self):
- return None
+ try:
+ return get_output(['bzr', 'nick', self.srcdir])
+ except:
+ return None
branchname = property(branchname)
def exists(self):
@@ -119,29 +139,58 @@ class BzrBranch(Branch):
except:
return False
- def _checkout(self, buildscript):
- cmd = ['bzr', 'branch', self.module]
- if self.checkoutdir:
- cmd.append(self.checkoutdir)
+ def create_mirror(self, buildscript):
+ if not self.config.dvcs_mirror_dir:
+ return
+ if self.config.nonetwork:
+ return
+
+ if not os.path.exists(os.path.join(self.config.dvcs_mirror_dir, '.bzr')):
+ cmd = ['bzr', 'init-repo', '--no-trees', self.config.dvcs_mirror_dir]
+ buildscript.execute(cmd)
+
+ local_mirror = os.path.join(self.config.dvcs_mirror_dir, self.checkoutdir)
+
+ if not os.path.exists(local_mirror):
+ cmd = ['bzr', 'init', '--create-prefix', local_mirror]
+ buildscript.execute(cmd)
+
+ if os.path.exists(self.srcdir):
+ cmd = ['bzr', 'info', self.srcdir]
+ cwd = self.config.dvcs_mirror_dir
+ try:
+ info = get_output(cmd, cwd=cwd)
+ if info.find('checkout of branch: %s' % self.checkoutdir) == -1:
+ raise NameError
+ except:
+ raise FatalError(_("""
+Path %s does not seem to be a checkout from dvcs_mirror_dir.
+Remove it or change your dvcs_mirror_dir settings.""") % self.srcdir)
+
+ else:
+ cmd = ['bzr', 'co', '--light', mirror_href, self.srcdir]
+ buildscript.execute(cmd)
- if self.tag:
- cmd.append('-rtag:%s' % self.tag)
+ def _checkout(self, buildscript, copydir=None):
+ if self.config.dvcs_mirror_dir:
+ self.create_mirror(buildscript)
+ self.real_update(buildscript)
+ else:
+ cmd = ['bzr', 'branch'] + self.revspec + [self.module, self.srcdir]
+ buildscript.execute(cmd)
- if self.config.sticky_date:
- raise FatalError(_('date based checkout not yet supported\n'))
+ def _export(self, buildscript):
+ cmd = ['bzr', 'export'] + self.revspec + [self.srcdir, self.module]
+ buildscript.execute(cmd)
- buildscript.execute(cmd, 'bzr', cwd=self.checkoutroot)
+ def real_update(self, buildscript):
+ cmd = ['bzr', 'pull'] + self.revspec + [self.module, '-d', self.srcdir]
+ buildscript.execute(cmd)
+ cmd = ['bzr', 'update'] + self.revspec + [self.srcdir]
- def _update(self, buildscript, overwrite=False):
- if self.config.sticky_date:
- raise FatalError(_('date based checkout not yet supported\n'))
- cmd = ['bzr', 'pull']
- if overwrite:
- cmd.append('--overwrite')
- if self.tag:
- cmd.append('-rtag:%s' % self.tag)
- cmd.append(self.module)
- buildscript.execute(cmd, 'bzr', cwd=self.srcdir)
+ def _update(self, buildscript, copydir=None):
+ self.create_mirror(buildscript)
+ self.real_update(buildscript)
def checkout(self, buildscript):
if not inpath('bzr', os.environ['PATH'].split(os.pathsep)):
@@ -151,8 +200,8 @@ class BzrBranch(Branch):
def tree_id(self):
if not os.path.exists(self.srcdir):
return None
- output = get_output(['bzr', 'revno'], cwd = self.srcdir)
- return output.strip()
-
+ else:
+ cmd = ['bzr', 'revision-info', '--tree', '-d', self.srcdir]
+ return get_output(cmd).strip()
register_repo_type('bzr', BzrRepository)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]