D5021: absorb: prompt user to accept absorb changes by default

mbthomas (Mark Thomas) phabricator at mercurial-scm.org
Fri Oct 12 17:50:26 UTC 2018


mbthomas created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Change the default absorb behaviour to print the changes out and then prompt
  the user if they want to absorb the changes or not.
  
  Providing the `-p` option still prints the result and exits.  A new `-a` option
  is provided which applies the changes without printing them, giving the
  equivalent of the old behaviour.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/absorb.py
  tests/test-absorb-edit-lines.t
  tests/test-absorb-phase.t
  tests/test-absorb-rename.t
  tests/test-absorb-strip.t
  tests/test-absorb.t

CHANGE DETAILS

diff --git a/tests/test-absorb.t b/tests/test-absorb.t
--- a/tests/test-absorb.t
+++ b/tests/test-absorb.t
@@ -68,7 +68,7 @@
 
 Run absorb:
 
-  $ hg absorb
+  $ hg absorb --apply-changes
   saved backup bundle to * (glob)
   2 of 2 chunk(s) applied
   $ hg annotate a
@@ -84,7 +84,20 @@
   > 2b
   > 4d
   > EOF
-  $ hg absorb
+  $ echo y | hg absorb --config ui.interactive=1
+  showing changes for a
+          @@ -0,1 +0,0 @@
+  f548282 -1a
+          @@ -2,1 +1,0 @@
+  ff5d556 -3
+          @@ -4,1 +2,0 @@
+  84e5416 -5e
+  
+  3 changesets affected
+  84e5416 commit 5
+  ff5d556 commit 3
+  f548282 commit 1
+  apply changes (yn)?  y
   saved backup bundle to * (glob)
   3 of 3 chunk(s) applied
   $ hg annotate a
@@ -112,7 +125,7 @@
 Non 1:1 map changes will be ignored:
 
   $ echo 1 > a
-  $ hg absorb
+  $ hg absorb --apply-changes
   nothing applied
   [1]
 
@@ -124,7 +137,7 @@
   > 4d
   > insert aftert 4d
   > EOF
-  $ hg absorb -q
+  $ hg absorb -q --apply-changes
   $ hg status
   $ hg annotate a
   1: insert before 2b
@@ -142,7 +155,7 @@
      b2                        2:946e4bc87915
    * ba                        2:946e4bc87915
   $ sedi 's/insert/INSERT/' a
-  $ hg absorb -q
+  $ hg absorb -q --apply-changes
   $ hg status
   $ hg bookmarks
      b1                        1:a4183e9b3d31
@@ -156,11 +169,11 @@
   $ touch c
   $ hg add c
   $ hg rm b
-  $ hg absorb
+  $ hg absorb --apply-changes
   nothing applied
   [1]
   $ sedi 's/INSERT/Insert/' a
-  $ hg absorb
+  $ hg absorb --apply-changes
   saved backup bundle to * (glob)
   2 of 2 chunk(s) applied
   $ hg status
@@ -182,7 +195,7 @@
   
   1 changesets affected
   85b4e0e commit 4
-  $ hg absorb
+  $ hg absorb --apply-changes
   saved backup bundle to * (glob)
   1 of 2 chunk(s) applied
   $ hg diff -U 0
@@ -233,7 +246,7 @@
   
   $ echo 2 >> m1
   $ echo 2 >> m2
-  $ hg absorb
+  $ hg absorb --apply-changes
   abort: no mutable changeset to change
   [255]
   $ hg revert -q -C m1 m2
@@ -259,15 +272,15 @@
   $ hg status
   M a
   M b
-  $ hg absorb a
+  $ hg absorb --apply-changes a
   saved backup bundle to * (glob)
   1 of 1 chunk(s) applied
   $ hg status
   M b
-  $ hg absorb --exclude b
+  $ hg absorb --apply-changes --exclude b
   nothing applied
   [1]
