resolve: keep wlock while resolving stable
authorMads Kiilerich <madski at unity3d.com>
Mon, 26 May 2014 19:02:11 +0200
branchstable
changeset 21709 14560418856d
parent 21708 2668a78df8ba
child 21720 db2392a4effc
child 21730 8da100383dc3
resolve: keep wlock while resolving This will make resolve use correct locking and thus make it more safe. Resolve is usually a long running command spending a lot of time waiting for user input on hard problems. It is thus a real world scenario to start multiple resolves at once or run other commands (such as up -C and merge) while resolve is running. Proper locking prevents that.
mercurial/commands.py
--- a/mercurial/commands.py	Thu Jun 05 16:47:14 2014 +0900
+++ b/mercurial/commands.py	Mon May 26 19:02:11 2014 +0200
@@ -4927,44 +4927,49 @@
         raise util.Abort(_('no files or directories specified; '
                            'use --all to remerge all files'))
 
-    ms = mergemod.mergestate(repo)
-    m = scmutil.match(repo[None], pats, opts)
-    ret = 0
-
-    for f in ms:
-        if m(f):
-            if show:
-                if nostatus:
-                    ui.write("%s\n" % f)
+    wlock = repo.wlock()
+    try:
+        ms = mergemod.mergestate(repo)
+        m = scmutil.match(repo[None], pats, opts)
+        ret = 0
+
+        for f in ms:
+            if m(f):
+                if show:
+                    if nostatus:
+                        ui.write("%s\n" % f)
+                    else:
+                        ui.write("%s %s\n" % (ms[f].upper(), f),
+                                 label='resolve.' +
+                                 {'u': 'unresolved', 'r': 'resolved'}[ms[f]])
+                elif mark:
+                    ms.mark(f, "r")
+                elif unmark:
+                    ms.mark(f, "u")
                 else:
-                    ui.write("%s %s\n" % (ms[f].upper(), f),
-                             label='resolve.' +
-                             {'u': 'unresolved', 'r': 'resolved'}[ms[f]])
-            elif mark:
-                ms.mark(f, "r")
-            elif unmark:
-                ms.mark(f, "u")
-            else:
-                wctx = repo[None]
-
-                # backup pre-resolve (merge uses .orig for its own purposes)
-                a = repo.wjoin(f)
-                util.copyfile(a, a + ".resolve")
-
-                try:
-                    # resolve file
-                    ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
-                                 'resolve')
-                    if ms.resolve(f, wctx):
-                        ret = 1
-                finally:
-                    ui.setconfig('ui', 'forcemerge', '', 'resolve')
-                    ms.commit()
-
-                # replace filemerge's .orig file with our resolve file
-                util.rename(a + ".resolve", a + ".orig")
-
-    ms.commit()
+                    wctx = repo[None]
+
+                    # backup pre-resolve (merge uses .orig for its own purposes)
+                    a = repo.wjoin(f)
+                    util.copyfile(a, a + ".resolve")
+
+                    try:
+                        # resolve file
+                        ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
+                                     'resolve')
+                        if ms.resolve(f, wctx):
+                            ret = 1
+                    finally:
+                        ui.setconfig('ui', 'forcemerge', '', 'resolve')
+                        ms.commit()
+
+                    # replace filemerge's .orig file with our resolve file
+                    util.rename(a + ".resolve", a + ".orig")
+
+        ms.commit()
+    finally:
+        wlock.release()
+
     return ret
 
 @command('revert',