changeset 10417:58e040c51231 stable

branch: avoid using reserved tag names Reported as Debian bug #552423.
author Wagner Bruna <wbruna@softwareexpress.com.br>
date Thu, 11 Feb 2010 12:02:48 -0200
parents b8801b58bbd8
children 41d0ed2c79df e553a425751d
files mercurial/changelog.py mercurial/dirstate.py tests/test-branches tests/test-branches.out
diffstat 4 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/changelog.py	Sun Feb 07 11:38:36 2010 +0100
+++ b/mercurial/changelog.py	Thu Feb 11 12:02:48 2010 -0200
@@ -218,8 +218,13 @@
             parseddate = "%d %d" % util.parsedate(date)
         else:
             parseddate = "%d %d" % util.makedate()
-        if extra and extra.get("branch") in ("default", ""):
-            del extra["branch"]
+        if extra:
+            branch = extra.get("branch")
+            if branch in ("default", ""):
+                del extra["branch"]
+            elif branch in (".", "null", "tip"):
+                raise error.RevlogError(_('the name \'%s\' is reserved')
+                                        % branch)
         if extra:
             extra = encodeextra(extra)
             parseddate = "%s %s" % (parseddate, extra)
--- a/mercurial/dirstate.py	Sun Feb 07 11:38:36 2010 +0100
+++ b/mercurial/dirstate.py	Thu Feb 11 12:02:48 2010 -0200
@@ -202,6 +202,8 @@
         self._pl = p1, p2
 
     def setbranch(self, branch):
+        if branch in ['tip', '.', 'null']:
+            raise util.Abort(_('the name \'%s\' is reserved') % branch)
         self._branch = branch
         self._opener("branch", "w").write(branch + '\n')
 
--- a/tests/test-branches	Sun Feb 07 11:38:36 2010 +0100
+++ b/tests/test-branches	Thu Feb 11 12:02:48 2010 -0200
@@ -36,6 +36,10 @@
 hg branch c
 hg commit -d '5 0' -m "Adding c branch"
 
+hg branch tip
+hg branch null
+hg branch .
+
 echo 'd' >d
 hg add d
 hg branch 'a branch name much longer than the default justification used by branches'
--- a/tests/test-branches.out	Sun Feb 07 11:38:36 2010 +0100
+++ b/tests/test-branches.out	Thu Feb 11 12:02:48 2010 -0200
@@ -6,6 +6,9 @@
 created new head
 1 files updated, 0 files merged, 2 files removed, 0 files unresolved
 marked working directory as branch c
+abort: the name 'tip' is reserved
+abort: the name 'null' is reserved
+abort: the name '.' is reserved
 marked working directory as branch a branch name much longer than the default justification used by branches
 a branch name much longer than the default justification used by branches 7:10ff5895aa57
 b                              4:aee39cd168d0