-  $ hg absorb b
+  $ hg absorb --apply-changes b
   saved backup bundle to * (glob)
   1 of 1 chunk(s) applied
   $ hg status
@@ -312,15 +325,15 @@
   > add-noise=1
   > EOF
 
-  $ hg --config absorb.max-stack-size=3 absorb
+  $ hg --config absorb.max-stack-size=3 absorb -a
   absorb: only the recent 3 changesets will be analysed
   2 of 2 chunk(s) applied
   $ hg log -T '{rev}:{node|short} {desc} {get(extras, "absorb_source")}\n'
   6:3dfde4199b46 commit b 2 712d16a8f445834e36145408eabc1d29df05ec09
   5:99cfab7da5ff commit b 1 74cfa6294160149d60adbf7582b99ce37a4597ec
   4:fec2b3bd9e08 commit a 2 28f10dcf96158f84985358a2e5d5b3505ca69c22
   0:f9a81da8dc53 commit a 1 
-  $ hg absorb
+  $ hg absorb --apply-changes
   1 of 1 chunk(s) applied
   $ hg log -T '{rev}:{node|short} {desc} {get(extras, "absorb_source")}\n'
   10:e1c8c1e030a4 commit b 2 3dfde4199b4610ea6e3c6fa9f5bdad8939d69524
@@ -367,7 +380,7 @@
   
   1 changesets affected
   99b4ae7 foo
-  $ hg absorb
+  $ hg absorb --apply-changes
   1 of 1 chunk(s) applied
   $ hg diff -c .
   diff --git a/foo.py b/foo.py
@@ -414,7 +427,7 @@
   30970db b3
   1154859 b12
   bfafb49 a12
-  $ hg absorb -v | grep became
+  $ hg absorb -av | grep became
   0:bfafb49242db: 1 file(s) changed, became 4:1a2de97fc652
   1:115485984805: 2 file(s) changed, became 5:0c930dfab74c
   2:30970dbf7b40: became empty and was dropped
@@ -468,7 +481,7 @@
   2 changesets affected
   82dbe7f a1234
   f1c23dd a123
-  $ hg absorb --verbose
+  $ hg absorb --apply-changes --verbose
   1:f1c23dd5d08d: became empty and was dropped
   2:82dbe7fd19f0: became empty and was dropped
   a: 1 of 1 chunk(s) applied
diff --git a/tests/test-absorb-strip.t b/tests/test-absorb-strip.t
--- a/tests/test-absorb-strip.t
+++ b/tests/test-absorb-strip.t
@@ -22,7 +22,7 @@
   $ hg up E -q
   $ echo 1 >> B
   $ echo 2 >> D
-  $ hg absorb
+  $ hg absorb -a
   saved backup bundle to * (glob)
   2 of 2 chunk(s) applied
 
diff --git a/tests/test-absorb-rename.t b/tests/test-absorb-rename.t
--- a/tests/test-absorb-rename.t
+++ b/tests/test-absorb-rename.t
@@ -34,7 +34,7 @@
   2 0b888b00216c a: 3
 
   $ sedi 's/$/a/' a
-  $ hg absorb -pq
+  $ hg absorb -apq
   showing changes for a
           @@ -0,3 +0,3 @@
   eff892d -1
@@ -62,7 +62,7 @@
 
   $ sedi 's/a/A/' a
 
-  $ hg absorb -pq
+  $ hg absorb -apq
   showing changes for a
           @@ -0,3 +0,3 @@
           -1a
@@ -105,7 +105,7 @@
   $ sedi 's/$/a/' a
   $ sedi 's/$/b/' b
 
-  $ hg absorb -pq
+  $ hg absorb -apq
   showing changes for a
           @@ -0,1 +0,1 @@
   eff892d -1
@@ -149,7 +149,7 @@
   $ sedi 's/$/a/' a
   $ sedi 's/$/a/' b
 
