narrow: widden the lock context in `tracking`
The tracking configuration we modify must be read under lock. So we grab the
lock sooner.
--- 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