Patchwork D6582: abort: added support for histedit

login
register
mail settings
Submitter phabricator
Date July 4, 2019, 3 p.m.
Message ID <fb09a83ff705cb02490e98c6e5ad0a13@localhost.localdomain>
Download mbox | patch
Permalink /patch/40769/
State Not Applicable
Headers show

Comments

phabricator - July 4, 2019, 3 p.m.
taapas1128 edited the summary of this revision.
taapas1128 updated this revision to Diff 15754.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6582?vs=15735&id=15754

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6582/new/

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

AFFECTED FILES
  hgext/histedit.py
  tests/test-abort.t

CHANGE DETAILS




To: taapas1128, durin42, #hg-reviewers
Cc: pulkit, mercurial-devel

Patch

diff --git a/tests/test-abort.t b/tests/test-abort.t
--- a/tests/test-abort.t
+++ b/tests/test-abort.t
@@ -3,9 +3,12 @@ 
   > rebase=
   > shelve=
   > mq =
+  > histedit =
   > [phases]
   > publish=False
-  > 
+  > [experimental]
+  > evolution.createmarkers=True
+  > evolution.allowunstable=True
   > [alias]
   > tglog = log -G --template "{rev}:{phase} '{desc}' {branches}\n"
   > EOF
@@ -719,5 +722,257 @@ 
   unshelve of 'default' aborted
   $ cd ..
 
