Patchwork [1,of,3] absorb: preserve branch-changing changesets even if empty

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

Comments

Manuel Jacob - June 16, 2020, 1:58 p.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1591000380 -7200
#      Mon Jun 01 10:33:00 2020 +0200
# Node ID 658889a51a83ba348575179ec210bd7a40f79ff0
# Parent  ef8dcee272acbe22af5829e31c55b694f345ceba
# EXP-Topic absorb-empty
absorb: preserve branch-changing changesets even if empty

This makes the behavior consistent with 'hg commit', which allows to create
otherwise empty changesets if the branch changes compared to the parent. A
branch change can denote important information, so it should be preserved.
Yuya Nishihara - June 17, 2020, 11:36 a.m.
On Tue, 16 Jun 2020 15:58:12 +0200, Manuel Jacob wrote:
> # HG changeset patch
> # User Manuel Jacob <me@manueljacob.de>
> # Date 1591000380 -7200
> #      Mon Jun 01 10:33:00 2020 +0200
> # Node ID 658889a51a83ba348575179ec210bd7a40f79ff0
> # Parent  ef8dcee272acbe22af5829e31c55b694f345ceba
> # EXP-Topic absorb-empty
> absorb: preserve branch-changing changesets even if empty

Queued, thanks.

Patch

diff --git a/hgext/absorb.py b/hgext/absorb.py
--- a/hgext/absorb.py
+++ b/hgext/absorb.py
@@ -887,6 +887,8 @@ 
             if len(parents) != 1:
                 return False
             pctx = parents[0]
+        if ctx.branch() != pctx.branch():
+            return False
         # ctx changes more files (not a subset of memworkingcopy)
         if not set(ctx.files()).issubset(set(memworkingcopy)):
             return False
diff --git a/tests/test-absorb.t b/tests/test-absorb.t
--- a/tests/test-absorb.t
+++ b/tests/test-absorb.t
@@ -525,3 +525,31 @@ 
   a: 1 of 1 chunk(s) applied
   $ hg id
   bfafb49242db tip
+
+  $ cd ..
+  $ hg init repo6
+  $ cd repo6
+  $ echo a1 > a
+  $ touch b
+  $ hg commit -m a -A a b
+  $ hg branch foo -q
+  $ echo b > b
+  $ hg commit -m foo  # will become empty
+  $ hg branch bar -q
+  $ hg commit -m bar  # is already empty
+  $ echo a2 > a
+  $ echo -n '' > 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
+  |
+  o  4 (branch: foo) foo
+  |
+  o  3 (branch: default) a
+      a |  1 +
+      b |  0
+      2 files changed, 1 insertions(+), 0 deletions(-)
+