Mercurial > public > mercurial-scm > hg
comparison mercurial/context.py @ 33998:becce02036e1
context: make parents and text optional in metadataonlyctx
The metadataonlyctx is to copy an existing context with some minor metadata
changes. If the caller only wants to change "extra", or "user", ideally it
does not have to read and pass "parents" and "text" information.
This patch makes "parents" and "text" optionally to convenient callers.
Differential Revision: https://phab.mercurial-scm.org/D548
author | Jun Wu <quark@fb.com> |
---|---|
date | Mon, 28 Aug 2017 16:49:41 -0700 |
parents | e43264525ce5 |
children | be814edf3306 |
comparison
equal
deleted
inserted
replaced
33997:d0f1e3d3ef4d | 33998:becce02036e1 |
---|---|
2296 metadata or is left empty. | 2296 metadata or is left empty. |
2297 """ | 2297 """ |
2298 def __new__(cls, repo, originalctx, *args, **kwargs): | 2298 def __new__(cls, repo, originalctx, *args, **kwargs): |
2299 return super(metadataonlyctx, cls).__new__(cls, repo) | 2299 return super(metadataonlyctx, cls).__new__(cls, repo) |
2300 | 2300 |
2301 def __init__(self, repo, originalctx, parents, text, user=None, date=None, | 2301 def __init__(self, repo, originalctx, parents=None, text=None, user=None, |
2302 extra=None, editor=False): | 2302 date=None, extra=None, editor=False): |
2303 if text is None: | |
2304 text = originalctx.description() | |
2303 super(metadataonlyctx, self).__init__(repo, text, user, date, extra) | 2305 super(metadataonlyctx, self).__init__(repo, text, user, date, extra) |
2304 self._rev = None | 2306 self._rev = None |
2305 self._node = None | 2307 self._node = None |
2306 self._originalctx = originalctx | 2308 self._originalctx = originalctx |
2307 self._manifestnode = originalctx.manifestnode() | 2309 self._manifestnode = originalctx.manifestnode() |
2308 parents = [(p or nullid) for p in parents] | 2310 if parents is None: |
2309 p1, p2 = self._parents = [changectx(self._repo, p) for p in parents] | 2311 parents = originalctx.parents() |
2312 else: | |
2313 parents = [repo[p] for p in parents if p is not None] | |
2314 parents = parents[:] | |
2315 while len(parents) < 2: | |
2316 parents.append(repo[nullid]) | |
2317 p1, p2 = self._parents = parents | |
2310 | 2318 |
2311 # sanity check to ensure that the reused manifest parents are | 2319 # sanity check to ensure that the reused manifest parents are |
2312 # manifests of our commit parents | 2320 # manifests of our commit parents |
2313 mp1, mp2 = self.manifestctx().parents | 2321 mp1, mp2 = self.manifestctx().parents |
2314 if p1 != nullid and p1.manifestnode() != mp1: | 2322 if p1 != nullid and p1.manifestnode() != mp1: |