[PATCH] Issue916: tag ought to work sanely even when there is no checkout
Jesse Glick
Jesse.Glick at Sun.COM
Tue Apr 1 21:53:22 UTC 2008
# HG changeset patch
# User Jesse Glick <jesse.glick at sun.com>
# Date 1207086619 14400
# Node ID e3535a8101336b22919011408dc74ac5eddc65b0
# Parent ee5313bc3c0c6d4c4963f01aeb1bfc639d91367b
Issue916: tag ought to work sanely even when there is no checkout.
Commit the tag changeset as a child of tip.
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -124,10 +124,7 @@
tag_disallowed = ':\r\n'
- def _tag(self, names, node, message, local, user, date, parent=None,
- extra={}):
- use_dirstate = parent is None
-
+ def _tag(self, names, node, message, local, user, date):
if isinstance(names, str):
allchars = names
names = (names,)
@@ -164,7 +161,8 @@
self.hook('tag', node=hex(node), tag=name, local=local)
return
- if use_dirstate:
+ parent = None
+ if self.dirstate.parents()[0] != nullid:
try:
fp = self.wfile('.hgtags', 'rb+')
except IOError, err:
@@ -172,6 +170,7 @@
else:
prevtags = fp.read()
else:
+ parent = self.changelog.tip()
try:
prevtags = self.filectx('.hgtags', parent).data()
except revlog.LookupError:
@@ -183,11 +182,13 @@
# committed tags are stored in UTF-8
writetags(fp, names, util.fromlocal, prevtags)
- if use_dirstate and '.hgtags' not in self.dirstate:
+ if '.hgtags' not in self.dirstate:
self.add(['.hgtags'])
- tagnode = self.commit(['.hgtags'], message, user, date, p1=parent,
- extra=extra)
+ tagnode = self.commit(['.hgtags'], message, user, date, p1=parent)
+
+ if parent:
+ self.remove(['.hgtags'], True)
for name in names:
self.hook('tag', node=hex(node), tag=name, local=local)
diff --git a/tests/test-tag b/tests/test-tag
--- a/tests/test-tag
+++ b/tests/test-tag
@@ -55,3 +55,13 @@
cat .hgtags
hg tag -d '1000000 0' newline
cat .hgtags
+
+echo % issue 916
+rm -f .hgtags.orig
+hg status
+hg up null
+hg tag -d "1000000 0" whatever
+hg log -l2 -p
+hg status
+hg tag -d "1000000 0" whatnow
+hg tip -p
diff --git a/tests/test-tag.out b/tests/test-tag.out
--- a/tests/test-tag.out
+++ b/tests/test-tag.out
@@ -49,3 +49,49 @@
f68b039e72eacbb2e68b0543e1f6e50990aa2bb5 localnewline
0acdaf8983679e0aac16e811534eb49d7ee1f2b4 foobar0acdaf8983679e0aac16e811534eb49d7ee1f2b4 foobar
6ae703d793c8b1f097116869275ecd97b2977a2b newline
+% issue 916
+0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+changeset: 9:e437e41a85a0
+tag: tip
+user: test
+date: Mon Jan 12 13:46:40 1970 +0000
+summary: Added tag whatever for changeset aaa789ea5279
+
+diff -r aaa789ea5279 -r e437e41a85a0 .hgtags
+--- a/.hgtags Mon Jan 12 13:46:40 1970 +0000
++++ b/.hgtags Mon Jan 12 13:46:40 1970 +0000
+@@ -1,2 +1,3 @@
+ 0acdaf8983679e0aac16e811534eb49d7ee1f2b4 foobar
+ 6ae703d793c8b1f097116869275ecd97b2977a2b newline
++aaa789ea52799f74c0081926959c67705ece6d43 whatever
+
+changeset: 8:aaa789ea5279
+tag: whatever
+user: test
+date: Mon Jan 12 13:46:40 1970 +0000
+summary: Added tag newline for changeset 6ae703d793c8
+
+diff -r 6ae703d793c8 -r aaa789ea5279 .hgtags
+--- a/.hgtags Mon Jan 12 13:46:40 1970 +0000
++++ b/.hgtags Mon Jan 12 13:46:40 1970 +0000
+@@ -1,1 +1,2 @@
+-0acdaf8983679e0aac16e811534eb49d7ee1f2b4 foobar
+\ No newline at end of file
++0acdaf8983679e0aac16e811534eb49d7ee1f2b4 foobar
++6ae703d793c8b1f097116869275ecd97b2977a2b newline
+
+changeset: 10:5ee24b637121
+tag: tip
+user: test
+date: Mon Jan 12 13:46:40 1970 +0000
+summary: Added tag whatnow for changeset e437e41a85a0
+
+diff -r e437e41a85a0 -r 5ee24b637121 .hgtags
+--- a/.hgtags Mon Jan 12 13:46:40 1970 +0000
++++ b/.hgtags Mon Jan 12 13:46:40 1970 +0000
+@@ -1,3 +1,4 @@
+ 0acdaf8983679e0aac16e811534eb49d7ee1f2b4 foobar
+ 6ae703d793c8b1f097116869275ecd97b2977a2b newline
+ aaa789ea52799f74c0081926959c67705ece6d43 whatever
++e437e41a85a08e4107bf352e1230ac35aaaad7d6 whatnow
+
More information about the Mercurial-devel
mailing list