[PATCH] Break core of repo.tag into dirstate/hook-free repo._tag for convert-repo

Brendan Cully brendan at kublai.com
Tue Feb 27 06:55:15 UTC 2007


# HG changeset patch
# User Brendan Cully <brendan at kublai.com>
# Date 1172559269 28800
# Node ID d4ea576053579f65009b5f33b9ad8e2988a5c52d
# Parent  b53c6f7dbb1f49767217c0ddf1e838e6c651ceea
Break core of repo.tag into dirstate/hook-free repo._tag for convert-repo

diff -r b53c6f7dbb1f -r d4ea57605357 mercurial/localrepo.py
--- a/mercurial/localrepo.py	Wed Feb 21 00:38:06 2007 +0100
+++ b/mercurial/localrepo.py	Mon Feb 26 22:54:29 2007 -0800
@@ -217,6 +217,33 @@ class localrepository(repo.repository):
 
     tag_disallowed = ':\r\n'
 
+    def _checktag(self, name):
+        for c in self.tag_disallowed:
+            if c in name:
+                raise util.Abort(_('%r cannot be used in a tag name') % c)
+        
+    def _tag(self, name, node, message, local, user, date, parent=None):
+        use_dirstate = parent is None
+
+        self._checktag(name)
+
+        if local:
+            # local tags are stored in the current charset
+            self.opener('localtags', 'a').write('%s %s\n' % (hex(node), name))
+            return
+
+        # committed tags are stored in UTF-8
+        line = '%s %s\n' % (hex(node), util.fromlocal(name))
+        if use_dirstate:
+            self.wfile('.hgtags', 'ab').write(line)
+        else:
+            ntags = self.filectx('.hgtags', parent).data()
+            self.wfile('.hgtags', 'ab').write(ntags + line)
+        if use_dirstate and self.dirstate.state('.hgtags') == '?':
+            self.add(['.hgtags'])
+
+        return self.commit(['.hgtags'], message, user, date, p1=parent)
+
     def tag(self, name, node, message, local, user, date):
         '''tag a revision with a symbolic name.
 
@@ -235,30 +262,17 @@ class localrepository(repo.repository):
 
         date: date tuple to use if committing'''
 
-        for c in self.tag_disallowed:
-            if c in name:
-                raise util.Abort(_('%r cannot be used in a tag name') % c)
-
-        self.hook('pretag', throw=True, node=hex(node), tag=name, local=local)
-
-        if local:
-            # local tags are stored in the current charset
-            self.opener('localtags', 'a').write('%s %s\n' % (hex(node), name))
-            self.hook('tag', node=hex(node), tag=name, local=local)
-            return
+        self._checktag(name)
 
         for x in self.status()[:5]:
             if '.hgtags' in x:
                 raise util.Abort(_('working copy of .hgtags is changed '
                                    '(please commit .hgtags manually)'))
 
-        # committed tags are stored in UTF-8
-        line = '%s %s\n' % (hex(node), util.fromlocal(name))
-        self.wfile('.hgtags', 'ab').write(line)
-        if self.dirstate.state('.hgtags') == '?':
-            self.add(['.hgtags'])
-
-        self.commit(['.hgtags'], message, user, date)
+        self.hook('pretag', throw=True, node=hex(node), tag=name, local=local)
+
+        self._tag(name, node, message, local, user, date)
+
         self.hook('tag', node=hex(node), tag=name, local=local)
 
     def tags(self):



More information about the Mercurial-devel mailing list