mercurial/localrepo.py
changeset 2974 eef469259745
parent 2972 96d034d02d61
child 3016 aebc3f64b20f
equal deleted inserted replaced
2973:fb493241d7f6 2974:eef469259745
   167                 r = runhook(hname, cmd) or r
   167                 r = runhook(hname, cmd) or r
   168         return r
   168         return r
   169 
   169 
   170     tag_disallowed = ':\r\n'
   170     tag_disallowed = ':\r\n'
   171 
   171 
   172     def tag(self, name, node, local=False, message=None, user=None, date=None):
   172     def tag(self, name, node, message, local, user, date):
   173         '''tag a revision with a symbolic name.
   173         '''tag a revision with a symbolic name.
   174 
   174 
   175         if local is True, the tag is stored in a per-repository file.
   175         if local is True, the tag is stored in a per-repository file.
   176         otherwise, it is stored in the .hgtags file, and a new
   176         otherwise, it is stored in the .hgtags file, and a new
   177         changeset is committed with the change.
   177         changeset is committed with the change.
   189 
   189 
   190         for c in self.tag_disallowed:
   190         for c in self.tag_disallowed:
   191             if c in name:
   191             if c in name:
   192                 raise util.Abort(_('%r cannot be used in a tag name') % c)
   192                 raise util.Abort(_('%r cannot be used in a tag name') % c)
   193 
   193 
   194         self.hook('pretag', throw=True, node=node, tag=name, local=local)
   194         self.hook('pretag', throw=True, node=hex(node), tag=name, local=local)
   195 
   195 
   196         if local:
   196         if local:
   197             self.opener('localtags', 'a').write('%s %s\n' % (node, name))
   197             self.opener('localtags', 'a').write('%s %s\n' % (hex(node), name))
   198             self.hook('tag', node=node, tag=name, local=local)
   198             self.hook('tag', node=hex(node), tag=name, local=local)
   199             return
   199             return
   200 
   200 
   201         for x in self.status()[:5]:
   201         for x in self.status()[:5]:
   202             if '.hgtags' in x:
   202             if '.hgtags' in x:
   203                 raise util.Abort(_('working copy of .hgtags is changed '
   203                 raise util.Abort(_('working copy of .hgtags is changed '
   204                                    '(please commit .hgtags manually)'))
   204                                    '(please commit .hgtags manually)'))
   205 
   205 
   206         self.wfile('.hgtags', 'ab').write('%s %s\n' % (node, name))
   206         self.wfile('.hgtags', 'ab').write('%s %s\n' % (hex(node), name))
   207         if self.dirstate.state('.hgtags') == '?':
   207         if self.dirstate.state('.hgtags') == '?':
   208             self.add(['.hgtags'])
   208             self.add(['.hgtags'])
   209 
   209 
   210         if not message:
       
   211             message = _('Added tag %s for changeset %s') % (name, node)
       
   212 
       
   213         self.commit(['.hgtags'], message, user, date)
   210         self.commit(['.hgtags'], message, user, date)
   214         self.hook('tag', node=node, tag=name, local=local)
   211         self.hook('tag', node=hex(node), tag=name, local=local)
   215 
   212 
   216     def tags(self):
   213     def tags(self):
   217         '''return a mapping of tag to node'''
   214         '''return a mapping of tag to node'''
   218         if not self.tagscache:
   215         if not self.tagscache:
   219             self.tagscache = {}
   216             self.tagscache = {}