Mercurial > hgsubversion
comparison hgsubversion/maps.py @ 1183:09b20039192c
maps: change revmap init to accept svnmeta not a repo
This will allow us to access config options through one object.
author | Sean Farley <sean.michael.farley@gmail.com> |
---|---|
date | Mon, 24 Mar 2014 11:20:44 -0500 |
parents | 8f9619a67565 |
children | 43384d2782dc |
comparison
equal
deleted
inserted
replaced
1182:8f9619a67565 | 1183:09b20039192c |
---|---|
192 | 192 |
193 class RevMap(dict): | 193 class RevMap(dict): |
194 | 194 |
195 VERSION = 1 | 195 VERSION = 1 |
196 | 196 |
197 def __init__(self, repo): | 197 def __init__(self, meta): |
198 dict.__init__(self) | 198 dict.__init__(self) |
199 self.path = self.mappath(repo) | 199 self.meta = meta |
200 self.repo = repo | 200 self.ypath = os.path.join(meta.metapath, 'lastpulled') |
201 self.ypath = os.path.join(repo.path, 'svn', 'lastpulled') | |
202 # TODO(durin42): Consider moving management of the youngest | 201 # TODO(durin42): Consider moving management of the youngest |
203 # file to svnmeta itself rather than leaving it here. | 202 # file to svnmeta itself rather than leaving it here. |
204 # must load youngest file first, or else self._load() can | 203 # must load youngest file first, or else self._load() can |
205 # clobber the info | 204 # clobber the info |
206 self._youngest = util.load(self.ypath, 0) | 205 self._youngest = util.load(self.ypath, 0) |
207 self.oldest = 0 | 206 self.oldest = 0 |
208 if os.path.isfile(self.path): | 207 |
208 if os.path.isfile(self.meta.revmap_file): | |
209 self._load() | 209 self._load() |
210 else: | 210 else: |
211 self._write() | 211 self._write() |
212 | 212 |
213 def _set_youngest(self, rev): | 213 def _set_youngest(self, rev): |
223 return dict((v, k) for (k, v) in self.iteritems()) | 223 return dict((v, k) for (k, v) in self.iteritems()) |
224 | 224 |
225 def branchedits(self, branch, rev): | 225 def branchedits(self, branch, rev): |
226 check = lambda x: x[0][1] == branch and x[0][0] < rev.revnum | 226 check = lambda x: x[0][1] == branch and x[0][0] < rev.revnum |
227 return sorted(filter(check, self.iteritems()), reverse=True) | 227 return sorted(filter(check, self.iteritems()), reverse=True) |
228 | |
229 @staticmethod | |
230 def mappath(repo): | |
231 return os.path.join(repo.path, 'svn', 'rev_map') | |
232 | 228 |
233 @classmethod | 229 @classmethod |
234 def readmapfile(cls, path, missingok=True): | 230 def readmapfile(cls, path, missingok=True): |
235 try: | 231 try: |
236 f = open(path) | 232 f = open(path) |
242 if ver != cls.VERSION: | 238 if ver != cls.VERSION: |
243 raise hgutil.Abort('revmap too new -- please upgrade') | 239 raise hgutil.Abort('revmap too new -- please upgrade') |
244 return f | 240 return f |
245 | 241 |
246 def _load(self): | 242 def _load(self): |
247 for l in self.readmapfile(self.path): | 243 for l in self.readmapfile(self.meta.revmap_file): |
248 revnum, ha, branch = l.split(' ', 2) | 244 revnum, ha, branch = l.split(' ', 2) |
249 if branch == '\n': | 245 if branch == '\n': |
250 branch = None | 246 branch = None |
251 else: | 247 else: |
252 branch = branch[:-1] | 248 branch = branch[:-1] |
256 if revnum < self.oldest or not self.oldest: | 252 if revnum < self.oldest or not self.oldest: |
257 self.oldest = revnum | 253 self.oldest = revnum |
258 dict.__setitem__(self, (revnum, branch), node.bin(ha)) | 254 dict.__setitem__(self, (revnum, branch), node.bin(ha)) |
259 | 255 |
260 def _write(self): | 256 def _write(self): |
261 f = open(self.path, 'w') | 257 f = open(self.meta.revmap_file, 'w') |
262 f.write('%s\n' % self.VERSION) | 258 f.write('%s\n' % self.VERSION) |
263 f.close() | 259 f.close() |
264 | 260 |
265 def __setitem__(self, key, ha): | 261 def __setitem__(self, key, ha): |
266 revnum, branch = key | 262 revnum, branch = key |
267 f = open(self.path, 'a') | 263 f = open(self.meta.revmap_file, 'a') |
268 b = branch or '' | 264 b = branch or '' |
269 f.write(str(revnum) + ' ' + node.hex(ha) + ' ' + b + '\n') | 265 f.write(str(revnum) + ' ' + node.hex(ha) + ' ' + b + '\n') |
270 f.close() | 266 f.close() |
271 if revnum > self.youngest or not self.youngest: | 267 if revnum > self.youngest or not self.youngest: |
272 self.youngest = revnum | 268 self.youngest = revnum |