Patchwork D1576: amend: extract function for calculating changeset extras

login
register
mail settings
Submitter phabricator
Date Dec. 1, 2017, 10:43 p.m.
Message ID <differential-rev-PHID-DREV-vn4x4zszshpr544de6w6-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/25874/
State Superseded
Headers show

Comments

phabricator - Dec. 1, 2017, 10:43 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  We (Google) have extensions that would like to put their own entries
  in the extras. Some of these don't make sense to keep on amend
  (e.g. an entry saying "this corresponds to snaphot X of review unit
  Y"). So this patch extracts a function for calculating the extras so
  our extension can more easily override it.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1576

AFFECTED FILES
  mercurial/cmdutil.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel
phabricator - Dec. 2, 2017, 2:48 a.m.
yuja added a comment.


  Queued, but I doubt if `pureextra == old.extra()` would work with your extension.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1576

To: martinvonz, #hg-reviewers, yuja
Cc: mercurial-devel
phabricator - Dec. 2, 2017, 5:15 a.m.
martinvonz added a comment.


  In https://phab.mercurial-scm.org/D1576#26799, @yuja wrote:
  
  > Queued, but I doubt if `pureextra == old.extra()` would work with your extension.
  
  
  I did think about that and then I forgot it before I sent the patch :( We don't need this that urgently, so I'll just drop the patch and think of a better way of dealing with it. We should perhaps instead have some way of just indicating which extras can be carried over.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1576

To: martinvonz, #hg-reviewers, yuja
Cc: mercurial-devel

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -3114,6 +3114,22 @@ 
     else:
         return f not in ctx2.manifest()
 
+def _amendextras(extra, old, wctx):
+    """Calculated extras for amended changeset.
+
+    This is a separate function so extensions can override it and filter out
+    (or add) certain entries.
+    """
+    # Copy to avoid mutating input
+    extra = extra.copy()
+    # Update extra dict from amended commit (e.g. to preserve graft
+    # source)
+    extra.update(old.extra())
+
+    # Also update it from the from the wctx
+    extra.update(wctx.extra())
+    return extra
+
 def amend(ui, repo, old, extra, pats, opts):
     # avoid cycle context -> subrepo -> cmdutil
     from . import context
@@ -3137,14 +3153,7 @@ 
         # base     o - first parent of the changeset to amend
         wctx = repo[None]
 
-        # Copy to avoid mutating input
-        extra = extra.copy()
-        # Update extra dict from amended commit (e.g. to preserve graft
-        # source)
-        extra.update(old.extra())
-
-        # Also update it from the from the wctx
-        extra.update(wctx.extra())
+        extra = _amendextras(extra, old, wctx)
 
         user = opts.get('user') or old.user()
         date = opts.get('date') or old.date()