Patchwork D9182: absorb: update commit hash references in the new commits

login
register
mail settings
Submitter phabricator
Date Oct. 9, 2020, 4:22 p.m.
Message ID <differential-rev-PHID-DREV-ei6ockg3qwpyrbld4d5o-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47419/
State Superseded
Headers show

Comments

phabricator - Oct. 9, 2020, 4:22 p.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/absorb.py
  tests/test-absorb.t

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-absorb.t b/tests/test-absorb.t
--- a/tests/test-absorb.t
+++ b/tests/test-absorb.t
@@ -603,21 +603,21 @@ 
   $ hg commit -m a -A a b
   $ hg branch foo -q
   $ echo b > b
-  $ hg commit -m foo  # will become empty
+  $ hg commit -m 'foo (child of 0cde1ae39321)'  # will become empty
   $ hg branch bar -q
-  $ hg commit -m bar  # is already empty
+  $ hg commit -m 'bar (child of e969dc86aefc)'  # is already empty
   $ echo a2 > a
   $ printf '' > b
   $ hg absorb --apply-changes --verbose | grep became
   0:0cde1ae39321: 1 file(s) changed, became 3:fc7fcdd90fdb
-  1:795dfb1adcef: 2 file(s) changed, became 4:a8740537aa53
-  2:b02935f68891: 2 file(s) changed, became 5:59533e01c707
-  $ hg log -T '{rev} (branch: {branch}) {desc}\n' -G --stat
-  @  5 (branch: bar) bar
+  1:e969dc86aefc: 2 file(s) changed, became 4:8fc6b2cb43a5
+  2:0298954ced32: 2 file(s) changed, became 5:ca8386dc4e2c
+  $ hg log -T '{rev}:{node|short} (branch: {branch}) {desc}\n' -G --stat
+  @  5:ca8386dc4e2c (branch: bar) bar (child of 8fc6b2cb43a5)
   |
-  o  4 (branch: foo) foo
+  o  4:8fc6b2cb43a5 (branch: foo) foo (child of fc7fcdd90fdb)
   |
-  o  3 (branch: default) a
+  o  3:fc7fcdd90fdb (branch: default) a
       a |  1 +
       b |  0
       2 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/hgext/absorb.py b/hgext/absorb.py
--- a/hgext/absorb.py
+++ b/hgext/absorb.py
@@ -244,7 +244,7 @@ 
         return content, mode, copy
 
 
-def overlaycontext(memworkingcopy, ctx, parents=None, extra=None):
+def overlaycontext(memworkingcopy, ctx, parents=None, extra=None, desc=None):
     """({path: content}, ctx, (p1node, p2node)?, {}?) -> memctx
     memworkingcopy overrides file contents.
     """
@@ -253,8 +253,9 @@ 
         parents = ctx.repo().changelog.parents(ctx.node())
     if extra is None:
         extra = ctx.extra()
+    if desc is None:
+        desc = ctx.description()
     date = ctx.date()
-    desc = ctx.description()
     user = ctx.user()
     files = set(ctx.files()).union(memworkingcopy)
     store = overlaystore(ctx, memworkingcopy)
@@ -923,7 +924,18 @@ 
         extra = ctx.extra()
         if self._useobsolete and self.ui.configbool(b'absorb', b'add-noise'):
             extra[b'absorb_source'] = ctx.hex()
-        mctx = overlaycontext(memworkingcopy, ctx, parents, extra=extra)
+
+        desc = rewriteutil.update_hash_refs(
+            ctx.repo(),
+            ctx.description(),
+            {
+                oldnode: [newnode]
+                for oldnode, newnode in self.replacemap.items()
+            },
+        )
+        mctx = overlaycontext(
+            memworkingcopy, ctx, parents, extra=extra, desc=desc
+        )
         return mctx.commit()
 
     @util.propertycache