D6582: abort: added support for histedit
taapas1128 (Taapas Agrawal)
phabricator at mercurial-scm.org
Thu Jun 27 19:14:53 UTC 2019
taapas1128 created this revision.
Herald added a reviewer: durin42.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
This patch adds the support for histedit in `hg abort` plan.
`_aborthistedit()` has been modified for independent calls.
Results are shown as tests.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D6582
AFFECTED FILES
hgext/histedit.py
tests/test-abort.t
CHANGE DETAILS
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
@@ -669,5 +672,233 @@
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]
+
+ $ 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
+
+
+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
@@ -1886,38 +1886,41 @@
if repo.vfs.exists('histedit-last-edit.txt'):
repo.vfs.unlink('histedit-last-edit.txt')
-def _aborthistedit(ui, repo, state, nobackup=False):
- try:
- state.read()
- __, leafs, tmpnodes, __ = processreplacement(state)
- ui.debug('restore wc to old parent %s\n'
- % node.short(state.topmost))
-
- # Recover our old commits if necessary
- if not state.topmost in repo and state.backupfile:
- backupfile = repo.vfs.join(state.backupfile)
- f = hg.openpath(ui, backupfile)
- gen = exchange.readbundle(ui, f, backupfile)
- with repo.transaction('histedit.abort') as tr:
- bundle2.applybundle(repo, gen, tr, source='histedit',
- url='bundle:' + backupfile)
-
- os.remove(backupfile)
-
- # check whether we should update away
- if repo.unfiltered().revs('parents() and (%n or %ln::)',
- state.parentctxnode, leafs | tmpnodes):
- hg.clean(repo, state.topmost, show_stats=True, quietempty=True)
- cleanupnode(ui, repo, tmpnodes, nobackup=nobackup)
- cleanupnode(ui, repo, leafs, nobackup=nobackup)
- except Exception:
- if state.inprogress():
- ui.warn(_('warning: encountered an exception during histedit '
- '--abort; the repository may not have been completely '
- 'cleaned up\n'))
- raise
- finally:
- state.clear()
+def _aborthistedit(ui, repo, state=None, nobackup=False):
+ if not state:
+ state = histeditstate(repo)
+ with repo.wlock(), repo.lock():
+ try:
+ state.read()
+ __, leafs, tmpnodes, __ = processreplacement(state)
+ ui.debug('restore wc to old parent %s\n'
+ % node.short(state.topmost))
+
+ # Recover our old commits if necessary
+ if not state.topmost in repo and state.backupfile:
+ backupfile = repo.vfs.join(state.backupfile)
+ f = hg.openpath(ui, backupfile)
+ gen = exchange.readbundle(ui, f, backupfile)
+ with repo.transaction('histedit.abort') as tr:
+ bundle2.applybundle(repo, gen, tr, source='histedit',
+ url='bundle:' + backupfile)
+
+ os.remove(backupfile)
+
+ # check whether we should update away
+ if repo.unfiltered().revs('parents() and (%n or %ln::)',
+ state.parentctxnode, leafs | tmpnodes):
+ hg.clean(repo, state.topmost, show_stats=True, quietempty=True)
+ cleanupnode(ui, repo, tmpnodes, nobackup=nobackup)
+ cleanupnode(ui, repo, leafs, nobackup=nobackup)
+ except Exception:
+ if state.inprogress():
+ ui.warn(_('warning: encountered an exception during histedit '
+ '--abort; the repository may not have been completely '
+ 'cleaned up\n'))
+ raise
+ finally:
+ state.clear()
def _edithisteditplan(ui, repo, state, rules):
state.read()
@@ -2314,5 +2317,5 @@
def extsetup(ui):
cmdutil.summaryhooks.add('histedit', summaryhook)
statemod.addunfinished('histedit', fname='histedit-state', allowcommit=True,
- continueflag=True)
-
+ continueflag=True, abortfunc=_aborthistedit)
+
To: taapas1128, durin42, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list