changeset 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 d0f1e3d3ef4d
children be814edf3306
files mercurial/context.py
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Thu Aug 17 18:09:32 2017 +0200
+++ b/mercurial/context.py	Mon Aug 28 16:49:41 2017 -0700
@@ -2298,15 +2298,23 @@
     def __new__(cls, repo, originalctx, *args, **kwargs):
         return super(metadataonlyctx, cls).__new__(cls, repo)
 
-    def __init__(self, repo, originalctx, parents, text, user=None, date=None,
-                 extra=None, editor=False):
+    def __init__(self, repo, originalctx, parents=None, text=None, user=None,
+                 date=None, extra=None, editor=False):
+        if text is None:
+            text = originalctx.description()
         super(metadataonlyctx, self).__init__(repo, text, user, date, extra)
         self._rev = None
         self._node = None
         self._originalctx = originalctx
         self._manifestnode = originalctx.manifestnode()
-        parents = [(p or nullid) for p in parents]
-        p1, p2 = self._parents = [changectx(self._repo, p) for p in parents]
+        if parents is None:
+            parents = originalctx.parents()
+        else:
+            parents = [repo[p] for p in parents if p is not None]
+        parents = parents[:]
+        while len(parents) < 2:
+            parents.append(repo[nullid])
+        p1, p2 = self._parents = parents
 
         # sanity check to ensure that the reused manifest parents are
         # manifests of our commit parents