Mercurial > hgsubversion
comparison hgsubversion/svnmeta.py @ 748:e1e2af66953d
svnmeta: store subdir in a file, and verify it when loading.
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Fri, 12 Nov 2010 19:22:20 +0100 |
parents | 34b25f6bc4ef |
children | cc1d4aa3ba41 |
comparison
equal
deleted
inserted
replaced
747:34b25f6bc4ef | 748:e1e2af66953d |
---|---|
30 hgutil.rename(path, file_path) | 30 hgutil.rename(path, file_path) |
31 | 31 |
32 | 32 |
33 class SVNMeta(object): | 33 class SVNMeta(object): |
34 | 34 |
35 def __init__(self, repo, uuid=None, subdir=''): | 35 def __init__(self, repo, uuid=None, subdir=None): |
36 """path is the path to the target hg repo. | 36 """path is the path to the target hg repo. |
37 | 37 |
38 subdir is the subdirectory of the edits *on the svn server*. | 38 subdir is the subdirectory of the edits *on the svn server*. |
39 It is needed for stripping paths off in certain cases. | 39 It is needed for stripping paths off in certain cases. |
40 """ | 40 """ |
43 self.path = os.path.normpath(repo.join('..')) | 43 self.path = os.path.normpath(repo.join('..')) |
44 | 44 |
45 if not os.path.isdir(self.meta_data_dir): | 45 if not os.path.isdir(self.meta_data_dir): |
46 os.makedirs(self.meta_data_dir) | 46 os.makedirs(self.meta_data_dir) |
47 self.uuid = uuid | 47 self.uuid = uuid |
48 # TODO: validate subdir too | 48 self.subdir = subdir |
49 self.revmap = maps.RevMap(repo) | 49 self.revmap = maps.RevMap(repo) |
50 | 50 |
51 author_host = self.ui.config('hgsubversion', 'defaulthost', uuid) | 51 author_host = self.ui.config('hgsubversion', 'defaulthost', uuid) |
52 authors = self.ui.config('hgsubversion', 'authormap') | 52 authors = self.ui.config('hgsubversion', 'authormap') |
53 tag_locations = self.ui.configlist('hgsubversion', 'tagpaths', ['tags']) | 53 tag_locations = self.ui.configlist('hgsubversion', 'tagpaths', ['tags']) |
54 self.usebranchnames = self.ui.configbool('hgsubversion', | 54 self.usebranchnames = self.ui.configbool('hgsubversion', |
55 'usebranchnames', True) | 55 'usebranchnames', True) |
56 branchmap = self.ui.config('hgsubversion', 'branchmap') | 56 branchmap = self.ui.config('hgsubversion', 'branchmap') |
57 tagmap = self.ui.config('hgsubversion', 'tagmap') | 57 tagmap = self.ui.config('hgsubversion', 'tagmap') |
58 | 58 |
59 # FIXME: test that this hasn't changed! defer & compare? | |
60 if subdir: | |
61 # strip leading and trailing slashes | |
62 # collapse all repeated slashes to a single one | |
63 subdir = '/'.join(p for p in subdir.split('/') if p) | |
64 self.subdir = subdir | |
65 self.branches = {} | 59 self.branches = {} |
66 if os.path.exists(self.branch_info_file): | 60 if os.path.exists(self.branch_info_file): |
67 f = open(self.branch_info_file) | 61 f = open(self.branch_info_file) |
68 self.branches = pickle.load(f) | 62 self.branches = pickle.load(f) |
69 f.close() | 63 f.close() |
123 @property | 117 @property |
124 def editor(self): | 118 def editor(self): |
125 if not hasattr(self, '_editor'): | 119 if not hasattr(self, '_editor'): |
126 self._editor = editor.HgEditor(self) | 120 self._editor = editor.HgEditor(self) |
127 return self._editor | 121 return self._editor |
122 | |
123 def _get_subdir(self): | |
124 return self.__subdir | |
125 | |
126 def _set_subdir(self, subdir): | |
127 if subdir: | |
128 subdir = '/'.join(p for p in subdir.split('/') if p) | |
129 | |
130 subdirfile = os.path.join(self.meta_data_dir, 'subdir') | |
131 | |
132 if os.path.isfile(subdirfile): | |
133 stored_subdir = open(subdirfile).read() | |
134 assert stored_subdir is not None | |
135 if subdir is None: | |
136 self.__subdir = stored_subdir | |
137 elif subdir != stored_subdir: | |
138 raise hgutil.Abort('unable to work on a different path in the ' | |
139 'repository') | |
140 else: | |
141 self.__subdir = subdir | |
142 elif subdir is not None: | |
143 f = open(subdirfile, 'w') | |
144 f.write(subdir) | |
145 f.close() | |
146 self.__subdir = subdir | |
147 else: | |
148 raise hgutil.Abort("hgsubversion metadata unavailable; " | |
149 "please run 'hg svn rebuildmeta'") | |
150 | |
151 subdir = property(_get_subdir, _set_subdir, None, | |
152 'Error-checked sub-directory of source Subversion ' | |
153 'repository.') | |
128 | 154 |
129 def _get_uuid(self): | 155 def _get_uuid(self): |
130 return self.__uuid | 156 return self.__uuid |
131 | 157 |
132 def _set_uuid(self, uuid): | 158 def _set_uuid(self, uuid): |