Patchwork [2,of,3] absorb: preserve branch-closing changesets even if empty

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

Comments

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

This makes the behavior consistent with 'hg commit', which allows to create
otherwise empty changesets if they close the branch. A lost branch closure can
inadvertently re-open a branch, so it should be preserved.

Patch

diff --git a/hgext/absorb.py b/hgext/absorb.py
--- a/hgext/absorb.py
+++ b/hgext/absorb.py
@@ -889,6 +889,8 @@ 
             pctx = parents[0]
         if ctx.branch() != pctx.branch():
             return False
+        if ctx.extra().get(b'close'):
+            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
@@ -553,3 +553,37 @@ 
       b |  0
       2 files changed, 1 insertions(+), 0 deletions(-)
   
+
+  $ cd ..
+  $ hg init repo7
+  $ cd repo7
+  $ echo a1 > a
+  $ touch b
+  $ hg commit -m a -A a b
+  $ echo b > b
+  $ hg commit -m foo --close-branch  # will become empty
+  $ echo c > c
+  $ hg commit -m reopen -A c -q
+  $ hg commit -m bar --close-branch  # is already empty
+  $ echo a2 > a
+  $ echo -n '' > b
+  $ hg absorb --apply-changes --verbose | grep became
+  0:0cde1ae39321: 1 file(s) changed, became 4:fc7fcdd90fdb
+  1:651b953d5764: 2 file(s) changed, became 5:0c9de988ecdc
+  2:76017bba73f6: 2 file(s) changed, became 6:d53ac896eb25
+  3:c7c1d67efc1d: 2 file(s) changed, became 7:66520267fe96
+  $ hg up null -q  # to make visible closed heads
+  $ hg log -T '{rev} {desc}\n' -G --stat
+  _  7 bar
+  |
+  o  6 reopen
+  |   c |  1 +
+  |   1 files changed, 1 insertions(+), 0 deletions(-)
+  |
+  _  5 foo
+  |
+  o  4 a
+      a |  1 +
+      b |  0
+      2 files changed, 1 insertions(+), 0 deletions(-)
+