[PATCH 2 of 4] commands: add missing wlock to branch

Idan Kamara idankk86 at gmail.com
Thu Apr 19 10:31:49 CDT 2012


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1334847563 -10800
# Branch stable
# Node ID fc93afd91fcae90e2dd20716f1039b4d54d37191
# Parent  e1bb6f88a73a34b8d9848fa9cd69895e388657b5
commands: add missing wlock to branch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -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')),


More information about the Mercurial-devel mailing list