[jhbuild] refactor checkout modes support



commit e4b13aee7458e51f1034e5dc60a2af1a680ceaae
Author: Frederic Peters <fpeters 0d be>
Date:   Thu Apr 30 18:27:40 2009 +0200

    refactor checkout modes support
    
    Merged much code from the different version control systems into the base
    class, to provide consistent and solid support for checkout modes.  This
    notably fixes copy mode for Git (GNOME #580815) and svn (GNOME #580910).
---
 jhbuild/versioncontrol/__init__.py |   38 +++++++++++++++++++++++++++++++++++-
 jhbuild/versioncontrol/arch.py     |    5 +---
 jhbuild/versioncontrol/bzr.py      |    5 +---
 jhbuild/versioncontrol/cvs.py      |   22 +-------------------
 jhbuild/versioncontrol/darcs.py    |    6 +----
 jhbuild/versioncontrol/git.py      |   30 +--------------------------
 jhbuild/versioncontrol/hg.py       |    5 +---
 jhbuild/versioncontrol/mtn.py      |    1 +
 jhbuild/versioncontrol/svn.py      |   22 +-------------------
 9 files changed, 46 insertions(+), 88 deletions(-)

diff --git a/jhbuild/versioncontrol/__init__.py b/jhbuild/versioncontrol/__init__.py
index 3b0e790..46b5929 100644
--- a/jhbuild/versioncontrol/__init__.py
+++ b/jhbuild/versioncontrol/__init__.py
@@ -92,12 +92,45 @@ class Branch:
            May raise NotImplementedError if cannot check a given branch."""
         raise NotImplementedError
 
+    def get_checkoutdir(self):
+        if self.config.checkout_mode == 'copy' and self.config.copy_dir:
+            return os.path.join(self.config.copy_dir, os.path.basename(self.module))
+        if self.checkoutdir:
+            return os.path.join(self.checkoutroot, self.checkoutdir)
+        else:
+            return os.path.join(self.checkoutroot, os.path.basename(self.module))
+
+
     def checkout(self, buildscript):
         """Checkout or update the given source directory.
 
         May raise CommandError or BuildStateError if a problem occurrs.
         """
-        raise NotImplementedError
+        if self.checkout_mode in ('clobber', 'export'):
+            self._wipedir(buildscript)
+            if self.checkout_mode == 'export':
+                try:
+                    self._export(buildscript)
+                except NotImplementedError:
+                    pass
+                else:
+                    return
+            self._checkout(buildscript)
+        elif self.checkout_mode in ('update', 'copy'):
+            if self.checkout_mode == 'copy' and self.config.copy_dir:
+                copydir = self.config.copy_dir
+                if os.path.exists(os.path.join(copydir,
+                            os.path.basename(self.get_checkoutdir()))):
+                    self._update(buildscript, copydir)
+                else:
+                    self._wipedir(buildscript)
+                    self._checkout(buildscript, copydir)
+                self._copy(buildscript, copydir)
+            else:
+                if os.path.exists(self.get_checkoutdir()):
+                    self._update(buildscript)
+                else:
+                    self._checkout(buildscript)
 
     def force_checkout(self, buildscript):
         """A more agressive version of checkout()."""
@@ -112,6 +145,9 @@ class Branch:
         if os.path.exists(self.srcdir):
             buildscript.execute(['rm', '-rf', self.srcdir])
 
+    def _export(self, buildscript):
+        raise NotImplementedError
+
     def _copy(self, buildscript, copydir):
          module = self.module
          if self.checkoutdir:
diff --git a/jhbuild/versioncontrol/arch.py b/jhbuild/versioncontrol/arch.py
index 045785f..7a2b411 100644
--- a/jhbuild/versioncontrol/arch.py
+++ b/jhbuild/versioncontrol/arch.py
@@ -153,10 +153,7 @@ class ArchBranch(Branch):
     def checkout(self, buildscript):
         if not inpath('arch', os.environ['PATH'].split(os.pathsep)):
             raise CommandError(_('%s not found') % 'arch')
-        if os.path.exists(self.srcdir):
-            self._update(buildscript)
-        else:
-            self._checkout(buildscript)
+        Branch.checkout(self, buildscript)
 
     def tree_id(self):
         if not os.path.exists(self.srcdir):
diff --git a/jhbuild/versioncontrol/bzr.py b/jhbuild/versioncontrol/bzr.py
index e386d8f..bf26520 100644
--- a/jhbuild/versioncontrol/bzr.py
+++ b/jhbuild/versioncontrol/bzr.py
@@ -146,10 +146,7 @@ class BzrBranch(Branch):
     def checkout(self, buildscript):
         if not inpath('bzr', os.environ['PATH'].split(os.pathsep)):
             raise CommandError(_('%s not found') % 'bzr')
-        if os.path.exists(self.srcdir):
-            self._update(buildscript)
-        else:
-            self._checkout(buildscript)
+        Branch.checkout(self, buildscript)
 
     def tree_id(self):
         if not os.path.exists(self.srcdir):
diff --git a/jhbuild/versioncontrol/cvs.py b/jhbuild/versioncontrol/cvs.py
index 811e4af..06a03d3 100644
--- a/jhbuild/versioncontrol/cvs.py
+++ b/jhbuild/versioncontrol/cvs.py
@@ -295,27 +295,7 @@ class CVSBranch(Branch):
     def checkout(self, buildscript):
         if not inpath('cvs', os.environ['PATH'].split(os.pathsep)):
             raise CommandError(_('%s not found') % 'cvs')
-        if self.checkout_mode in ('clobber', 'export'):
-            self._wipedir(buildscript)
-            if self.checkout_mode == 'clobber':
-                self._checkout(buildscript)
-            else:
-                self._export(buildscript)
-        elif self.checkout_mode in ('update', 'copy'):
-            if self.checkout_mode == 'copy' and self.config.copy_dir:
-                copydir = self.config.copy_dir
-                if os.path.exists(os.path.join(copydir, 
-                                  os.path.basename(self.srcdir), 'CVS')):
-                    self._update(buildscript, copydir)
-                else:
-                    self._wipedir(buildscript)
-                    self._checkout(buildscript, copydir)
-                self._copy(buildscript, copydir)
-            else:
-                if os.path.exists(self.srcdir):
-                    self._update(buildscript, copydir = self.config.checkoutroot)
-                else:
-                    self._checkout(buildscript, copydir = self.config.checkoutroot)
+        Branch.checkout(self, buildscript)
 
     def tree_id(self):
         if not os.path.exists(self.srcdir):
diff --git a/jhbuild/versioncontrol/darcs.py b/jhbuild/versioncontrol/darcs.py
index cc7593a..525a7f8 100644
--- a/jhbuild/versioncontrol/darcs.py
+++ b/jhbuild/versioncontrol/darcs.py
@@ -106,11 +106,7 @@ class DarcsBranch(Branch):
     def checkout(self, buildscript):
         if not inpath('darcs', os.environ['PATH'].split(os.pathsep)):
             raise CommandError(_('%s not found') % 'darcs')
-
-        if os.path.exists(self.srcdir):
-            self._update(buildscript)
-        else:
-            self._checkout(buildscript)
+        Branch.checkout(self, buildscript)
         self._fix_permissions()
 
     def tree_id(self):
diff --git a/jhbuild/versioncontrol/git.py b/jhbuild/versioncontrol/git.py
index 3959714..d76b1a9 100644
--- a/jhbuild/versioncontrol/git.py
+++ b/jhbuild/versioncontrol/git.py
@@ -123,15 +123,6 @@ class GitBranch(Branch):
         return os.path.join(*path_elements)
     srcdir = property(srcdir)
 
-    def get_checkoutdir(self, copydir=None):
-        if copydir:
-            return os.path.join(copydir, os.path.basename(self.module))
-        elif self.checkoutdir:
-            return os.path.join(self.checkoutroot, self.checkoutdir)
-        else:
-            return os.path.join(self.checkoutroot,
-                                os.path.basename(self.module))
-
     def local_branch_exist(self, branch, buildscript=None):
         try:
             cmd = ['git', 'show-ref', '--quiet', '--verify', 'refs/heads/' + branch]
@@ -230,7 +221,7 @@ class GitBranch(Branch):
 
 
     def _update(self, buildscript, copydir=None, update_mirror=True):
-        cwd = self.get_checkoutdir(copydir)
+        cwd = self.get_checkoutdir()
 
         if not os.path.exists(os.path.join(cwd, '.git')):
             if os.path.exists(os.path.join(cwd, '.svn')):
@@ -296,24 +287,7 @@ class GitBranch(Branch):
     def checkout(self, buildscript):
         if not inpath('git', os.environ['PATH'].split(os.pathsep)):
             raise CommandError(_('%s not found') % 'git')
-        if self.checkout_mode in ('clobber', 'export'):
-            self._wipedir(buildscript)
-            self._checkout(buildscript)
-        elif self.checkout_mode in ('update', 'copy'):
-            if self.checkout_mode == 'copy' and self.config.copy_dir:
-                copydir = self.config.copy_dir
-                if os.path.exists(os.path.join(copydir,
-                        os.path.basename(self.get_checkoutdir()), '.git')):
-                    self._update(buildscript, copydir)
-                else:
-                    self._wipedir(buildscript)
-                    self._checkout(buildscript, copydir)
-                self._copy(buildscript, copydir)
-            else:
-                if os.path.exists(self.get_checkoutdir()):
-                    self._update(buildscript)
-                else:
-                    self._checkout(buildscript)
+        Branch.checkout(self, buildscript)
 
     def tree_id(self):
         if not os.path.exists(self.srcdir):
diff --git a/jhbuild/versioncontrol/hg.py b/jhbuild/versioncontrol/hg.py
index 53670ba..f485b8a 100644
--- a/jhbuild/versioncontrol/hg.py
+++ b/jhbuild/versioncontrol/hg.py
@@ -98,10 +98,7 @@ class HgBranch(Branch):
     def checkout(self, buildscript):
         if not inpath('hg', os.environ['PATH'].split(os.pathsep)):
             raise CommandError(_('%s not found') % 'hg')
-        if os.path.exists(self.srcdir):
-            self._update(buildscript)
-        else:
-            self._checkout(buildscript)
+        Branch.checkout(self, buildscript)
 
     def get_revision_id(self):
         # Return the id of the tip, see bug #313997.
diff --git a/jhbuild/versioncontrol/mtn.py b/jhbuild/versioncontrol/mtn.py
index 352a694..b731de2 100644
--- a/jhbuild/versioncontrol/mtn.py
+++ b/jhbuild/versioncontrol/mtn.py
@@ -135,6 +135,7 @@ class MonotoneBranch(Branch):
         buildscript.execute(cmd, 'mtn', cwd=self._codir)
 
     def checkout(self, buildscript):
+        # XXX: doesn't support alternative checkout modes
         if not inpath('mtn', os.environ['PATH'].split(os.pathsep)):
             raise CommandError(_('%s not found') % 'mtn')
 
diff --git a/jhbuild/versioncontrol/svn.py b/jhbuild/versioncontrol/svn.py
index 570f75c..1685beb 100644
--- a/jhbuild/versioncontrol/svn.py
+++ b/jhbuild/versioncontrol/svn.py
@@ -309,27 +309,7 @@ class SubversionBranch(Branch):
     def checkout(self, buildscript):
         if not inpath('svn', os.environ['PATH'].split(os.pathsep)):
             raise CommandError(_('%s not found') % 'svn')
-        if self.checkout_mode in ('clobber', 'export'):
-            self._wipedir(buildscript)
-            if self.checkout_mode == 'clobber':
-                self._checkout(buildscript)
-            else:
-                self._export(buildscript)
-        elif self.checkout_mode in ('update', 'copy'):
-            if self.checkout_mode == 'copy' and self.config.copy_dir:
-                copydir = self.config.copy_dir
-                if os.path.exists(os.path.join(copydir,
-                                  os.path.basename(self.srcdir), '.svn')):
-                    self._update(buildscript, copydir)
-                else:
-                    self._wipedir(buildscript)
-                    self._checkout(buildscript, copydir)
-                self._copy(buildscript, copydir)
-            else:
-                if os.path.exists(self.srcdir):
-                    self._update(buildscript, copydir = self.config.checkoutroot)
-                else:
-                    self._checkout(buildscript, copydir = self.config.checkoutroot)
+        Branch.checkout(self, buildscript)
 
     def tree_id(self):
         if not os.path.exists(self.srcdir):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]