diff treepkg/subversion.py @ 304:6cffb43a28ca

Add a way to specify svn subset checkouts where only parts of a source tree are checked out. The subset can be specified in the configuration file on a per-track basis. This feature was already present for some of the kde enterprise packagers but is now part of the base classes.
author Bernhard Herzog <bh@intevation.de>
date Thu, 26 Nov 2009 20:20:57 +0000
parents df01eb4dbfc5
children d0acc0614de5
line wrap: on
line diff
--- a/treepkg/subversion.py	Thu Nov 26 15:37:48 2009 +0000
+++ b/treepkg/subversion.py	Thu Nov 26 20:20:57 2009 +0000
@@ -120,21 +120,60 @@
 
     """Describes a subversion repository"""
 
-    def __init__(self, url, external_subdirs=()):
+    def __init__(self, url, external_subdirs=(), subset=()):
         """Initialize the subversion repository description
         Parameters:
           url -- The url of the repository
+
           external_subdirs -- A list of subdirectories which are managed
                               by svn externals definitions
+
+          subset -- A sequence of (filename, recurse) pairs where
+                    filename is a filename (usually a directory name)
+                    relative to url and recurse should be a boolean
+                    indicating whether checkout filename with recursion.
+                    If recurse is False, svn checkout/export will be
+                    called with the -N option.
+
+                    The first item in subset should be for '.', which
+                    indicates the top-level directory under url.  If a
+                    non-empty subset is given this will usually be
+                    ('.', False) so that the top-level directory is not
+                    checked out recursively.
         """
         self.url = url
         self.external_subdirs = external_subdirs
+        if not subset:
+            # default subset is to checkout the top-level directory at
+            # URL recursively.  Alwas having a subset makes the code
+            # simpler
+            subset = [(".", True)]
+        self.subset = subset
 
     def checkout(self, localdir, revision=None):
-        """Checks out the repository into localdir.  The revision
-        parameter should be an and indicates the revision to check out.
+        """Checks out the repository into localdir.
+        The revision parameter should be an int and indicates the
+        revision to check out or it should be None to indicate that the
+        newest version is to be checked out.
         """
-        checkout(self.url, localdir, revision=revision)
+        base_url = self.url
+        if not base_url.endswith("/"):
+            base_url += "/"
+        subdir, recurse = self.subset[0]
+        checkout(base_url + subdir, os.path.join(localdir, subdir),
+                 revision=revision, recurse=recurse)
+        for subdir, recurse in self.subset[1:]:
+            update(os.path.join(localdir, subdir), revision=revision,
+                   recurse=recurse)
+        if len(self.subset) > 1 and revision is None:
+            # do an additional update on the whole working copy after
+            # creating a subset checkout so that svn info will show
+            # revision numbers that match the entire working copy
+            # (externals are handled elsewhere).  The repository might
+            # have been changed between the initial checkout of the
+            # top-level directory and the updates for the
+            # subdirectories.
+            update(localdir, revision=revision)
 
     def export(self, localdir, destdir):
         """Exports the working copy in localdir to destdir"""
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)