Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/localrepo.py @ 4932:f0c25ed40ec6
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 | 22fcd6444ad9 |
children | 8535c1770dd3 ea7b982b6c08 |
comparison
equal
deleted
inserted
replaced
4931:c4dd58af0fc8 | 4932:f0c25ed40ec6 |
---|---|
116 if c in name: | 116 if c in name: |
117 raise util.Abort(_('%r cannot be used in a tag name') % c) | 117 raise util.Abort(_('%r cannot be used in a tag name') % c) |
118 | 118 |
119 self.hook('pretag', throw=True, node=hex(node), tag=name, local=local) | 119 self.hook('pretag', throw=True, node=hex(node), tag=name, local=local) |
120 | 120 |
121 def writetag(fp, name, munge, prevtags): | |
122 if prevtags and prevtags[-1] != '\n': | |
123 fp.write('\n') | |
124 fp.write('%s %s\n' % (hex(node), munge and munge(name) or name)) | |
125 fp.close() | |
126 self.hook('tag', node=hex(node), tag=name, local=local) | |
127 | |
128 prevtags = '' | |
121 if local: | 129 if local: |
130 try: | |
131 fp = self.opener('localtags', 'r+') | |
132 except IOError, err: | |
133 fp = self.opener('localtags', 'a') | |
134 else: | |
135 prevtags = fp.read() | |
136 | |
122 # local tags are stored in the current charset | 137 # local tags are stored in the current charset |
123 self.opener('localtags', 'a').write('%s %s\n' % (hex(node), name)) | 138 writetag(fp, name, None, prevtags) |
124 self.hook('tag', node=hex(node), tag=name, local=local) | |
125 return | 139 return |
126 | 140 |
127 # committed tags are stored in UTF-8 | |
128 line = '%s %s\n' % (hex(node), util.fromlocal(name)) | |
129 if use_dirstate: | 141 if use_dirstate: |
130 self.wfile('.hgtags', 'ab').write(line) | 142 try: |
143 fp = self.wfile('.hgtags', 'rb+') | |
144 except IOError, err: | |
145 fp = self.wfile('.hgtags', 'ab') | |
146 else: | |
147 prevtags = fp.read() | |
131 else: | 148 else: |
132 try: | 149 try: |
133 ntags = self.filectx('.hgtags', parent).data() | 150 prevtags = self.filectx('.hgtags', parent).data() |
134 except revlog.LookupError: | 151 except revlog.LookupError: |
135 ntags = '' | 152 pass |
136 self.wfile('.hgtags', 'wb').write(ntags + line) | 153 fp = self.wfile('.hgtags', 'wb') |
154 | |
155 # committed tags are stored in UTF-8 | |
156 writetag(fp, name, util.fromlocal, prevtags) | |
157 | |
137 if use_dirstate and self.dirstate.state('.hgtags') == '?': | 158 if use_dirstate and self.dirstate.state('.hgtags') == '?': |
138 self.add(['.hgtags']) | 159 self.add(['.hgtags']) |
139 | 160 |
140 tagnode = self.commit(['.hgtags'], message, user, date, p1=parent) | 161 tagnode = self.commit(['.hgtags'], message, user, date, p1=parent) |
141 | 162 |