Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/localrepo.py @ 2320:dbdce3b99988
fix parsing of tags. make parse errors useful. add new tag tests.
old code read every head of .hgtags. delete and recreate of .hgtags gave
new head, but if error in deleted rev, .hgtags had error messages every
time it was parsed. this was very hard to fix, because deleted revs hard
to get back and update, needed merges too.
new code reads .hgtags on every head. advantage is if parse error
happens with new code, is possible to fix them by editing .hgtags on a
head and committing.
NOTE: new code uses binary search of manifest of each head to be fast,
but still much slower than old code. best thing would be to have delete
record stored in filelog so we never touch manifest. could find live
heads directly from filelog. this is more work than i want now.
new tests check for parse of tags on different heads, and inaccessible
heads created by delete and recreate of .hgtags.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Thu, 18 May 2006 23:31:12 -0700 |
parents | 7c2623aedeb4 |
children | f0680b2d1d64 4f7745fc9823 |
comparison
equal
deleted
inserted
replaced
2319:04a18aaaca25 | 2320:dbdce3b99988 |
---|---|
164 def parsetag(line, context): | 164 def parsetag(line, context): |
165 if not line: | 165 if not line: |
166 return | 166 return |
167 s = l.split(" ", 1) | 167 s = l.split(" ", 1) |
168 if len(s) != 2: | 168 if len(s) != 2: |
169 self.ui.warn(_("%s: ignoring invalid tag\n") % context) | 169 self.ui.warn(_("%s: cannot parse entry\n") % context) |
170 return | 170 return |
171 node, key = s | 171 node, key = s |
172 key = key.strip() | |
172 try: | 173 try: |
173 bin_n = bin(node) | 174 bin_n = bin(node) |
174 except TypeError: | 175 except TypeError: |
175 self.ui.warn(_("%s: ignoring invalid tag\n") % context) | 176 self.ui.warn(_("%s: node '%s' is not well formed\n") % |
177 (context, node)) | |
176 return | 178 return |
177 if bin_n not in self.changelog.nodemap: | 179 if bin_n not in self.changelog.nodemap: |
178 self.ui.warn(_("%s: ignoring invalid tag\n") % context) | 180 self.ui.warn(_("%s: tag '%s' refers to unknown node\n") % |
181 (context, key)) | |
179 return | 182 return |
180 self.tagscache[key.strip()] = bin_n | 183 self.tagscache[key] = bin_n |
181 | 184 |
182 # read each head of the tags file, ending with the tip | 185 # read the tags file from each head, ending with the tip, |
183 # and add each tag found to the map, with "newer" ones | 186 # and add each tag found to the map, with "newer" ones |
184 # taking precedence | 187 # taking precedence |
188 heads = self.heads() | |
189 heads.reverse() | |
185 fl = self.file(".hgtags") | 190 fl = self.file(".hgtags") |
186 h = fl.heads() | 191 for node in heads: |
187 h.reverse() | 192 change = self.changelog.read(node) |
188 for r in h: | 193 rev = self.changelog.rev(node) |
194 fn, ff = self.manifest.find(change[0], '.hgtags') | |
195 if fn is None: continue | |
189 count = 0 | 196 count = 0 |
190 for l in fl.read(r).splitlines(): | 197 for l in fl.read(fn).splitlines(): |
191 count += 1 | 198 count += 1 |
192 parsetag(l, ".hgtags:%d" % count) | 199 parsetag(l, _(".hgtags (rev %d:%s), line %d") % |
193 | 200 (rev, short(node), count)) |
194 try: | 201 try: |
195 f = self.opener("localtags") | 202 f = self.opener("localtags") |
196 count = 0 | 203 count = 0 |
197 for l in f: | 204 for l in f: |
198 count += 1 | 205 count += 1 |
199 parsetag(l, "localtags:%d" % count) | 206 parsetag(l, _("localtags, line %d") % count) |
200 except IOError: | 207 except IOError: |
201 pass | 208 pass |
202 | 209 |
203 self.tagscache['tip'] = self.changelog.tip() | 210 self.tagscache['tip'] = self.changelog.tip() |
204 | 211 |