changeset 1026:66395f232b7c

layouts: pull tag location list management into layout module We keep a list of locations within subversion where we look for tags that persists across runs. This pulls the logic for constructiong that list from config on first clone, and for mainting the list afterwards out of svnmeta and into layouts.
author David Schleimer <dschleimer@fb.com>
date Tue, 21 May 2013 16:29:18 -0700
parents 2bf860f327e2
children 16045f6f3fef
files hgsubversion/layouts/base.py hgsubversion/layouts/single.py hgsubversion/layouts/standard.py hgsubversion/svnmeta.py
diffstat 4 files changed, 41 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/layouts/base.py
+++ b/hgsubversion/layouts/base.py
@@ -41,3 +41,11 @@ class BaseLayout(object):
 
         """
         self.__unimplemented('remotepath')
+
+    def taglocations(self, meta_data_dir):
+        """Return a list of locations within svn to search for tags
+
+        Should be returned in reverse-sorted order.
+
+        """
+        self.__unimplemented('tagpaths')
--- a/hgsubversion/layouts/single.py
+++ b/hgsubversion/layouts/single.py
@@ -13,3 +13,6 @@ class SingleLayout(base.BaseLayout):
 
     def remotepath(self, branch, subdir='/'):
         return subdir or '/'
+
+    def taglocations(self, meta_data_dir):
+        return []
--- a/hgsubversion/layouts/standard.py
+++ b/hgsubversion/layouts/standard.py
@@ -1,11 +1,17 @@
-
+import os.path
+import pickle
 
 import base
-
+import hgsubversion.util as util
 
 class StandardLayout(base.BaseLayout):
     """The standard trunk, branches, tags layout"""
 
+    def __init__(self, ui):
+        base.BaseLayout.__init__(self, ui)
+
+        self._tag_locations = None
+
     def localname(self, path):
         if path == 'trunk':
             return None
@@ -29,3 +35,24 @@ class StandardLayout(base.BaseLayout):
                 branchpath = 'branches/%s' % branch
 
         return '%s/%s' % (subdir or '', branchpath)
+
+    def taglocations(self, meta_data_dir):
+        if self._tag_locations is None:
+
+            tag_locations_file = os.path.join(meta_data_dir, 'tag_locations')
+
+            if os.path.exists(tag_locations_file):
+                f = open(tag_locations_file)
+                self._tag_locations = pickle.load(f)
+                f.close()
+            else:
+                self._tag_locations = self.ui.configlist('hgsubversion',
+                                                        'tagpaths',
+                                                        ['tags'])
+            util.pickle_atomic(self._tag_locations, tag_locations_file)
+
+            # ensure nested paths are handled properly
+            self._tag_locations.sort()
+            self._tag_locations.reverse()
+
+        return self._tag_locations
--- a/hgsubversion/svnmeta.py
+++ b/hgsubversion/svnmeta.py
@@ -34,7 +34,6 @@ class SVNMeta(object):
 
         author_host = self.ui.config('hgsubversion', 'defaulthost', uuid)
         authors = util.configpath(self.ui, 'authormap')
-        tag_locations = self.ui.configlist('hgsubversion', 'tagpaths', ['tags'])
         self.usebranchnames = self.ui.configbool('hgsubversion',
                                                  'usebranchnames', True)
         branchmap = util.configpath(self.ui, 'branchmap')
@@ -48,19 +47,9 @@ class SVNMeta(object):
             f.close()
         self.prevbranches = dict(self.branches)
         self.tags = maps.Tags(repo)
-        if os.path.exists(self.tag_locations_file):
-            f = open(self.tag_locations_file)
-            self.tag_locations = pickle.load(f)
-            f.close()
-        else:
-            self.tag_locations = tag_locations
         self._layout = layouts.detect.layout_from_file(self.meta_data_dir,
                                                        ui=self.repo.ui)
         self._layoutobj = None
-        util.pickle_atomic(self.tag_locations, self.tag_locations_file)
-        # ensure nested paths are handled properly
-        self.tag_locations.sort()
-        self.tag_locations.reverse()
 
         self.authors = maps.AuthorMap(self.ui, self.authors_file,
                                  defaulthost=author_host)
@@ -167,10 +156,6 @@ class SVNMeta(object):
     def branch_info_file(self):
         return os.path.join(self.meta_data_dir, 'branch_info')
 
-    @property
-    def tag_locations_file(self):
-        return os.path.join(self.meta_data_dir, 'tag_locations')
-
     @property
     def authors_file(self):
         return os.path.join(self.meta_data_dir, 'authors')
@@ -268,7 +253,7 @@ class SVNMeta(object):
         """
         if self.layout != 'single':
             path = self.normalize(path)
-            for tagspath in self.tag_locations:
+            for tagspath in self.layoutobj.taglocations(self.meta_data_dir):
                 if path.startswith(tagspath + '/'):
                     tag = path[len(tagspath) + 1:]
                     if tag: