Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/localrepo.py @ 4889:d69b1fb111b9
tag: handle .hgtags and .hg/localtags with missing final newline (issue 601)
This also fixes an asymmetry bug in which we called the pretag hook if we
were going to create a local tag, but didn't call the tag hook afterwards.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Mon, 16 Jul 2007 20:15:03 -0700 |
parents | 192cd95c2ba8 |
children | 8535c1770dd3 6fd953d5faea |
comparison
equal
deleted
inserted
replaced
4888:2d545b98a7bc | 4889:d69b1fb111b9 |
---|---|
117 if c in name: | 117 if c in name: |
118 raise util.Abort(_('%r cannot be used in a tag name') % c) | 118 raise util.Abort(_('%r cannot be used in a tag name') % c) |
119 | 119 |
120 self.hook('pretag', throw=True, node=hex(node), tag=name, local=local) | 120 self.hook('pretag', throw=True, node=hex(node), tag=name, local=local) |
121 | 121 |
122 def writetag(fp, name, munge, prevtags): | |
123 if prevtags and prevtags[-1] != '\n': | |
124 fp.write('\n') | |
125 fp.write('%s %s\n' % (hex(node), munge and munge(name) or name)) | |
126 fp.close() | |
127 self.hook('tag', node=hex(node), tag=name, local=local) | |
128 | |
129 prevtags = '' | |
122 if local: | 130 if local: |
131 try: | |
132 fp = self.opener('localtags', 'r+') | |
133 except IOError, err: | |
134 fp = self.opener('localtags', 'a') | |
135 else: | |
136 prevtags = fp.read() | |
137 | |
123 # local tags are stored in the current charset | 138 # local tags are stored in the current charset |
124 self.opener('localtags', 'a').write('%s %s\n' % (hex(node), name)) | 139 writetag(fp, name, None, prevtags) |
125 self.hook('tag', node=hex(node), tag=name, local=local) | |
126 return | 140 return |
127 | 141 |
128 # committed tags are stored in UTF-8 | |
129 line = '%s %s\n' % (hex(node), util.fromlocal(name)) | |
130 if use_dirstate: | 142 if use_dirstate: |
131 self.wfile('.hgtags', 'ab').write(line) | 143 try: |
144 fp = self.wfile('.hgtags', 'rb+') | |
145 except IOError, err: | |
146 fp = self.wfile('.hgtags', 'ab') | |
147 else: | |
148 prevtags = fp.read() | |
132 else: | 149 else: |
133 try: | 150 try: |
134 ntags = self.filectx('.hgtags', parent).data() | 151 prevtags = self.filectx('.hgtags', parent).data() |
135 except revlog.LookupError: | 152 except revlog.LookupError: |
136 ntags = '' | 153 pass |
137 self.wfile('.hgtags', 'wb').write(ntags + line) | 154 fp = self.wfile('.hgtags', 'wb') |
155 | |
156 # committed tags are stored in UTF-8 | |
157 writetag(fp, name, util.fromlocal, prevtags) | |
158 | |
138 if use_dirstate and self.dirstate.state('.hgtags') == '?': | 159 if use_dirstate and self.dirstate.state('.hgtags') == '?': |
139 self.add(['.hgtags']) | 160 self.add(['.hgtags']) |
140 | 161 |
141 tagnode = self.commit(['.hgtags'], message, user, date, p1=parent, | 162 tagnode = self.commit(['.hgtags'], message, user, date, p1=parent, |
142 extra=extra) | 163 extra=extra) |