# HG changeset patch # User David Schleimer # Date 1369178958 25200 # Node ID 66395f232b7cb25e9ff6648f0fd4a5aea3802156 # Parent 2bf860f327e22276e54721373aa68c99819fa80a 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. diff --git a/hgsubversion/layouts/base.py b/hgsubversion/layouts/base.py --- 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') diff --git a/hgsubversion/layouts/single.py b/hgsubversion/layouts/single.py --- 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 [] diff --git a/hgsubversion/layouts/standard.py b/hgsubversion/layouts/standard.py --- 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 diff --git a/hgsubversion/svnmeta.py b/hgsubversion/svnmeta.py --- 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: