branch: avoid using reserved tag names
Reported as Debian bug #552423.
--- 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