--- a/mercurial/commands.py Tue Mar 13 15:47:55 2007 -0500
+++ b/mercurial/commands.py Tue Mar 13 18:50:02 2007 -0500
@@ -255,12 +255,10 @@
current branch name.
"""
- if label is not None:
- repo.opener("branch", "w").write(util.fromlocal(label) + '\n')
+ if label:
+ repo.dirstate.setbranch(util.fromlocal(label))
else:
- b = util.tolocal(repo.workingctx().branch())
- if b:
- ui.write("%s\n" % b)
+ ui.write("%s\n" % util.tolocal(repo.dirstate.branch()))
def branches(ui, repo):
"""list repository named branches
--- a/mercurial/context.py Tue Mar 13 15:47:55 2007 -0500
+++ b/mercurial/context.py Tue Mar 13 18:50:02 2007 -0500
@@ -411,11 +411,7 @@
def deleted(self): return self._status[3]
def unknown(self): return self._status[4]
def clean(self): return self._status[5]
- def branch(self):
- try:
- return self._repo.opener("branch").read().strip() or "default"
- except IOError:
- return "default"
+ def branch(self): return self._repo.dirstate.branch()
def parents(self):
"""return contexts for each parent changeset"""
--- a/mercurial/dirstate.py Tue Mar 13 15:47:55 2007 -0500
+++ b/mercurial/dirstate.py Tue Mar 13 18:50:02 2007 -0500
@@ -25,6 +25,7 @@
self.dirs = None
self.copymap = {}
self.ignorefunc = None
+ self._branch = None
def wjoin(self, f):
return os.path.join(self.root, f)
@@ -137,6 +138,15 @@
self.lazyread()
return self.pl
+ def branch(self):
+ if not self._branch:
+ try:
+ self._branch = self.opener("branch").read().strip()\
+ or "default"
+ except IOError:
+ self._branch = "default"
+ return self._branch
+
def markdirty(self):
if not self.dirty:
self.dirty = 1
@@ -146,6 +156,10 @@
self.markdirty()
self.pl = p1, p2
+ def setbranch(self, branch):
+ self._branch = branch
+ self.opener("branch", "w").write(branch + '\n')
+
def state(self, key):
try:
return self[key][0]
--- a/mercurial/merge.py Tue Mar 13 15:47:55 2007 -0500
+++ b/mercurial/merge.py Tue Mar 13 18:50:02 2007 -0500
@@ -488,9 +488,9 @@
if not partial:
recordupdates(repo, action, branchmerge)
repo.dirstate.setparents(fp1, fp2)
+ if not branchmerge:
+ repo.dirstate.setbranch(p2.branch())
repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3])
- if not branchmerge:
- repo.opener("branch", "w").write(p2.branch() + "\n")
return stats
--- a/tests/test-newbranch Tue Mar 13 15:47:55 2007 -0500
+++ b/tests/test-newbranch Tue Mar 13 18:50:02 2007 -0500
@@ -12,7 +12,7 @@
hg ci -m "add branch name" -d "1000000 0"
hg branch bar
hg ci -m "change branch name" -d "1000000 0"
-hg branch ""
+hg branch default
hg ci -m "clear branch name" -d "1000000 0"
hg co foo