commands: add missing wlock to branch stable
authorIdan Kamara <idankk86@gmail.com>
Thu, 19 Apr 2012 17:59:23 +0300
branchstable
changeset 16471 85c7602e283a
parent 16470 b2e1da5db6df
child 16472 14a4e17f0817
commands: add missing wlock to branch
mercurial/commands.py
--- a/mercurial/commands.py	Thu Apr 19 17:59:23 2012 +0300
+++ b/mercurial/commands.py	Thu Apr 19 17:59:23 2012 +0300
@@ -863,23 +863,29 @@
 
     Returns 0 on success.
     """
-
-    if opts.get('clean'):
-        label = repo[None].p1().branch()
-        repo.dirstate.setbranch(label)
-        ui.status(_('reset working directory to branch %s\n') % label)
-    elif label:
-        if not opts.get('force') and label in repo.branchtags():
-            if label not in [p.branch() for p in repo.parents()]:
-                raise util.Abort(_('a branch of the same name already exists'),
-                                 # i18n: "it" refers to an existing branch
-                                 hint=_("use 'hg update' to switch to it"))
-        repo.dirstate.setbranch(label)
-        ui.status(_('marked working directory as branch %s\n') % label)
-        ui.status(_('(branches are permanent and global, '
-                    'did you want a bookmark?)\n'))
-    else:
+    if not opts.get('clean') and not label:
         ui.write("%s\n" % repo.dirstate.branch())
+        return
+
+    wlock = repo.wlock()
+    try:
+        if opts.get('clean'):
+            label = repo[None].p1().branch()
+            repo.dirstate.setbranch(label)
+            ui.status(_('reset working directory to branch %s\n') % label)
+        elif label:
+            if not opts.get('force') and label in repo.branchtags():
+                if label not in [p.branch() for p in repo.parents()]:
+                    raise util.Abort(_('a branch of the same name already'
+                                       ' exists'),
+                                     # i18n: "it" refers to an existing branch
+                                     hint=_("use 'hg update' to switch to it"))
+            repo.dirstate.setbranch(label)
+            ui.status(_('marked working directory as branch %s\n') % label)
+            ui.status(_('(branches are permanent and global, '
+                        'did you want a bookmark?)\n'))
+    finally:
+        wlock.release()
 
 @command('branches',
     [('a', 'active', False, _('show only branches that have unmerged heads')),