dirstate: rename parentchange to changing_parents
Since the new argument breaks the API anyway, we can rename it to a better name.
The previous name `parentchange` might be seen as something active, a function
that would directly change the parents, however this is just a context manager
to frame the operation that will change the parents and adjust the
dirstate content accordingly.
In addition, the future sister method that will be about changes to tracking and
files would have a hard time fitting in the same naming scheme in a clear way.
The new naming uses a clear prefix will make it more distinct from other
dirstate methods and easier to extend with other similar contexts.
--- a/hgext/absorb.py Wed Jan 25 18:46:20 2023 +0100
+++ b/hgext/absorb.py Wed Jan 25 19:12:31 2023 +0100
@@ -881,7 +881,7 @@
dirstate._fsmonitorstate.invalidate = noop
try:
- with dirstate.parentchange(self.repo):
+ with dirstate.changing_parents(self.repo):
dirstate.rebuild(ctx.node(), ctx.manifest(), self.paths)
finally:
restore()
--- a/hgext/fix.py Wed Jan 25 18:46:20 2023 +0100
+++ b/hgext/fix.py Wed Jan 25 19:12:31 2023 +0100
@@ -776,7 +776,7 @@
newp1 = replacements.get(oldp1, oldp1)
if newp1 != oldp1:
assert repo.dirstate.p2() == nullid
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
scmutil.movedirstate(repo, repo[newp1])
--- a/hgext/git/dirstate.py Wed Jan 25 18:46:20 2023 +0100
+++ b/hgext/git/dirstate.py Wed Jan 25 19:12:31 2023 +0100
@@ -384,7 +384,7 @@
pass
@contextlib.contextmanager
- def parentchange(self, repo):
+ def changing_parents(self, repo):
# TODO: track this maybe?
yield
--- a/hgext/keyword.py Wed Jan 25 18:46:20 2023 +0100
+++ b/hgext/keyword.py Wed Jan 25 19:12:31 2023 +0100
@@ -696,7 +696,7 @@
kwt = getattr(repo, '_keywordkwt', None)
if kwt is None:
return orig(ui, repo, old, extra, pats, opts)
- with repo.wlock(), repo.dirstate.parentchange(repo):
+ with repo.wlock(), repo.dirstate.changing_parents(repo):
kwt.postcommit = True
newid = orig(ui, repo, old, extra, pats, opts)
if newid != old.node():
@@ -762,7 +762,7 @@
if ctx != recctx:
modified, added = _preselect(wstatus, recctx.files())
kwt.restrict = False
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
kwt.overwrite(recctx, modified, False, True)
kwt.overwrite(recctx, added, False, True, True)
kwt.restrict = True
--- a/hgext/largefiles/lfcommands.py Wed Jan 25 18:46:20 2023 +0100
+++ b/hgext/largefiles/lfcommands.py Wed Jan 25 19:12:31 2023 +0100
@@ -517,7 +517,7 @@
filelist = set(filelist)
lfiles = [f for f in lfiles if f in filelist]
- with lfdirstate.parentchange(repo):
+ with lfdirstate.changing_parents(repo):
update = {}
dropped = set()
updated, removed = 0, 0
@@ -580,7 +580,7 @@
statuswriter(_(b'getting changed largefiles\n'))
cachelfiles(ui, repo, None, lfiles)
- with lfdirstate.parentchange(repo):
+ with lfdirstate.changing_parents(repo):
for lfile in lfiles:
update1 = 0
--- a/hgext/largefiles/lfutil.py Wed Jan 25 18:46:20 2023 +0100
+++ b/hgext/largefiles/lfutil.py Wed Jan 25 19:12:31 2023 +0100
@@ -231,7 +231,7 @@
if len(standins) > 0:
vfs.makedirs(lfstoredir)
- with lfdirstate.parentchange(repo):
+ with lfdirstate.changing_parents(repo):
for standin in standins:
lfile = splitstandin(standin)
lfdirstate.update_file(
@@ -581,7 +581,7 @@
repo = ctx.repo()
lfdirstate = openlfdirstate(repo.ui, repo)
- with lfdirstate.parentchange(repo):
+ with lfdirstate.changing_parents(repo):
orig(node)
# ATTENTION: "ctx.files()" may differ from "repo[node].files()"
--- a/hgext/largefiles/overrides.py Wed Jan 25 18:46:20 2023 +0100
+++ b/hgext/largefiles/overrides.py Wed Jan 25 19:12:31 2023 +0100
@@ -660,7 +660,7 @@
def mergerecordupdates(orig, repo, actions, branchmerge, getfiledata):
if MERGE_ACTION_LARGEFILE_MARK_REMOVED in actions:
lfdirstate = lfutil.openlfdirstate(repo.ui, repo)
- with lfdirstate.parentchange(repo):
+ with lfdirstate.changing_parents(repo):
for lfile, args, msg in actions[
MERGE_ACTION_LARGEFILE_MARK_REMOVED
]:
@@ -1800,7 +1800,7 @@
raise error.ProgrammingError(
b'largefiles is not compatible with in-memory merge'
)
- with lfdirstate.parentchange(repo):
+ with lfdirstate.changing_parents(repo):
result = orig(repo, node, branchmerge, force, *args, **kwargs)
newstandins = lfutil.getstandinsstate(repo)
--- a/hgext/mq.py Wed Jan 25 18:46:20 2023 +0100
+++ b/hgext/mq.py Wed Jan 25 19:12:31 2023 +0100
@@ -1082,7 +1082,7 @@
if merge and files:
# Mark as removed/merged and update dirstate parent info
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
for f in files:
repo.dirstate.update_file_p1(f, p1_tracked=True)
p1 = repo.dirstate.p1()
@@ -1830,7 +1830,7 @@
if keepchanges and tobackup:
raise error.Abort(_(b"local changes found, qrefresh first"))
self.backup(repo, tobackup)
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
for f in a:
repo.wvfs.unlinkpath(f, ignoremissing=True)
repo.dirstate.update_file(
@@ -1988,7 +1988,7 @@
bmlist = repo[top].bookmarks()
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
# XXX do we actually need the dirstateguard
dsguard = None
try:
--- a/hgext/narrow/narrowcommands.py Wed Jan 25 18:46:20 2023 +0100
+++ b/hgext/narrow/narrowcommands.py Wed Jan 25 19:12:31 2023 +0100
@@ -320,7 +320,7 @@
repo.store.markremoved(f)
ui.status(_(b'deleting unwanted files from working copy\n'))
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
narrowspec.updateworkingcopy(repo, assumeclean=True)
narrowspec.copytoworkingcopy(repo)
@@ -380,7 +380,7 @@
if ellipsesremote:
ds = repo.dirstate
p1, p2 = ds.p1(), ds.p2()
- with ds.parentchange(repo):
+ with ds.changing_parents(repo):
ds.setparents(repo.nullid, repo.nullid)
if isoldellipses:
with wrappedextraprepare:
@@ -419,10 +419,12 @@
bundle2.processbundle(repo, bundle, op=op, remote=remote)
if ellipsesremote:
- with ds.parentchange(repo):
+ with ds.changing_parents(repo):
ds.setparents(p1, p2)
- with repo.transaction(b'widening'), repo.dirstate.parentchange(repo):
+ with repo.transaction(b'widening'), repo.dirstate.changing_parents(
+ repo
+ ):
repo.setnewnarrowpats()
narrowspec.updateworkingcopy(repo)
narrowspec.copytoworkingcopy(repo)
@@ -591,7 +593,7 @@
if update_working_copy:
with repo.wlock(), repo.lock(), repo.transaction(
b'narrow-wc'
- ), repo.dirstate.parentchange(repo):
+ ), repo.dirstate.changing_parents(repo):
narrowspec.updateworkingcopy(repo)
narrowspec.copytoworkingcopy(repo)
return 0
--- a/hgext/split.py Wed Jan 25 18:46:20 2023 +0100
+++ b/hgext/split.py Wed Jan 25 19:12:31 2023 +0100
@@ -134,7 +134,7 @@
# Set working parent to ctx.p1(), and keep working copy as ctx's content
if ctx.node() != repo.dirstate.p1():
hg.clean(repo, ctx.node(), show_stats=False)
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
scmutil.movedirstate(repo, ctx.p1())
# Any modified, added, removed, deleted result means split is incomplete
--- a/hgext/uncommit.py Wed Jan 25 18:46:20 2023 +0100
+++ b/hgext/uncommit.py Wed Jan 25 19:12:31 2023 +0100
@@ -236,7 +236,7 @@
# Fully removed the old commit
mapping[old.node()] = ()
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
scmutil.movedirstate(repo, repo[newid], match)
scmutil.cleanupnodes(repo, mapping, b'uncommit', fixphase=True)
@@ -317,7 +317,7 @@
newpredctx = repo[newprednode]
dirstate = repo.dirstate
- with dirstate.parentchange(repo):
+ with dirstate.changing_parents(repo):
scmutil.movedirstate(repo, newpredctx)
mapping = {curctx.node(): (newprednode,)}
--- a/hgext/win32text.py Wed Jan 25 18:46:20 2023 +0100
+++ b/hgext/win32text.py Wed Jan 25 19:12:31 2023 +0100
@@ -216,7 +216,7 @@
def wrap_revert(orig, repo, ctx, names, uipathfn, actions, *args, **kwargs):
# reset dirstate cache for file we touch
ds = repo.dirstate
- with ds.parentchange(repo):
+ with ds.changing_parents(repo):
for filename in actions[b'revert'][0]:
entry = ds.get_entry(filename)
if entry is not None:
--- a/mercurial/cmdutil.py Wed Jan 25 18:46:20 2023 +0100
+++ b/mercurial/cmdutil.py Wed Jan 25 19:12:31 2023 +0100
@@ -638,7 +638,7 @@
# already called within a `pendingchange`, However we
# are taking a shortcut here in order to be able to
# quickly deprecated the older API.
- with dirstate.parentchange(repo):
+ with dirstate.changing_parents(repo):
dirstate.update_file(
realname,
p1_tracked=True,
@@ -1532,7 +1532,7 @@
new_node = mem_ctx.commit()
if repo.dirstate.p1() == ctx.node():
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
scmutil.movedirstate(repo, repo[new_node])
replacements = {ctx.node(): [new_node]}
scmutil.cleanupnodes(
@@ -1625,7 +1625,7 @@
new_node = mem_ctx.commit()
if repo.dirstate.p1() == ctx.node():
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
scmutil.movedirstate(repo, repo[new_node])
replacements = {ctx.node(): [new_node]}
scmutil.cleanupnodes(repo, replacements, b'copy', fixphase=True)
@@ -3024,7 +3024,7 @@
newid = repo.commitctx(new)
ms.reset()
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
# Reroute the working copy parent to the new changeset
repo.setparents(newid, repo.nullid)
--- a/mercurial/commands.py Wed Jan 25 18:46:20 2023 +0100
+++ b/mercurial/commands.py Wed Jan 25 19:12:31 2023 +0100
@@ -6264,7 +6264,7 @@
#
# All this should eventually happens, but in the mean time, we use this
# context manager slightly out of the context it should be.
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
mergestatemod.recordupdates(repo, ms.actions(), branchmerge, None)
if not didwork and pats:
--- a/mercurial/context.py Wed Jan 25 18:46:20 2023 +0100
+++ b/mercurial/context.py Wed Jan 25 19:12:31 2023 +0100
@@ -1595,7 +1595,7 @@
if p2node is None:
p2node = self._repo.nodeconstants.nullid
dirstate = self._repo.dirstate
- with dirstate.parentchange(self._repo):
+ with dirstate.changing_parents(self._repo):
copies = dirstate.setparents(p1node, p2node)
pctx = self._repo[p1node]
if copies:
@@ -2050,7 +2050,7 @@
return sorted(f for f in ds.matches(match) if ds.get_entry(f).tracked)
def markcommitted(self, node):
- with self._repo.dirstate.parentchange(self._repo):
+ with self._repo.dirstate.changing_parents(self._repo):
for f in self.modified() + self.added():
self._repo.dirstate.update_file(
f, p1_tracked=True, wc_tracked=True
--- a/mercurial/dirstate.py Wed Jan 25 18:46:20 2023 +0100
+++ b/mercurial/dirstate.py Wed Jan 25 19:12:31 2023 +0100
@@ -69,7 +69,7 @@
def requires_parents_change(func):
def wrap(self, *args, **kwargs):
if not self.pendingparentchange():
- msg = 'calling `%s` outside of a parentchange context'
+ msg = 'calling `%s` outside of a changing_parents context'
msg %= func.__name__
raise error.ProgrammingError(msg)
if self._invalidated_context:
@@ -83,7 +83,7 @@
def requires_no_parents_change(func):
def wrap(self, *args, **kwargs):
if self.pendingparentchange():
- msg = 'calling `%s` inside of a parentchange context'
+ msg = 'calling `%s` inside of a changing_parents context'
msg %= func.__name__
raise error.ProgrammingError(msg)
return func(self, *args, **kwargs)
@@ -127,7 +127,7 @@
self._dirty_tracked_set = False
self._ui = ui
self._filecache = {}
- # nesting level of `parentchange` context
+ # nesting level of `changing_parents` context
self._parentwriters = 0
# True if the current dirstate changing operations have been
# invalidated (used to make sure all nested contexts have been exited)
@@ -151,7 +151,7 @@
self._pl
@contextlib.contextmanager
- def parentchange(self, repo):
+ def changing_parents(self, repo):
"""Context manager for handling dirstate parents.
If an exception occurs in the scope of the context manager,
@@ -180,6 +180,14 @@
assert self._parentwriters == 0
self._invalidated_context = False
+ # here to help migration to the new code
+ def parentchange(self):
+ msg = (
+ "Mercurial 6.4 and later requires call to "
+ "`dirstate.changing_parents(repo)`"
+ )
+ raise error.ProgrammingError(msg)
+
def pendingparentchange(self):
"""Returns true if the dirstate is in the middle of a set of changes
that modify the dirstate parent.
@@ -399,7 +407,7 @@
if self._parentwriters == 0:
raise ValueError(
b"cannot set dirstate parent outside of "
- b"dirstate.parentchange context manager"
+ b"dirstate.changing_parents context manager"
)
self._dirty = True
@@ -523,7 +531,7 @@
rewriting operation.
It should not be called during a merge (p2 != nullid) and only within
- a `with dirstate.parentchange(repo):` context.
+ a `with dirstate.changing_parents(repo):` context.
"""
if self.in_merge:
msg = b'update_file_reference should not be called when merging'
@@ -566,7 +574,7 @@
This is to be called when the direstates parent changes to keep track
of what is the file situation in regards to the working copy and its parent.
- This function must be called within a `dirstate.parentchange` context.
+ This function must be called within a `dirstate.changing_parents` context.
note: the API is at an early stage and we might need to adjust it
depending of what information ends up being relevant and useful to
--- a/mercurial/interfaces/dirstate.py Wed Jan 25 18:46:20 2023 +0100
+++ b/mercurial/interfaces/dirstate.py Wed Jan 25 19:12:31 2023 +0100
@@ -35,7 +35,7 @@
_checkexec = interfaceutil.Attribute("""Callable for checking exec bits.""")
@contextlib.contextmanager
- def parentchange(repo):
+ def changing_parents(repo):
"""Context manager for handling dirstate parents.
If an exception occurs in the scope of the context manager,
--- a/mercurial/merge.py Wed Jan 25 18:46:20 2023 +0100
+++ b/mercurial/merge.py Wed Jan 25 19:12:31 2023 +0100
@@ -2155,7 +2155,7 @@
assert len(getfiledata) == (
mresult.len((mergestatemod.ACTION_GET,)) if wantfiledata else 0
)
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
### Filter Filedata
#
# We gathered "cache" information for the clean file while
@@ -2377,7 +2377,7 @@
# fix up dirstate for copies and renames
copies.graftcopies(wctx, ctx, base)
else:
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
repo.setparents(pctx.node(), pother)
repo.dirstate.write(repo.currenttransaction())
# fix up dirstate for copies and renames
--- a/mercurial/shelve.py Wed Jan 25 18:46:20 2023 +0100
+++ b/mercurial/shelve.py Wed Jan 25 19:12:31 2023 +0100
@@ -637,7 +637,7 @@
ui.status(_(b'shelved as %s\n') % name)
if opts[b'keep']:
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
scmutil.movedirstate(repo, parent, match)
else:
hg.update(repo, parent.node())
@@ -862,14 +862,14 @@
shelvectx = repo[state.parents[1]]
pendingctx = state.pendingctx
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
repo.setparents(state.pendingctx.node(), repo.nullid)
repo.dirstate.write(repo.currenttransaction())
targetphase = _target_phase(repo)
overrides = {(b'phases', b'new-commit'): targetphase}
with repo.ui.configoverride(overrides, b'unshelve'):
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
repo.setparents(state.parents[0], repo.nullid)
newnode, ispartialunshelve = _createunshelvectx(
ui, repo, shelvectx, basename, interactive, opts
@@ -1068,7 +1068,7 @@
)
raise error.ConflictResolutionRequired(b'unshelve')
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
repo.setparents(tmpwctx.node(), repo.nullid)
newnode, ispartialunshelve = _createunshelvectx(
ui, repo, shelvectx, basename, interactive, opts
--- a/mercurial/sparse.py Wed Jan 25 18:46:20 2023 +0100
+++ b/mercurial/sparse.py Wed Jan 25 19:12:31 2023 +0100
@@ -451,7 +451,7 @@
message,
)
- with repo.dirstate.parentchange(repo):
+ with repo.dirstate.changing_parents(repo):
mergemod.applyupdates(
repo,
tmresult,
@@ -655,7 +655,7 @@
The remaining sparse config only has profiles, if defined. The working
directory is refreshed, as needed.
"""
- with repo.wlock(), repo.dirstate.parentchange(repo):
+ with repo.wlock(), repo.dirstate.changing_parents(repo):
raw = repo.vfs.tryread(b'sparse')
includes, excludes, profiles = parseconfig(repo.ui, raw, b'sparse')
@@ -671,7 +671,7 @@
The updated sparse config is written out and the working directory
is refreshed, as needed.
"""
- with repo.wlock(), repo.dirstate.parentchange(repo):
+ with repo.wlock(), repo.dirstate.changing_parents(repo):
# read current configuration
raw = repo.vfs.tryread(b'sparse')
includes, excludes, profiles = parseconfig(repo.ui, raw, b'sparse')
@@ -730,7 +730,7 @@
The new config is written out and a working directory refresh is performed.
"""
- with repo.wlock(), repo.lock(), repo.dirstate.parentchange(repo):
+ with repo.wlock(), repo.lock(), repo.dirstate.changing_parents(repo):
raw = repo.vfs.tryread(b'sparse')
oldinclude, oldexclude, oldprofiles = parseconfig(
repo.ui, raw, b'sparse'
--- a/tests/test-narrow-expanddirstate.t Wed Jan 25 18:46:20 2023 +0100
+++ b/tests/test-narrow-expanddirstate.t Wed Jan 25 19:12:31 2023 +0100
@@ -74,7 +74,7 @@
> narrowspec.copytoworkingcopy(repo)
> newmatcher = narrowspec.match(repo.root, includes, excludes)
> added = matchmod.differencematcher(newmatcher, currentmatcher)
- > with repo.dirstate.parentchange(repo):
+ > with repo.dirstate.changing_parents(repo):
> for f in repo[b'.'].manifest().walk(added):
> repo.dirstate.update_file(
> f,
--- a/tests/test-rebuildstate.t Wed Jan 25 18:46:20 2023 +0100
+++ b/tests/test-rebuildstate.t Wed Jan 25 19:12:31 2023 +0100
@@ -17,7 +17,7 @@
> try:
> for file in pats:
> if opts.get('normal_lookup'):
- > with repo.dirstate.parentchange(repo):
+ > with repo.dirstate.changing_parents(repo):
> repo.dirstate.update_file(
> file,
> p1_tracked=True,