-
-
+####TEST `hg abort` operation histedit
+  $ cat >> $HGRCPATH << EOF
+  > [ui]
+  > logtemplate= {rev}:{node|short} ({phase}) {desc|firstline}\n
+  > EOF
+  $ hg init base
+  $ cd base
+
+  $ for x in a b c d e f ; do
+  >     echo $x > $x
+  >     hg add $x
+  >     hg ci -m $x
+  > done
+
+  $ hg log --graph
+  @  5:652413bf663e (draft) f
+  |
+  o  4:e860deea161a (draft) e
+  |
+  o  3:055a42cdd887 (draft) d
+  |
+  o  2:177f92b77385 (draft) c
+  |
+  o  1:d2ae7f538514 (draft) b
+  |
+  o  0:cb9a9f314b8b (draft) a
+  
+
+  $ HGEDITOR=cat hg histedit 1
+  pick d2ae7f538514 1 b
+  pick 177f92b77385 2 c
+  pick 055a42cdd887 3 d
+  pick e860deea161a 4 e
+  pick 652413bf663e 5 f
+  
+  # Edit history between d2ae7f538514 and 652413bf663e
+  #
+  # Commits are listed from least to most recent
+  #
+  # You can reorder changesets by reordering the lines
+  #
+  # Commands:
+  #
+  #  e, edit = use commit, but stop for amending
+  #  m, mess = edit commit message without changing commit content
+  #  p, pick = use commit
+  #  b, base = checkout changeset and apply further changesets from there
+  #  d, drop = remove commit from history
+  #  f, fold = use commit, but combine it with the one above
+  #  r, roll = like fold, but discard this commit's description and date
+  #
+  $ hg histedit 1 --commands - --verbose <<EOF | grep histedit
+  > pick 177f92b77385 2 c
+  > drop d2ae7f538514 1 b
+  > pick 055a42cdd887 3 d
+  > fold e860deea161a 4 e
+  > pick 652413bf663e 5 f
+  > EOF
+  [1]
+  $ hg log --graph --hidden
+  @  10:cacdfd884a93 (draft) f
+  |
+  o  9:59d9f330561f (draft) d
+  |
+  | x  8:b558abc46d09 (draft) fold-temp-revision e860deea161a
+  | |
+  | x  7:96e494a2d553 (draft) d
+  |/
+  o  6:b346ab9a313d (draft) c
+  |
+  | x  5:652413bf663e (draft) f
+  | |
+  | x  4:e860deea161a (draft) e
+  | |
+  | x  3:055a42cdd887 (draft) d
+  | |
+  | x  2:177f92b77385 (draft) c
+  | |
+  | x  1:d2ae7f538514 (draft) b
+  |/
+  o  0:cb9a9f314b8b (draft) a
+  
+  $ hg debugobsolete
+  d2ae7f538514cd87c17547b0de4cea71fe1af9fb 0 {cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b} (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '0', 'operation': 'histedit', 'user': 'test'}
+  177f92b773850b59254aa5e923436f921b55483b b346ab9a313db8537ecf96fca3ca3ca984ef3bd7 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '4', 'operation': 'histedit', 'user': 'test'}
+  055a42cdd88768532f9cf79daa407fc8d138de9b 59d9f330561fd6c88b1a6b32f0e45034d88db784 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '13', 'operation': 'histedit', 'user': 'test'}
+  e860deea161a2f77de56603b340ebbb4536308ae 59d9f330561fd6c88b1a6b32f0e45034d88db784 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '13', 'operation': 'histedit', 'user': 'test'}
+  652413bf663ef2a641cab26574e46d5f5a64a55a cacdfd884a9321ec4e1de275ef3949fa953a1f83 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '4', 'operation': 'histedit', 'user': 'test'}
+  96e494a2d553dd05902ba1cee1d94d4cb7b8faed 0 {b346ab9a313db8537ecf96fca3ca3ca984ef3bd7} (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '0', 'operation': 'histedit', 'user': 'test'}
+  b558abc46d09c30f57ac31e85a8a3d64d2e906e4 0 {96e494a2d553dd05902ba1cee1d94d4cb7b8faed} (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '0', 'operation': 'histedit', 'user': 'test'}
+
+Ensure hidden revision does not prevent histedit
+-------------------------------------------------
+
+create an hidden revision
+
+  $ hg histedit 6 --commands - << EOF
+  > pick b346ab9a313d 6 c
+  > drop 59d9f330561f 7 d
+  > pick cacdfd884a93 8 f
+  > EOF
+  $ hg log --graph
+  @  11:c13eb81022ca (draft) f
+  |
+  o  6:b346ab9a313d (draft) c
+  |
+  o  0:cb9a9f314b8b (draft) a
+  
+check hidden revision are ignored (6 have hidden children 7 and 8)
+
+  $ hg histedit 6 --commands - << EOF
+  > pick b346ab9a313d 6 c
+  > pick c13eb81022ca 8 f
+  > EOF
+
+Test phases support
+===========================================
+
+Check that histedit respect immutability
+-------------------------------------------
+
+  $ cat >> $HGRCPATH << EOF
+  > [ui]
+  > logtemplate= {rev}:{node|short} ({phase}) {desc|firstline}\n
+  > EOF
+
+  $ hg ph -pv '.^'
+  phase changed for 2 changesets
+  $ hg log -G
+  @  11:c13eb81022ca (draft) f
+  |
+  o  6:b346ab9a313d (public) c
+  |
+  o  0:cb9a9f314b8b (public) a
+  
+  $ hg histedit -r '.~2'
+  abort: cannot edit public changeset: cb9a9f314b8b
+  (see 'hg help phases' for details)
+  [255]
+
+Prepare further testing
+-------------------------------------------
+
+  $ for x in g h i j k ; do
+  >     echo $x > $x
+  >     hg add $x
+  >     hg ci -m $x
+  > done
+  $ hg phase --force --secret .~2
+  $ hg log -G
+  @  16:9760be57ca09 (secret) k
+  |
+  o  15:139d1fe0be2e (secret) j
+  |
+  o  14:5f3453928107 (secret) i
+  |
+  o  13:c205b3dc9a3c (draft) h
+  |
+  o  12:b7fead4e1227 (draft) g
+  |
+  o  11:c13eb81022ca (draft) f
+  |
+  o  6:b346ab9a313d (public) c
+  |
+  o  0:cb9a9f314b8b (public) a
+  
+
+  $ cd ..
+
+Check abort behavior
+-------------------------------------------
+
+We checks that abort properly clean the repository so the same histedit can be
+attempted later.
+  $ cd base
+  $ hg log -G
+  @  16:9760be57ca09 (secret) k
+  |
+  o  15:139d1fe0be2e (secret) j
+  |
+  o  14:5f3453928107 (secret) i
+  |
+  o  13:c205b3dc9a3c (draft) h
+  |
+  o  12:b7fead4e1227 (draft) g
+  |
+  o  11:c13eb81022ca (draft) f
+  |
+  o  6:b346ab9a313d (public) c
+  |
+  o  0:cb9a9f314b8b (public) a
+  
+  $ hg histedit -r 'c13eb81022ca' --commands - << EOF
+  > pick c13eb81022ca 13 f
+  > pick c205b3dc9a3c 15 h
+  > pick b7fead4e1227 14 g
+  > pick 5f3453928107 16 i
+  > roll 139d1fe0be2e 17 j
+  > edit 9760be57ca09 18 k
+  > EOF
+  Editing (9760be57ca09), you may commit or record as needed now.
+  (hg histedit --continue to resume)
+  [1]
+
+when in dry-run mode
+  $ hg abort --dry-run
+  aborting histedit
+
+when dry-run mode is used with no backup
+  $ hg abort --dry-run --no-backup
+  aborting histedit
+
+normal abort
+  $ hg abort
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  saved backup bundle to $TESTTMP/a/base/.hg/strip-backup/e5be0ec66c6b-5a90294a-backup.hg
+
+  $ hg log -G
+  @  16:9760be57ca09 (secret) k
+  |
+  o  15:139d1fe0be2e (secret) j
+  |
+  o  14:5f3453928107 (secret) i
+  |
+  o  13:c205b3dc9a3c (draft) h
+  |
+  o  12:b7fead4e1227 (draft) g
+  |
+  o  11:c13eb81022ca (draft) f
+  |
+  o  6:b346ab9a313d (public) c
+  |
+  o  0:cb9a9f314b8b (public) a
+  
+
+No-backup mode
+  $ hg histedit -r 'c13eb81022ca' --commands - << EOF
+  > pick c13eb81022ca 13 f
+  > pick c205b3dc9a3c 15 h
+  > pick b7fead4e1227 14 g
+  > pick 5f3453928107 16 i
+  > roll 139d1fe0be2e 17 j
+  > edit 9760be57ca09 18 k
+  > EOF
+  Editing (9760be57ca09), you may commit or record as needed now.
+  (hg histedit --continue to resume)
+  [1]
+  $ hg abort --no-backup
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+When no histedit is in progress
+  $ hg abort
+  abort: no operation in progress
+  [255]
diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -1919,6 +1919,18 @@ 
     finally:
             state.clear()
 
+def hgaborthistedit(ui, repo, **opts):
+    state = histeditstate(repo)
+    nobackup = False
+    if opts.get('no_backup'):
+        nobackup = True
+    if opts.get('dry_run'):
+        return 0
+    with repo.wlock() as wlock, repo.lock() as lock:
+        state.wlock = wlock
+        state.lock = lock
+        _aborthistedit(ui, repo, state, nobackup=nobackup)
+
 def _edithisteditplan(ui, repo, state, rules):
     state.read()
     if not rules:
@@ -2314,5 +2326,5 @@ 
 def extsetup(ui):
     cmdutil.summaryhooks.add('histedit', summaryhook)
     statemod.addunfinished('histedit', fname='histedit-state', allowcommit=True,
-                            continueflag=True)
-
+                            continueflag=True, abortfunc=hgaborthistedit)
+