changeset 50223:a6ca61fd1fa8

narrow: widden the lock context in `tracking` The tracking configuration we modify must be read under lock. So we grab the lock sooner.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 23 Feb 2023 00:12:53 +0100
parents c74d4ce646fb
children 99296ca9f29e
files hgext/narrow/narrowcommands.py
diffstat 1 files changed, 20 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- 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