comparison mercurial/localrepo.py @ 1986:719cf07b076d

add checking for invalid entries in tag files safely parse the differents tag files, output warning when parsing an invalid entry.
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Wed, 22 Mar 2006 05:30:47 +0100
parents ae12a81549a7
children 2da2d46862fb
comparison
equal deleted inserted replaced
1985:c577689006fa 1986:719cf07b076d
76 76
77 def tags(self): 77 def tags(self):
78 '''return a mapping of tag to node''' 78 '''return a mapping of tag to node'''
79 if not self.tagscache: 79 if not self.tagscache:
80 self.tagscache = {} 80 self.tagscache = {}
81 def addtag(self, k, n): 81
82 def parsetag(line, context):
83 if not line:
84 return
85 s = l.split(" ", 1)
86 if len(s) != 2:
87 self.ui.warn(_("%s: ignoring invalid tag\n") % context)
88 return
89 node, key = s
82 try: 90 try:
83 bin_n = bin(n) 91 bin_n = bin(node)
84 except TypeError: 92 except TypeError:
85 bin_n = '' 93 self.ui.warn(_("%s: ignoring invalid tag\n") % context)
86 self.tagscache[k.strip()] = bin_n 94 return
87 95 if bin_n not in self.changelog.nodemap:
88 try: 96 self.ui.warn(_("%s: ignoring invalid tag\n") % context)
89 # read each head of the tags file, ending with the tip 97 return
90 # and add each tag found to the map, with "newer" ones 98 self.tagscache[key.strip()] = bin_n
91 # taking precedence 99
92 fl = self.file(".hgtags") 100 # read each head of the tags file, ending with the tip
93 h = fl.heads() 101 # and add each tag found to the map, with "newer" ones
94 h.reverse() 102 # taking precedence
95 for r in h: 103 fl = self.file(".hgtags")
96 for l in fl.read(r).splitlines(): 104 h = fl.heads()
97 if l: 105 h.reverse()
98 n, k = l.split(" ", 1) 106 for r in h:
99 addtag(self, k, n) 107 count = 0
100 except KeyError: 108 for l in fl.read(r).splitlines():
101 pass 109 count += 1
110 parsetag(l, ".hgtags:%d" % count)
102 111
103 try: 112 try:
104 f = self.opener("localtags") 113 f = self.opener("localtags")
114 count = 0
105 for l in f: 115 for l in f:
106 n, k = l.split(" ", 1) 116 count += 1
107 addtag(self, k, n) 117 parsetag(l, "localtags:%d" % count)
108 except IOError: 118 except IOError:
109 pass 119 pass
110 120
111 self.tagscache['tip'] = self.changelog.tip() 121 self.tagscache['tip'] = self.changelog.tip()
112 122