-  $ hg absorb -pq
+  $ hg absorb -apq
   showing changes for a
           @@ -0,2 +0,2 @@
           -1
@@ -196,7 +196,7 @@
   $ sedi 's/$/a/' a
   $ sedi 's/$/c/' c
 
-  $ hg absorb -pq
+  $ hg absorb -apq
   showing changes for a
           @@ -0,2 +0,2 @@
   55105f9 -1
@@ -244,7 +244,7 @@
   
 run absorb again would apply the change to c
 
-  $ hg absorb -pq
+  $ hg absorb -apq
   showing changes for c
           @@ -0,1 +0,1 @@
   7060601 -1
@@ -309,7 +309,7 @@
   $ sedi 's/$/e/' e
   $ sedi 's/$/d/' d
 
-  $ hg absorb -pq
+  $ hg absorb -apq
   showing changes for d
           @@ -0,2 +0,2 @@
   55105f9 -1
diff --git a/tests/test-absorb-phase.t b/tests/test-absorb-phase.t
--- a/tests/test-absorb-phase.t
+++ b/tests/test-absorb-phase.t
@@ -19,7 +19,7 @@
   $ hg update C -q
   $ printf B1 > B
 
-  $ hg absorb -q
+  $ hg absorb -aq
 
   $ hg log -G -T '{desc} {phase}'
   @  C secret
diff --git a/tests/test-absorb-edit-lines.t b/tests/test-absorb-edit-lines.t
--- a/tests/test-absorb-edit-lines.t
+++ b/tests/test-absorb-edit-lines.t
@@ -15,10 +15,10 @@
 
 absorb --edit-lines will run the editor if filename is provided:
 
-  $ hg absorb --edit-lines
+  $ hg absorb --edit-lines --apply-changes
   nothing applied
   [1]
-  $ HGEDITOR=cat hg absorb --edit-lines a
+  $ HGEDITOR=cat hg absorb --edit-lines --apply-changes a
   HG: editing a
   HG: "y" means the line to the right exists in the changeset to the top
   HG:
@@ -43,7 +43,7 @@
   >     y   : f
   >     yyy : g
   > EOF
-  $ HGEDITOR='cat editortext >' hg absorb -q --edit-lines a
+  $ HGEDITOR='cat editortext >' hg absorb -q --edit-lines --apply-changes a
   $ hg cat -r 0 a
   d  
   e
diff --git a/hgext/absorb.py b/hgext/absorb.py
--- a/hgext/absorb.py
+++ b/hgext/absorb.py
@@ -952,7 +952,7 @@
         chunks = cmdutil.recordfilter(ui, origchunks)[0]
         targetctx = overlaydiffcontext(stack[-1], chunks)
     fm = None
-    if opts.get('print_changes'):
+    if opts.get('print_changes') or not opts.get('apply_changes'):
         fm = ui.formatter('absorb', opts)
     state.diffwith(targetctx, matcher, fm)
     if fm is not None:
@@ -971,16 +971,22 @@
                      label='absorb.description')
         fm.end()
     if not opts.get('dry_run'):
+        if not opts.get('apply_changes'):
+            if ui.promptchoice("apply changes (yn)? $$ &Yes $$ &No", default=1):
+                raise error.Abort(_('absorb cancelled\n'))
+
         state.apply()
         if state.commit():
             state.printchunkstats()
         elif not ui.quiet:
             ui.write(_('nothing applied\n'))
     return state
 
 @command('^absorb',
-         [('p', 'print-changes', None,
-           _('print which changesets are modified by which changes')),
+         [('a', 'apply-changes', None,
+           _('apply changes without prompting for confirmation')),
+          ('p', 'print-changes', None,
+           _('just print which changesets are modified by which changes')),
           ('i', 'interactive', None,
            _('interactively select which chunks to apply (EXPERIMENTAL)')),
           ('e', 'edit-lines', None,



To: mbthomas, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list