Mercurial > hgsubversion
comparison hgsubversion/layouts/standard.py @ 1291:13f8e9cc90c6
layouts: generate cached taglocations property
Now that we have the machinery, we use the generator to define this
property. As a bonus, we no longer have to import util which saves from having
to import hgext_util.
author | Sean Farley <sean.michael.farley@gmail.com> |
---|---|
date | Mon, 24 Mar 2014 11:20:53 -0500 |
parents | cc1e2c8cdaa6 |
children | 7bbe120be193 |
comparison
equal
deleted
inserted
replaced
1290:3549a84bdebe | 1291:13f8e9cc90c6 |
---|---|
22 x = '/'.join(p for p in x.split('/') if p) | 22 x = '/'.join(p for p in x.split('/') if p) |
23 if x: | 23 if x: |
24 x = '/' + x | 24 x = '/' + x |
25 return x | 25 return x |
26 meta._gen_cachedconfig('infix', '', pre=_infix_transform) | 26 meta._gen_cachedconfig('infix', '', pre=_infix_transform) |
27 | |
28 # the lambda is to ensure nested paths are handled properly | |
29 meta._gen_cachedconfig('taglocations', ['tags'], 'tag_locations', | |
30 'tagpaths', lambda x: list(reversed(sorted(x)))) | |
27 | 31 |
28 @property | 32 @property |
29 def trunk(self): | 33 def trunk(self): |
30 return 'trunk' + self.meta.infix | 34 return 'trunk' + self.meta.infix |
31 | 35 |
61 self.meta.infix)) | 65 self.meta.infix)) |
62 | 66 |
63 return '%s/%s' % (subdir or '', branchpath) | 67 return '%s/%s' % (subdir or '', branchpath) |
64 | 68 |
65 def taglocations(self, metapath): | 69 def taglocations(self, metapath): |
66 # import late to avoid trouble when running the test suite | 70 return self.meta.taglocations |
67 try: | |
68 # newer versions of mercurial >= 2.8 will import this because the | |
69 # hgext_ logic is already being done in core | |
70 from hgsubversion import util | |
71 except ImportError: | |
72 from hgext_hgsubversion import util | |
73 | |
74 if self._tag_locations is None: | |
75 | |
76 tag_locations_file = os.path.join(metapath, 'tag_locations') | |
77 self._tag_locations = util.load(tag_locations_file) | |
78 | |
79 if not self._tag_locations: | |
80 self._tag_locations = self.meta.ui.configlist('hgsubversion', | |
81 'tagpaths', | |
82 ['tags']) | |
83 util.dump(self._tag_locations, tag_locations_file) | |
84 | |
85 # ensure nested paths are handled properly | |
86 self._tag_locations.sort() | |
87 self._tag_locations.reverse() | |
88 | |
89 return self._tag_locations | |
90 | 71 |
91 def get_path_tag(self, path, taglocations): | 72 def get_path_tag(self, path, taglocations): |
92 for tagspath in taglocations: | 73 for tagspath in taglocations: |
93 if path.startswith(tagspath + '/'): | 74 if path.startswith(tagspath + '/'): |
94 tag = path[len(tagspath) + 1:] | 75 tag = path[len(tagspath) + 1:] |