##// END OF EJS Templates
add checking for invalid entries in tag files...
Benoit Boissinot -
r1986:719cf07b default
parent child Browse files
Show More
@@ -78,33 +78,43 b' class localrepository(object):'
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):
82 try:
83 bin_n = bin(n)
84 except TypeError:
85 bin_n = ''
86 self.tagscache[k.strip()] = bin_n
87
81
88 try:
82 def parsetag(line, context):
89 # read each head of the tags file, ending with the tip
83 if not line:
90 # and add each tag found to the map, with "newer" ones
84 return
91 # taking precedence
85 s = l.split(" ", 1)
92 fl = self.file(".hgtags")
86 if len(s) != 2:
93 h = fl.heads()
87 self.ui.warn(_("%s: ignoring invalid tag\n") % context)
94 h.reverse()
88 return
95 for r in h:
89 node, key = s
96 for l in fl.read(r).splitlines():
90 try:
97 if l:
91 bin_n = bin(node)
98 n, k = l.split(" ", 1)
92 except TypeError:
99 addtag(self, k, n)
93 self.ui.warn(_("%s: ignoring invalid tag\n") % context)
100 except KeyError:
94 return
101 pass
95 if bin_n not in self.changelog.nodemap:
96 self.ui.warn(_("%s: ignoring invalid tag\n") % context)
97 return
98 self.tagscache[key.strip()] = bin_n
99
100 # read each head of the tags file, ending with the tip
101 # and add each tag found to the map, with "newer" ones
102 # taking precedence
103 fl = self.file(".hgtags")
104 h = fl.heads()
105 h.reverse()
106 for r in h:
107 count = 0
108 for l in fl.read(r).splitlines():
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
@@ -31,3 +31,13 b' hg co -m 1'
31 hg id
31 hg id
32 hg status
32 hg status
33
33
34 hg commit -m "merge" -d "1000000 0"
35 # invalid tags
36 echo "spam" >> .hgtags
37 echo >> .hgtags
38 echo "foo bar" >> .hgtags
39 echo "$T invalid" | sed "s/..../a5a5/" >> .hg/localtags
40 hg commit -m "tags" -d "1000000 0"
41 hg tags
42 hg tip
43
@@ -12,3 +12,17 b' M a'
12 8216907a933d tip
12 8216907a933d tip
13 8216907a933d+8a3ca90d111d+ tip
13 8216907a933d+8a3ca90d111d+ tip
14 M .hgtags
14 M .hgtags
15 .hgtags:2: ignoring invalid tag
16 .hgtags:4: ignoring invalid tag
17 localtags:1: ignoring invalid tag
18 tip 4:fd868a874787a7b5af31e1675666ce691c803035
19 first 0:0acdaf8983679e0aac16e811534eb49d7ee1f2b4
20 changeset: 4:fd868a874787
21 .hgtags:2: ignoring invalid tag
22 .hgtags:4: ignoring invalid tag
23 localtags:1: ignoring invalid tag
24 tag: tip
25 user: test
26 date: Mon Jan 12 13:46:40 1970 +0000
27 summary: tags
28
General Comments 0
You need to be logged in to leave comments. Login now