mercurial/commands.py
changeset 4207 7e1c8a565a4f
parent 4204 f9bbcebcacea
child 4209 dbc3846c09a1
child 4217 3be4785f8994
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -255,12 +255,10 @@ def branch(ui, repo, label=None):
     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