Patchwork [2,of,3] metadataonlyctx: make parents and text optional

login
register
mail settings
Submitter Jun Wu
Date March 26, 2017, 6:41 p.m.
Message ID <336512ee2f947f07149e.1490553700@localhost.localdomain>
Download mbox | patch
Permalink /patch/19694/
State Deferred
Headers show

Comments

Jun Wu - March 26, 2017, 6:41 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1490551051 25200
#      Sun Mar 26 10:57:31 2017 -0700
# Node ID 336512ee2f947f07149e399a84927f9d820d2b62
# Parent  65636eb4a1e55f69daf6795a9ecad7a3da39108e
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 336512ee2f94
metadataonlyctx: make parents and text optional

Sometimes the caller is not interested in changing parents or text
(description), but only the commit metadata. This makes that easier.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -2042,6 +2042,8 @@  class metadataonlyctx(committablectx):
         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
@@ -2049,4 +2051,8 @@  class metadataonlyctx(committablectx):
         self._originalctx = originalctx
         self._manifestnode = originalctx.manifestnode()
+        if parents is None:
+            parents = [p.node() for p in originalctx.parents()]
+            while len(parents) < 2:
+                parents.append(nullid)
         parents = [(p or nullid) for p in parents]
         p1, p2 = self._parents = [changectx(self._repo, p) for p in parents]