narrow: widden the lock context in `tracking`
authorPierre-Yves David <pierre-yves.david@octobus.net>
Thu, 23 Feb 2023 00:12:53 +0100
changeset 50184 a6ca61fd1fa8
parent 50183 c74d4ce646fb
child 50185 99296ca9f29e
narrow: widden the lock context in `tracking` The tracking configuration we modify must be read under lock. So we grab the lock sooner.
hgext/narrow/narrowcommands.py
--- a/hgext/narrow/narrowcommands.py	Thu Feb 23 03:49:29 2023 +0100
+++ b/hgext/narrow/narrowcommands.py	Thu Feb 23 00:12:53 2023 +0100
@@ -579,31 +579,31 @@
         fm.end()
         return 0
 
-    oldincludes, oldexcludes = repo.narrowpats
+    with repo.wlock(), repo.lock():
+        oldincludes, oldexcludes = repo.narrowpats
 
-    # filter the user passed additions and deletions into actual additions and
-    # deletions of excludes and includes
-    addedincludes -= oldincludes
-    removedincludes &= oldincludes
-    addedexcludes -= oldexcludes
-    removedexcludes &= oldexcludes
+        # filter the user passed additions and deletions into actual additions and
+        # deletions of excludes and includes
+        addedincludes -= oldincludes
+        removedincludes &= oldincludes
+        addedexcludes -= oldexcludes
+        removedexcludes &= oldexcludes
 
-    widening = addedincludes or removedexcludes
-    narrowing = removedincludes or addedexcludes
+        widening = addedincludes or removedexcludes
+        narrowing = removedincludes or addedexcludes
 
-    if update_working_copy:
-        with repo.wlock(), repo.lock(), repo.transaction(
-            b'narrow-wc'
-        ), repo.dirstate.changing_parents(repo):
-            narrowspec.updateworkingcopy(repo)
-            narrowspec.copytoworkingcopy(repo)
-        return 0
+        if update_working_copy:
+            with repo.transaction(b'narrow-wc'), repo.dirstate.changing_parents(
+                repo
+            ):
+                narrowspec.updateworkingcopy(repo)
+                narrowspec.copytoworkingcopy(repo)
+            return 0
 
-    if not (widening or narrowing or autoremoveincludes):
-        ui.status(_(b"nothing to widen or narrow\n"))
-        return 0
+        if not (widening or narrowing or autoremoveincludes):
+            ui.status(_(b"nothing to widen or narrow\n"))
+            return 0
 
-    with repo.wlock(), repo.lock():
         cmdutil.bailifchanged(repo)
 
         # Find the revisions we have in common with the remote. These will