Index: jhbuild/versioncontrol/bzr.py
===================================================================
--- jhbuild/versioncontrol/bzr.py	(révision 2162)
+++ jhbuild/versioncontrol/bzr.py	(copie de travail)
@@ -28,6 +28,13 @@
 from jhbuild.utils.cmds import get_output
 from jhbuild.versioncontrol import Repository, Branch, register_repo_type
 
+try:
+    import bzrlib
+    import bzrlib.bzrdir
+except ImportError:
+    # no bzr lib, no playground
+    bzrlib = None
+
 # Make sure that the urlparse module considers sftp://
 # scheme to be netloc aware and set to allow relative URIs.
 if 'sftp' not in urlparse.uses_netloc:
@@ -52,9 +59,9 @@
         # allow user to adjust location of branch.
         self.href = config.repos.get(name, href)
 
-    branch_xml_attrs = ['module', 'checkoutdir']
+    branch_xml_attrs = ['module', 'checkoutdir', 'revision']
 
-    def branch(self, name, module=None, checkoutdir=None):
+    def branch(self, name, module=None, checkoutdir=None, revision=None):
         if name in self.config.branches:
             module = self.config.branches[name]
             if not module:
@@ -63,11 +70,18 @@
             if module is None:
                 module = name
             module = urlparse.urljoin(self.href, module)
-        return BzrBranch(self, module, checkoutdir)
+        if self.config.bzr_playground and bzrlib:
+            return BzrPlaygroundBranch(self, module, checkoutdir, revision)
+        else:
+            return BzrBranch(self, module, checkoutdir, revision)
 
 
 class BzrBranch(Branch):
-    """A class representing a Darcs branch."""
+    """A class representing a Bzr branch."""
+    
+    def __init__(self, repository, module, checkoutdir, revision):
+        Branch.__init__(self, repository, module, checkoutdir)
+        self.revision = revision
 
     def srcdir(self):
         if self.checkoutdir:
@@ -119,4 +133,109 @@
         return output.strip()
 
 
