comparison mercurial/context.py @ 35400:8a0cac20a1ad

memfilectx: make changectx argument mandatory in constructor (API) committablefilectx has three subclasses: workingfilectx, memfilectx, and overlayfilectx. committablefilectx takes an optional (change) ctx instance to its constructor. If it's provided, it's set on the instance as self._changectx. If not, that property is supposed to be defined by the class. However, only workingfilectx does that. The other two will have the property undefined if it's not passed in the constructor. That seems bad to me. This patch makes the changectx argument to the memfilectx constructor mandatory because that fixes the failure I ran into. It seems like we should also fix the overlayfilectx case. Differential Revision: https://phab.mercurial-scm.org/D1658
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 11 Dec 2017 09:27:40 -0800
parents 8384553b1684
children 265cd9e19d26
comparison
equal deleted inserted replaced
35399:dffc35a5be9f 35400:8a0cac20a1ad
2202 parents = (self._repo[parents[0]], self._repo[parents[1]]) 2202 parents = (self._repo[parents[0]], self._repo[parents[1]])
2203 2203
2204 files = self._cache.keys() 2204 files = self._cache.keys()
2205 def getfile(repo, memctx, path): 2205 def getfile(repo, memctx, path):
2206 if self._cache[path]['exists']: 2206 if self._cache[path]['exists']:
2207 return memfilectx(repo, path, 2207 return memfilectx(repo, memctx, path,
2208 self._cache[path]['data'], 2208 self._cache[path]['data'],
2209 'l' in self._cache[path]['flags'], 2209 'l' in self._cache[path]['flags'],
2210 'x' in self._cache[path]['flags'], 2210 'x' in self._cache[path]['flags'],
2211 self._cache[path]['copied'], 2211 self._cache[path]['copied'])
2212 memctx)
2213 else: 2212 else:
2214 # Returning None, but including the path in `files`, is 2213 # Returning None, but including the path in `files`, is
2215 # necessary for memctx to register a deletion. 2214 # necessary for memctx to register a deletion.
2216 return None 2215 return None
2217 return memctx(self._repo, parents, text, files, getfile, date=date, 2216 return memctx(self._repo, parents, text, files, getfile, date=date,
2387 # this is weird but apparently we only keep track of one parent 2386 # this is weird but apparently we only keep track of one parent
2388 # (why not only store that instead of a tuple?) 2387 # (why not only store that instead of a tuple?)
2389 copied = fctx.renamed() 2388 copied = fctx.renamed()
2390 if copied: 2389 if copied:
2391 copied = copied[0] 2390 copied = copied[0]
2392 return memfilectx(repo, path, fctx.data(), 2391 return memfilectx(repo, memctx, path, fctx.data(),
2393 islink=fctx.islink(), isexec=fctx.isexec(), 2392 islink=fctx.islink(), isexec=fctx.isexec(),
2394 copied=copied, memctx=memctx) 2393 copied=copied)
2395 2394
2396 return getfilectx 2395 return getfilectx
2397 2396
2398 def memfilefrompatch(patchstore): 2397 def memfilefrompatch(patchstore):
2399 """Given a patch (e.g. patchstore object) return a memfilectx 2398 """Given a patch (e.g. patchstore object) return a memfilectx
2403 def getfilectx(repo, memctx, path): 2402 def getfilectx(repo, memctx, path):
2404 data, mode, copied = patchstore.getfile(path) 2403 data, mode, copied = patchstore.getfile(path)
2405 if data is None: 2404 if data is None:
2406 return None 2405 return None
2407 islink, isexec = mode 2406 islink, isexec = mode
2408 return memfilectx(repo, path, data, islink=islink, 2407 return memfilectx(repo, memctx, path, data, islink=islink,
2409 isexec=isexec, copied=copied, 2408 isexec=isexec, copied=copied)
2410 memctx=memctx)
2411 2409
2412 return getfilectx 2410 return getfilectx
2413 2411
2414 class memctx(committablectx): 2412 class memctx(committablectx):
2415 """Use memctx to perform in-memory commits via localrepo.commitctx(). 2413 """Use memctx to perform in-memory commits via localrepo.commitctx().
2537 class memfilectx(committablefilectx): 2535 class memfilectx(committablefilectx):
2538 """memfilectx represents an in-memory file to commit. 2536 """memfilectx represents an in-memory file to commit.
2539 2537
2540 See memctx and committablefilectx for more details. 2538 See memctx and committablefilectx for more details.
2541 """ 2539 """
2542 def __init__(self, repo, path, data, islink=False, 2540 def __init__(self, repo, changectx, path, data, islink=False,
2543 isexec=False, copied=None, memctx=None): 2541 isexec=False, copied=None):
2544 """ 2542 """
2545 path is the normalized file path relative to repository root. 2543 path is the normalized file path relative to repository root.
2546 data is the file content as a string. 2544 data is the file content as a string.
2547 islink is True if the file is a symbolic link. 2545 islink is True if the file is a symbolic link.
2548 isexec is True if the file is executable. 2546 isexec is True if the file is executable.
2549 copied is the source file path if current file was copied in the 2547 copied is the source file path if current file was copied in the
2550 revision being committed, or None.""" 2548 revision being committed, or None."""
2551 super(memfilectx, self).__init__(repo, path, None, memctx) 2549 super(memfilectx, self).__init__(repo, path, None, changectx)
2552 self._data = data 2550 self._data = data
2553 self._flags = (islink and 'l' or '') + (isexec and 'x' or '') 2551 self._flags = (islink and 'l' or '') + (isexec and 'x' or '')
2554 self._copied = None 2552 self._copied = None
2555 if copied: 2553 if copied:
2556 self._copied = (copied, nullid) 2554 self._copied = (copied, nullid)