diff mercurial/commands.py @ 35606:4b68ca118d8d

pull: hold wlock for the full operation when --update is used With now, the wlock is not held between the pull and the update. This can lead to race condition and make logic checking to post pull results more complicated (eg: with _afterlock).
author Boris Feld <boris.feld@octobus.net>
date Thu, 11 Jan 2018 11:57:59 +0000
parents dda3cae3c9c5
children a177c6aa055a
line wrap: on
line diff
--- a/mercurial/commands.py	Thu Jan 11 18:20:08 2018 +0800
+++ b/mercurial/commands.py	Thu Jan 11 11:57:59 2018 +0000
@@ -4007,36 +4007,40 @@
                         "so a rev cannot be specified.")
                 raise error.Abort(err)
 
-        pullopargs.update(opts.get('opargs', {}))
-        modheads = exchange.pull(repo, other, heads=revs,
-                                 force=opts.get('force'),
-                                 bookmarks=opts.get('bookmark', ()),
-                                 opargs=pullopargs).cgresult
-
-        # brev is a name, which might be a bookmark to be activated at
-        # the end of the update. In other words, it is an explicit
-        # destination of the update
-        brev = None
-
-        if checkout:
-            checkout = str(repo.changelog.rev(checkout))
-
-            # order below depends on implementation of
-            # hg.addbranchrevs(). opts['bookmark'] is ignored,
-            # because 'checkout' is determined without it.
-            if opts.get('rev'):
-                brev = opts['rev'][0]
-            elif opts.get('branch'):
-                brev = opts['branch'][0]
-            else:
-                brev = branches[0]
-        repo._subtoppath = source
-        try:
-            ret = postincoming(ui, repo, modheads, opts.get('update'),
-                               checkout, brev)
-
-        finally:
-            del repo._subtoppath
+        wlock = util.nullcontextmanager()
+        if opts.get('update'):
+            wlock = repo.wlock()
+        with wlock:
+            pullopargs.update(opts.get('opargs', {}))
+            modheads = exchange.pull(repo, other, heads=revs,
+                                     force=opts.get('force'),
+                                     bookmarks=opts.get('bookmark', ()),
+                                     opargs=pullopargs).cgresult
+
+            # brev is a name, which might be a bookmark to be activated at
+            # the end of the update. In other words, it is an explicit
+            # destination of the update
+            brev = None
+
+            if checkout:
+                checkout = str(repo.changelog.rev(checkout))
+
+                # order below depends on implementation of
+                # hg.addbranchrevs(). opts['bookmark'] is ignored,
+                # because 'checkout' is determined without it.
+                if opts.get('rev'):
+                    brev = opts['rev'][0]
+                elif opts.get('branch'):
+                    brev = opts['branch'][0]
+                else:
+                    brev = branches[0]
+            repo._subtoppath = source
+            try:
+                ret = postincoming(ui, repo, modheads, opts.get('update'),
+                                   checkout, brev)
+
+            finally:
+                del repo._subtoppath
 
     finally:
         other.close()