absorb: consider rewrite.empty-successor configuration
authorManuel Jacob <me@manueljacob.de>
Mon, 01 Jun 2020 09:42:41 +0200
changeset 45124 3ee8e2d5c0d8
parent 45123 1efbfa9b36a7
child 45125 f55099982bc5
absorb: consider rewrite.empty-successor configuration This adds support for the recently added rewrite.empty-successor configuration.
hgext/absorb.py
mercurial/helptext/config.txt
tests/test-absorb.t
--- a/hgext/absorb.py	Mon Jun 01 08:38:42 2020 +0200
+++ b/hgext/absorb.py	Mon Jun 01 09:42:41 2020 +0200
@@ -50,6 +50,7 @@
     phases,
     pycompat,
     registrar,
+    rewriteutil,
     scmutil,
     util,
 )
@@ -782,8 +783,10 @@
                 # nothing changed, nothing commited
                 nextp1 = ctx
                 continue
-            if ctx.files() and self._willbecomenoop(
-                memworkingcopy, ctx, nextp1
+            if (
+                self.skip_empty_successor
+                and ctx.files()
+                and self._willbecomenoop(memworkingcopy, ctx, nextp1)
             ):
                 # changeset is no longer necessary
                 self.replacemap[ctx.node()] = None
@@ -935,6 +938,10 @@
                 self.repo, replacements, operation=b'absorb', fixphase=True
             )
 
+    @util.propertycache
+    def skip_empty_successor(self):
+        return rewriteutil.skip_empty_successor(self.ui, b'absorb')
+
 
 def _parsechunk(hunk):
     """(crecord.uihunk or patch.recordhunk) -> (path, (a1, a2, [bline]))"""
--- a/mercurial/helptext/config.txt	Mon Jun 01 08:38:42 2020 +0200
+++ b/mercurial/helptext/config.txt	Mon Jun 01 09:42:41 2020 +0200
@@ -1896,7 +1896,7 @@
     operations. If set to ``skip``, the successor is not created. If set to
     ``keep``, the empty successor is created and kept.
 
-    Currently, only the rebase command considers this configuration.
+    Currently, only the rebase and absorb commands consider this configuration.
     (EXPERIMENTAL)
 
 ``storage``
--- a/tests/test-absorb.t	Mon Jun 01 08:38:42 2020 +0200
+++ b/tests/test-absorb.t	Mon Jun 01 09:42:41 2020 +0200
@@ -490,6 +490,71 @@
      +3
   
 
+Setting config rewrite.empty-successor=keep causes empty changesets to get committed:
+
+  $ cd ..
+  $ hg init repo4a
+  $ cd repo4a
+  $ cat > a <<EOF
+  > 1
+  > 2
+  > EOF
+  $ hg commit -m a12 -A a
+  $ cat > b <<EOF
+  > 1
+  > 2
+  > EOF
+  $ hg commit -m b12 -A b
+  $ echo 3 >> b
+  $ hg commit -m b3
+  $ echo 4 >> b
+  $ hg commit -m b4
+  $ echo 1 > b
+  $ echo 3 >> a
+  $ hg absorb -pn
+  showing changes for a
+          @@ -2,0 +2,1 @@
+  bfafb49 +3
+  showing changes for b
+          @@ -1,3 +1,0 @@
+  1154859 -2
+  30970db -3
+  a393a58 -4
+  
+  4 changesets affected
+  a393a58 b4
+  30970db b3
+  1154859 b12
+  bfafb49 a12
+  $ hg absorb -av --config rewrite.empty-successor=keep | grep became
+  0:bfafb49242db: 1 file(s) changed, became 4:1a2de97fc652
+  1:115485984805: 2 file(s) changed, became 5:0c930dfab74c
+  2:30970dbf7b40: 2 file(s) changed, became 6:df6574ae635c
+  3:a393a58b9a85: 2 file(s) changed, became 7:ad4bd3462c9e
+  $ hg log -T '{rev} {desc}\n' -Gp
+  @  7 b4
+  |
+  o  6 b3
+  |
+  o  5 b12
+  |  diff --git a/b b/b
+  |  new file mode 100644
+  |  --- /dev/null
+  |  +++ b/b
+  |  @@ -0,0 +1,1 @@
+  |  +1
+  |
+  o  4 a12
+     diff --git a/a b/a
+     new file mode 100644
+     --- /dev/null
+     +++ b/a
+     @@ -0,0 +1,3 @@
+     +1
+     +2
+     +3
+  
+
 Use revert to make the current change and its parent disappear.
 This should move us to the non-obsolete ancestor.