comparison hgsubversion/maps.py @ 1384:2d1d05e6e46c

maps: add a load method to base map Since all three map classes (authors, tags, branches) have the exact same logic for their load method, we add a generic one to base map so that each one can use it.
author Sean Farley <sean.michael.farley@gmail.com>
date Mon, 24 Mar 2014 11:20:58 -0500
parents 73c76f99ca08
children 9139d9295a36
comparison
equal deleted inserted replaced
1383:73c76f99ca08 1384:2d1d05e6e46c
25 25
26 # append mappings specified from the commandline 26 # append mappings specified from the commandline
27 clmap = util.configpath(self.meta.ui, self.mapname) 27 clmap = util.configpath(self.meta.ui, self.mapname)
28 if clmap: 28 if clmap:
29 self.load(clmap) 29 self.load(clmap)
30
31 def load(self, path):
32 '''Load mappings from a file at the specified path.'''
33 path = os.path.expandvars(path)
34 if not os.path.exists(path):
35 return
36
37 writing = False
38 mapfile = self.meta.__getattribute__(self.mapfilename)
39 if path != mapfile:
40 writing = open(mapfile, 'a')
41
42 self.meta.ui.debug('reading %s from %s\n' % (self.mapname , path))
43 f = open(path, 'r')
44 for number, line in enumerate(f):
45
46 if writing:
47 writing.write(line)
48
49 line = line.split('#')[0]
50 if not line.strip():
51 continue
52
53 try:
54 src, dst = line.split('=', 1)
55 except (IndexError, ValueError):
56 msg = 'ignoring line %i in %s %s: %s\n'
57 self.meta.ui.status(msg % (number, self.mapname, path,
58 line.rstrip()))
59 continue
60
61 src = src.strip()
62 dst = dst.strip()
63
64 if src not in self:
65 self.meta.ui.debug('adding %s to %s\n' % (src, self.mapname))
66 elif dst != self[src]:
67 msg = 'overriding %s: "%s" to "%s" (%s)\n'
68 self.meta.ui.status(msg % (self.mapname, self[src], dst, src))
69 self[src] = dst
70
71 f.close()
72 if writing:
73 writing.close()
30 74
31 class AuthorMap(dict): 75 class AuthorMap(dict):
32 '''A mapping from Subversion-style authors to Mercurial-style 76 '''A mapping from Subversion-style authors to Mercurial-style
33 authors, and back. The data is stored persistently on disk. 77 authors, and back. The data is stored persistently on disk.
34 78