Mercurial > hgsubversion
comparison hgsubversion/maps.py @ 448:fbc7cf4fd701
tags: reinstate a tag map file in a better way
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Tue, 23 Jun 2009 21:33:40 -0500 |
parents | 2851b81c65ce |
children | bb612e625be6 |
comparison
equal
deleted
inserted
replaced
447:0d3b5acb1d51 | 448:fbc7cf4fd701 |
---|---|
91 if author == hgauthor: | 91 if author == hgauthor: |
92 return svnauthor | 92 return svnauthor |
93 else: | 93 else: |
94 # Mercurial incorrectly splits at e.g. '.', so we roll our own. | 94 # Mercurial incorrectly splits at e.g. '.', so we roll our own. |
95 return author.rsplit('@', 1)[0] | 95 return author.rsplit('@', 1)[0] |
96 | |
97 | |
98 class TagMap(dict): | |
99 | |
100 VERSION = 1 | |
101 | |
102 def __init__(self, repo): | |
103 dict.__init__(self) | |
104 self.path = os.path.join(repo.path, 'svn', 'tagmap') | |
105 self.seen = 0 | |
106 if os.path.isfile(self.path): | |
107 self._load() | |
108 else: | |
109 self._write() | |
110 | |
111 def _load(self): | |
112 f = open(self.path) | |
113 ver = int(f.readline()) | |
114 if ver != self.VERSION: | |
115 print 'tagmap too new -- please upgrade' | |
116 raise NotImplementedError | |
117 for l in f: | |
118 hash, tag = l.split(' ', 1) | |
119 tag = tag[:-1] | |
120 dict.__setitem__(self, tag, node.bin(hash)) | |
121 f.close() | |
122 | |
123 def _write(self): | |
124 f = open(self.path, 'w') | |
125 f.write('%s\n' % self.VERSION) | |
126 f.flush() | |
127 f.close() | |
128 | |
129 def update(self, other): | |
130 for k,v in other.iteritems(): | |
131 self[k] = v | |
132 | |
133 def __contains__(self, tag): | |
134 return dict.__contains__(self, tag) and dict.__getitem__(self, tag) != node.nullid | |
135 | |
136 def __getitem__(self, tag): | |
137 if tag in self: | |
138 return dict.__getitem__(self, tag) | |
139 raise KeyError() | |
140 | |
141 def __setitem__(self, tag, hash): | |
142 f = open(self.path, 'a') | |
143 f.write(node.hex(hash) + ' ' + tag + '\n') | |
144 f.flush() | |
145 f.close() | |
146 dict.__setitem__(self, tag, hash) | |
96 | 147 |
97 | 148 |
98 class RevMap(dict): | 149 class RevMap(dict): |
99 | 150 |
100 VERSION = 1 | 151 VERSION = 1 |