[PATCH 1 of 3 remove-makememctx V2] memctx: refactor inline getfilectx into convenience method
Sean Farley
sean at farley.io
Fri Jun 9 21:20:24 UTC 2017
# HG changeset patch
# User Sean Farley <sean at farley.io>
# Date 1497039902 25200
# Fri Jun 09 13:25:02 2017 -0700
# Branch remove-makememctx
# Node ID dfe7dc826d3b1c6b0c933cc74c9ad14042f39877
# Parent 776d077eb4ef815e08631fb1e7b33375adca3ef1
memctx: refactor inline getfilectx into convenience method
No actual logic is changing, just moving code so __init__ is easier to
read.
diff --git a/mercurial/context.py b/mercurial/context.py
index 91b5bf1..5960d02 100644
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -2039,10 +2039,29 @@ def makecachingfilectxfn(func):
cache[path] = func(repo, memctx, path)
return cache[path]
return getfilectx
+def memfilefromctx(ctx):
+ """Given a context return a memfilectx for ctx[path]
+
+ This is a convenience method for building a memctx based on another
+ context.
+ """
+ def getfilectx(repo, memctx, path):
+ fctx = ctx[path]
+ # this is weird but apparently we only keep track of one parent
+ # (why not only store that instead of a tuple?)
+ copied = fctx.renamed()
+ if copied:
+ copied = copied[0]
+ return memfilectx(repo, path, fctx.data(),
+ islink=fctx.islink(), isexec=fctx.isexec(),
+ copied=copied, memctx=memctx)
+
+ return getfilectx
+
class memctx(committablectx):
"""Use memctx to perform in-memory commits via localrepo.commitctx().
Revision information is supplied at initialization time while
related files data and is made available through a callback
@@ -2086,21 +2105,11 @@ class memctx(committablectx):
self._files = files
self.substate = {}
# if store is not callable, wrap it in a function
if not callable(filectxfn):
- def getfilectx(repo, memctx, path):
- fctx = filectxfn[path]
- # this is weird but apparently we only keep track of one parent
- # (why not only store that instead of a tuple?)
- copied = fctx.renamed()
- if copied:
- copied = copied[0]
- return memfilectx(repo, path, fctx.data(),
- islink=fctx.islink(), isexec=fctx.isexec(),
- copied=copied, memctx=memctx)
- self._filectxfn = getfilectx
+ self._filectxfn = memfilefromctx(filectxfn)
else:
# memoizing increases performance for e.g. vcs convert scenarios.
self._filectxfn = makecachingfilectxfn(filectxfn)
if editor:
More information about the Mercurial-devel
mailing list