Mercurial > hgsubversion
comparison hgsubversion/maps.py @ 846:7ca3d1b08d67
Save filemap into .hg/svn/filemap just like other maps
author | Vitaliy Filippov <vitalif@yourcmc.ru> |
---|---|
date | Fri, 20 Jan 2012 19:06:32 +0400 |
parents | 5061640fe5bc |
children | 0de18c5c2e35 |
comparison
equal
deleted
inserted
replaced
845:8cf8ff0f52fe | 846:7ca3d1b08d67 |
---|---|
19 '''Initialise a new AuthorMap. | 19 '''Initialise a new AuthorMap. |
20 | 20 |
21 The ui argument is used to print diagnostic messages. | 21 The ui argument is used to print diagnostic messages. |
22 | 22 |
23 The path argument is the location of the backing store, | 23 The path argument is the location of the backing store, |
24 typically .hg/authormap. | 24 typically .hg/svn/authors. |
25 ''' | 25 ''' |
26 self.ui = ui | 26 self.ui = ui |
27 self.path = path | 27 self.path = path |
28 if defaulthost: | 28 if defaulthost: |
29 self.defaulthost = '@%s' % defaulthost.lstrip('@') | 29 self.defaulthost = '@%s' % defaulthost.lstrip('@') |
250 dict.__setitem__(self, (revnum, branch), ha) | 250 dict.__setitem__(self, (revnum, branch), ha) |
251 | 251 |
252 | 252 |
253 class FileMap(object): | 253 class FileMap(object): |
254 | 254 |
255 def __init__(self, repo): | 255 VERSION = 1 |
256 self.ui = repo.ui | 256 |
257 def __init__(self, ui, path): | |
258 '''Initialise a new FileMap. | |
259 | |
260 The ui argument is used to print diagnostic messages. | |
261 | |
262 The path argument is the location of the backing store, | |
263 typically .hg/svn/filemap. | |
264 ''' | |
265 self.ui = ui | |
266 self.path = path | |
257 self.include = {} | 267 self.include = {} |
258 self.exclude = {} | 268 self.exclude = {} |
259 filemap = repo.ui.config('hgsubversion', 'filemap') | 269 if os.path.isfile(self.path): |
260 if filemap and os.path.exists(filemap): | 270 self._load() |
261 self.load(filemap) | 271 else: |
272 self._write() | |
262 | 273 |
263 def _rpairs(self, name): | 274 def _rpairs(self, name): |
264 yield '.', name | 275 yield '.', name |
265 e = len(name) | 276 e = len(name) |
266 while e != -1: | 277 while e != -1: |
299 self.ui.status(msg % (m, fn, path)) | 310 self.ui.status(msg % (m, fn, path)) |
300 return | 311 return |
301 bits = m.strip('e'), path | 312 bits = m.strip('e'), path |
302 self.ui.debug('%sing %s\n' % bits) | 313 self.ui.debug('%sing %s\n' % bits) |
303 mapping[path] = path | 314 mapping[path] = path |
315 if fn != self.path: | |
316 f = open(self.path, 'a') | |
317 f.write(m + ' ' + path + '\n') | |
318 f.close() | |
304 | 319 |
305 def load(self, fn): | 320 def load(self, fn): |
306 self.ui.note('reading file map from %s\n' % fn) | 321 self.ui.note('reading file map from %s\n' % fn) |
307 f = open(fn, 'r') | 322 f = open(fn, 'r') |
323 self.load_fd(f, fn) | |
324 f.close() | |
325 | |
326 def load_fd(self, f, fn): | |
308 for line in f: | 327 for line in f: |
309 if line.strip() == '' or line.strip()[0] == '#': | 328 if line.strip() == '' or line.strip()[0] == '#': |
310 continue | 329 continue |
311 try: | 330 try: |
312 cmd, path = line.split(' ', 1) | 331 cmd, path = line.split(' ', 1) |
317 continue | 336 continue |
318 self.ui.warn('unknown filemap command %s\n' % cmd) | 337 self.ui.warn('unknown filemap command %s\n' % cmd) |
319 except IndexError: | 338 except IndexError: |
320 msg = 'ignoring bad line in filemap %s: %s\n' | 339 msg = 'ignoring bad line in filemap %s: %s\n' |
321 self.ui.warn(msg % (fn, line.rstrip())) | 340 self.ui.warn(msg % (fn, line.rstrip())) |
341 | |
342 def _load(self): | |
343 self.ui.note('reading in-repo file map from %s\n' % self.path) | |
344 f = open(self.path) | |
345 ver = int(f.readline()) | |
346 if ver != self.VERSION: | |
347 print 'filemap too new -- please upgrade' | |
348 raise NotImplementedError | |
349 self.load_fd(f, self.path) | |
350 f.close() | |
351 | |
352 def _write(self): | |
353 f = open(self.path, 'w') | |
354 f.write('%s\n' % self.VERSION) | |
322 f.close() | 355 f.close() |
323 | 356 |
324 class BranchMap(dict): | 357 class BranchMap(dict): |
325 '''Facility for controlled renaming of branch names. Example: | 358 '''Facility for controlled renaming of branch names. Example: |
326 | 359 |