comparison mercurial/context.py @ 32763:34be21aa2b26

memctx: refactor inline getfilectx into convenience method No actual logic is changing, just moving code so __init__ is easier to read.
author Sean Farley <sean@farley.io>
date Fri, 09 Jun 2017 13:25:02 -0700
parents dc7efa2826e4
children ec302748edd8
comparison
equal deleted inserted replaced
32762:2d93d2159e30 32763:34be21aa2b26
2039 cache[path] = func(repo, memctx, path) 2039 cache[path] = func(repo, memctx, path)
2040 return cache[path] 2040 return cache[path]
2041 2041
2042 return getfilectx 2042 return getfilectx
2043 2043
2044 def memfilefromctx(ctx):
2045 """Given a context return a memfilectx for ctx[path]
2046
2047 This is a convenience method for building a memctx based on another
2048 context.
2049 """
2050 def getfilectx(repo, memctx, path):
2051 fctx = ctx[path]
2052 # this is weird but apparently we only keep track of one parent
2053 # (why not only store that instead of a tuple?)
2054 copied = fctx.renamed()
2055 if copied:
2056 copied = copied[0]
2057 return memfilectx(repo, path, fctx.data(),
2058 islink=fctx.islink(), isexec=fctx.isexec(),
2059 copied=copied, memctx=memctx)
2060
2061 return getfilectx
2062
2044 class memctx(committablectx): 2063 class memctx(committablectx):
2045 """Use memctx to perform in-memory commits via localrepo.commitctx(). 2064 """Use memctx to perform in-memory commits via localrepo.commitctx().
2046 2065
2047 Revision information is supplied at initialization time while 2066 Revision information is supplied at initialization time while
2048 related files data and is made available through a callback 2067 related files data and is made available through a callback
2086 self._files = files 2105 self._files = files
2087 self.substate = {} 2106 self.substate = {}
2088 2107
2089 # if store is not callable, wrap it in a function 2108 # if store is not callable, wrap it in a function
2090 if not callable(filectxfn): 2109 if not callable(filectxfn):
2091 def getfilectx(repo, memctx, path): 2110 self._filectxfn = memfilefromctx(filectxfn)
2092 fctx = filectxfn[path]
2093 # this is weird but apparently we only keep track of one parent
2094 # (why not only store that instead of a tuple?)
2095 copied = fctx.renamed()
2096 if copied:
2097 copied = copied[0]
2098 return memfilectx(repo, path, fctx.data(),
2099 islink=fctx.islink(), isexec=fctx.isexec(),
2100 copied=copied, memctx=memctx)
2101 self._filectxfn = getfilectx
2102 else: 2111 else:
2103 # memoizing increases performance for e.g. vcs convert scenarios. 2112 # memoizing increases performance for e.g. vcs convert scenarios.
2104 self._filectxfn = makecachingfilectxfn(filectxfn) 2113 self._filectxfn = makecachingfilectxfn(filectxfn)
2105 2114
2106 if editor: 2115 if editor: