Patchwork [3,of,3] absorb: preserve changesets which were already empty

login
register
mail settings
Submitter Manuel Jacob
Date June 16, 2020, 1:58 p.m.
Message ID <1312926add4e21cea220.1592315894@tmp>
Download mbox | patch
Permalink /patch/46522/
State Accepted
Headers show

Comments

Manuel Jacob - June 16, 2020, 1:58 p.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1591037834 -7200
#      Mon Jun 01 20:57:14 2020 +0200
# Node ID 1312926add4e21cea2200ba46e1af5468792f404
# Parent  9a645c5fcc8551cb95e62ce1c538a902f3b7a4ca
# EXP-Topic absorb-empty
absorb: preserve changesets which were already empty

Most commands in Mercurial (commit, rebase, absorb itself) don’t create empty
changesets or drop them if they become empty. If there’s a changeset that’s
empty, it must be a deliberate choice of the user. At least it shouldn’t be
absorb’s responsibility to prune them. The fact that changesets that became
empty during absorb are pruned, is unaffected by this.

This case was found while writing patches which make it possible to configure
absorb and rebase to not drop empty changesets. Even without having such config
set, I think it’s valuable to preserve changesets which were already empty.

Patch

diff --git a/hgext/absorb.py b/hgext/absorb.py
--- a/hgext/absorb.py
+++ b/hgext/absorb.py
@@ -782,7 +782,7 @@ 
                 # nothing changed, nothing commited
                 nextp1 = ctx
                 continue
-            if self._willbecomenoop(memworkingcopy, ctx, nextp1):
+            if ctx.files() and self._willbecomenoop(memworkingcopy, ctx, nextp1):
                 # changeset is no longer necessary
                 self.replacemap[ctx.node()] = None
                 msg = _(b'became empty and was dropped')
diff --git a/tests/test-absorb.t b/tests/test-absorb.t
--- a/tests/test-absorb.t
+++ b/tests/test-absorb.t
@@ -587,3 +587,21 @@ 
       b |  0
       2 files changed, 1 insertions(+), 0 deletions(-)
   
+
+  $ cd ..
+  $ hg init repo8
+  $ cd repo8
+  $ echo a1 > a
+  $ hg commit -m a -A a
+  $ hg commit -m empty --config ui.allowemptycommit=True
+  $ echo a2 > a
+  $ hg absorb --apply-changes --verbose | grep became
+  0:ecf99a8d6699: 1 file(s) changed, became 2:7e3ccf8e2fa5
+  1:97f72456ae0d: 1 file(s) changed, became 3:2df488325d6f
+  $ hg log -T '{rev} {desc}\n' -G --stat
+  @  3 empty
+  |
+  o  2 a
+      a |  1 +
+      1 files changed, 1 insertions(+), 0 deletions(-)
+