Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/context.py @ 32785:041d976b662a
context: inline makememctx (API)
I have always thought it weird that we have a helper method instead of
just using __init__. So, I ripped it out.
author | Sean Farley <sean@farley.io> |
---|---|
date | Sat, 10 Jun 2017 10:24:33 -0400 |
parents | ec302748edd8 |
children | 448fc659a430 |
comparison
equal
deleted
inserted
replaced
32784:ec302748edd8 | 32785:041d976b662a |
---|---|
382 | 382 |
383 for l in r: | 383 for l in r: |
384 l.sort() | 384 l.sort() |
385 | 385 |
386 return r | 386 return r |
387 | |
388 | |
389 def makememctx(repo, parents, text, user, date, branch, files, store, | |
390 editor=None, extra=None): | |
391 def getfilectx(repo, memctx, path): | |
392 data, mode, copied = store.getfile(path) | |
393 if data is None: | |
394 return None | |
395 islink, isexec = mode | |
396 return memfilectx(repo, path, data, islink=islink, isexec=isexec, | |
397 copied=copied, memctx=memctx) | |
398 if extra is None: | |
399 extra = {} | |
400 if branch: | |
401 extra['branch'] = encoding.fromlocal(branch) | |
402 ctx = memctx(repo, parents, text, files, getfilectx, user, | |
403 date, extra, editor) | |
404 return ctx | |
405 | 387 |
406 def _filterederror(repo, changeid): | 388 def _filterederror(repo, changeid): |
407 """build an exception to be raised about a filtered changeid | 389 """build an exception to be raised about a filtered changeid |
408 | 390 |
409 This is extracted in a function to help extensions (eg: evolve) to | 391 This is extracted in a function to help extensions (eg: evolve) to |
2108 # Extensions that need to retain compatibility across Mercurial 3.1 can use | 2090 # Extensions that need to retain compatibility across Mercurial 3.1 can use |
2109 # this field to determine what to do in filectxfn. | 2091 # this field to determine what to do in filectxfn. |
2110 _returnnoneformissingfiles = True | 2092 _returnnoneformissingfiles = True |
2111 | 2093 |
2112 def __init__(self, repo, parents, text, files, filectxfn, user=None, | 2094 def __init__(self, repo, parents, text, files, filectxfn, user=None, |
2113 date=None, extra=None, editor=False): | 2095 date=None, extra=None, branch=None, editor=False): |
2114 super(memctx, self).__init__(repo, text, user, date, extra) | 2096 super(memctx, self).__init__(repo, text, user, date, extra) |
2115 self._rev = None | 2097 self._rev = None |
2116 self._node = None | 2098 self._node = None |
2117 parents = [(p or nullid) for p in parents] | 2099 parents = [(p or nullid) for p in parents] |
2118 p1, p2 = parents | 2100 p1, p2 = parents |
2119 self._parents = [changectx(self._repo, p) for p in (p1, p2)] | 2101 self._parents = [changectx(self._repo, p) for p in (p1, p2)] |
2120 files = sorted(set(files)) | 2102 files = sorted(set(files)) |
2121 self._files = files | 2103 self._files = files |
2104 if branch is not None: | |
2105 self._extra['branch'] = encoding.fromlocal(branch) | |
2122 self.substate = {} | 2106 self.substate = {} |
2123 | 2107 |
2124 # if store is not callable, wrap it in a function | 2108 if isinstance(filectxfn, patch.filestore): |
2125 if not callable(filectxfn): | 2109 self._filectxfn = memfilefrompatch(filectxfn) |
2110 elif not callable(filectxfn): | |
2111 # if store is not callable, wrap it in a function | |
2126 self._filectxfn = memfilefromctx(filectxfn) | 2112 self._filectxfn = memfilefromctx(filectxfn) |
2127 else: | 2113 else: |
2128 # memoizing increases performance for e.g. vcs convert scenarios. | 2114 # memoizing increases performance for e.g. vcs convert scenarios. |
2129 self._filectxfn = makecachingfilectxfn(filectxfn) | 2115 self._filectxfn = makecachingfilectxfn(filectxfn) |
2130 | 2116 |