+class BzrPlaygroundBranch(BzrBranch):
+    """A class representing a Bzr branch."""
+
+    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))
+    srcdir = property(srcdir)
+
+    def branchname(self):
+        return self.revision
+    branchname = property(branchname)
+    
+    def get_parent_branch(self):
+        tree = bzrlib.bzrdir.BzrDir.open_containing(self.srcdir)[0].open_workingtree()
+        return tree.branch.get_parent()
+
+    def _checkout(self, buildscript):
+        if self.config.sticky_date:
+            raise FatalError(_('date based checkout not yet supported\n'))
+
+        repo_base_dir = os.path.join(self.checkoutroot, 'bzr-repos')
+        user, host = self.config.bzr_playground.split('@')
+        project = os.path.basename(self.module)
+        workingtree_base_dir = self.config.checkoutroot
+
+        remote_branch = 'bzr+ssh://%s@%s/bzr/gnome/%s' % (user, host, self.get_module_uri())
+        local_branch = os.path.join(repo_base_dir, project, self.branchname or 'devel')
+        local_tree = self.srcdir
+
+        location_config = bzrlib.config.LocationConfig(repo_base_dir)
+        location_config.set_user_option(
+                'push_location', 'bzr+ssh://%s@%s/bzr/%s' % (user, host, user),
+                bzrlib.config.STORE_LOCATION_APPENDPATH)
+        location_config.set_user_option(
+                'public_branch', 'http://%s/%s' % (host, user),
+                bzrlib.config.STORE_LOCATION_APPENDPATH)
+
+        if not os.path.exists(repo_base_dir):
+            os.makedirs(repo_base_dir)
+
+        repo_dir = os.path.join(repo_base_dir, project)
+        if not os.path.exists(repo_dir):
+            buildscript.message(_('Initialising Bzr Repository'))
+            buildscript.execute(['bzr', 'init-repo', '--no-trees',
+                    '--format=rich-root-pack', repo_dir])
+
+        location_config = bzrlib.config.LocationConfig(repo_dir)
+        location_config.set_user_option('submit_branch', remote_branch)
+
+        buildscript.message(_('Creating remote repository for %s') % project)
+        buildscript.execute(['ssh', '%s@%s' % (user, host),
+                'bzr', 'make-module-repo', project])
+
+        if not os.path.exists(local_branch):
+            buildscript.message(_('Branching %s to %s') % (remote_branch, local_branch))
+            buildscript.execute(['bzr', 'branch', remote_branch, local_branch])
+        else:
+            buildscript.execute(['bzr', 'pull'], cwd = local_branch)
+        
+        if os.path.exists(local_tree):
+            buildscript.execute(['bzr', 'switch', local_branch], cwd = local_tree)
+        else:
+            buildscript.execute(['bzr', 'checkout', '--lightweight',
+                    local_branch, local_tree])
+
+    def get_module_uri(self):
+        if self.branchname:
+            return self.module + '/branches/%s' % self.branchname
+        else:
+            return self.module + '/trunk'
+
+    def _update(self, buildscript, overwrite=False):
+        if not self.get_parent_branch().endswith(self.get_module_uri()):
+            # module switched branch
+            self._checkout(buildscript)
+        if self.config.sticky_date:
+            raise FatalError(_('date based checkout not yet supported\n'))
+        cmd = ['bzr', 'pull']
+        if overwrite:
+            cmd.append('--overwrite')
+        buildscript.execute(cmd, 'bzr', cwd=self.srcdir)
+
+    def checkout(self, buildscript):
+        if os.path.exists(self.srcdir):
+            self._update(buildscript)
+        else:
+            self._checkout(buildscript)
+
+    def force_checkout(self, buildscript):
+        if os.path.exists(self.srcdir):
+            self._update(buildscript, overwrite=True)
+        else:
+            self._checkout(buildscript)
+
+    def tree_id(self):
+        if not os.path.exists(self.srcdir):
+            return None
+        output = get_output(['bzr', 'revno'], cwd = self.srcdir)
+        return output.strip()
+
+
+
 register_repo_type('bzr', BzrRepository)
Index: jhbuild/versioncontrol/svn.py
===================================================================
--- jhbuild/versioncontrol/svn.py	(révision 2162)
+++ jhbuild/versioncontrol/svn.py	(copie de travail)
@@ -152,8 +152,8 @@
         if checkoutdir is None:
             checkoutdir = name
         
-        if self.svn_program == 'bzr' and not revision:
-            return bzr.BzrBranch(self, module_href, checkoutdir)
+        if self.svn_program == 'bzr':
+            return bzr.BzrPlaygroundBranch(self, name, checkoutdir, revision)
         elif self.svn_program == 'git-svn':
             return git.GitSvnBranch(self, module_href, checkoutdir, revision)
         else:
Index: jhbuild/config.py
===================================================================
--- jhbuild/config.py	(révision 2162)
+++ jhbuild/config.py	(copie de travail)
@@ -42,7 +42,8 @@
                 'checkout_mode', 'copy_dir', 'module_checkout_mode',
                 'build_policy', 'trycheckout', 'min_time',
                 'nopoison', 'makecheck_advisory',
-                'quiet_mode', 'progress_bar', 'module_extra_env']
+                'quiet_mode', 'progress_bar', 'module_extra_env',
+                'bzr_playground']
 
 env_prepends = {}
 def prependpath(envvar, path):
Index: jhbuild/defaults.jhbuildrc
===================================================================
--- jhbuild/defaults.jhbuildrc	(révision 2162)
+++ jhbuild/defaults.jhbuildrc	(copie de travail)
@@ -118,3 +118,5 @@
 # arguments to pass to xvfb
 xvfbargs = ''
 
+# set to user@playground-server
+bzr_playground = None
