Mercurial > hg
view tests/test-histedit-no-change.t @ 26750:9f9ec4abe700
cmdutil: make in-memory changes visible to external editor (issue4378)
Before this patch, external editor process for the commit log can't
view some in-memory changes (especially, of dirstate), because they
aren't written out until the end of transaction (or wlock).
This causes unexpected output of Mercurial commands spawned from that
editor process.
To make in-memory changes visible to external editor process, this
patch does:
- write (or schedule to write) in-memory dirstate changes, and
- set HG_PENDING environment variable, if:
- a transaction is running, and
- there are in-memory changes to be visible
"hg diff" spawned from external editor process for "hg qrefresh"
shows:
- "changes newly imported into the topmost" before 49148d7868df(*)
- "all changes recorded in the topmost by refreshing" after this patch
(*) 49148d7868df changed steps invoking editor process
Even though backward compatibility may be broken, the latter behavior
looks reasonable, because "hg diff" spawned from the editor process
consistently shows "what changes new revision records" regardless of
invocation context.
In fact, issue4378 itself should be resolved by 800e090e9c64, which
made 'repo.transaction()' write in-memory dirstate changes out
explicitly before starting transaction. It also made "hg qrefresh"
imply 'dirstate.write()' before external editor invocation in call
chain below.
- mq.queue.refresh
- strip.strip
- repair.strip
- localrepository.transaction
- dirstate.write
- localrepository.commit
- invoke external editor
Though, this patch has '(issue4378)' in own summary line to indicate
that issues like issue4378 should be fixed by this.
BTW, this patch adds '-m' option to a 'hg ci --amend' execution in
'test-commit-amend.t', to avoid invoking external editor process.
In this case, "unsure" states may be changed to "clean" according to
timestamp or so on. These changes should be written into pending file,
if external editor invocation is required,
Then, writing dirstate changes out breaks stability of test, because
it shows "transaction abort!/rollback completed" occasionally.
Aborting after editor process invocation while commands below may
cause similar instability of tests, too (AFAIK, there is no more such
one, at this revision)
- commit --amend
- without --message/--logfile
- import
- without --message/--logfile,
- without --no-commit,
- without --bypass,
- one of below, and
- patch has no description text, or
- with --edit
- aborting at the 1st patch, which adds or removes file(s)
- if it only changes existing files, status is checked only for
changed files by 'scmutil.matchfiles()', and transition from
"unsure" to "normal" in dirstate doesn't occur (= dirstate
isn't changed, and written out)
- aborting at the 2nd or later patch implies other pending
changes (e.g. changelog), and always causes showing
"transaction abort!/rollback completed"
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sat, 17 Oct 2015 01:15:34 +0900 |
parents | 6084926366b9 |
children | 890273343170 |
line wrap: on
line source
test for old histedit issue #6: editing a changeset without any actual change would corrupt the repository $ . "$TESTDIR/histedit-helpers.sh" $ cat >> $HGRCPATH <<EOF > [extensions] > histedit= > EOF $ initrepo () > { > dir="$1" > comment="$2" > if [ -n "${comment}" ]; then > echo % ${comment} > echo % ${comment} | sed 's:.:-:g' > fi > hg init ${dir} > cd ${dir} > for x in a b c d e f ; do > echo $x > $x > hg add $x > hg ci -m $x > done > cd .. > } $ geneditor () > { > # generate an editor script for selecting changesets to be edited > choice=$1 # changesets that should be edited (using sed line ranges) > cat <<EOF | sed 's:^....::' > # editing the rules, replacing 'pick' with 'edit' for the chosen lines > sed '${choice}s:^pick:edit:' "\$1" > "\${1}.tmp" > mv "\${1}.tmp" "\$1" > # displaying the resulting rules, minus comments and empty lines > sed '/^#/d;/^$/d;s:^:| :' "\$1" >&2 > EOF > } $ startediting () > { > # begin an editing session > choice="$1" # changesets that should be edited > number="$2" # number of changesets considered (from tip) > comment="$3" > geneditor "${choice}" > edit.sh > echo % start editing the history ${comment} > HGEDITOR="sh ./edit.sh" hg histedit -- -${number} 2>&1 | fixbundle > } $ continueediting () > { > # continue an edit already in progress > editor="$1" # message editor when finalizing editing > comment="$2" > echo % finalize changeset editing ${comment} > HGEDITOR=${editor} hg histedit --continue 2>&1 | fixbundle > } $ graphlog () > { > comment="${1:-log}" > echo % "${comment}" > hg log -G --template '{rev} {node} \"{desc|firstline}\"\n' > } $ initrepo r1 "test editing with no change" % test editing with no change ----------------------------- $ cd r1 $ graphlog "log before editing" % log before editing @ 5 652413bf663ef2a641cab26574e46d5f5a64a55a "f" | o 4 e860deea161a2f77de56603b340ebbb4536308ae "e" | o 3 055a42cdd88768532f9cf79daa407fc8d138de9b "d" | o 2 177f92b773850b59254aa5e923436f921b55483b "c" | o 1 d2ae7f538514cd87c17547b0de4cea71fe1af9fb "b" | o 0 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b "a" $ startediting 2 3 "(not changing anything)" # edit the 2nd of 3 changesets % start editing the history (not changing anything) | pick 055a42cdd887 3 d | edit e860deea161a 4 e | pick 652413bf663e 5 f 0 files updated, 0 files merged, 2 files removed, 0 files unresolved Make changes as needed, you may commit or record as needed now. When you are finished, run hg histedit --continue to resume. $ continueediting true "(leaving commit message unaltered)" % finalize changeset editing (leaving commit message unaltered) 0 files updated, 0 files merged, 0 files removed, 0 files unresolved 0 files updated, 0 files merged, 0 files removed, 0 files unresolved check state of working copy $ hg id 794fe033d0a0 tip $ graphlog "log after history editing" % log after history editing @ 5 794fe033d0a030f8df77c5de945fca35c9181c30 "f" | o 4 04d2fab980779f332dec458cc944f28de8b43435 "e" | o 3 055a42cdd88768532f9cf79daa407fc8d138de9b "d" | o 2 177f92b773850b59254aa5e923436f921b55483b "c" | o 1 d2ae7f538514cd87c17547b0de4cea71fe1af9fb "b" | o 0 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b "a" $ cd .. $ initrepo r2 "test editing with no change, then abort" % test editing with no change, then abort ----------------------------------------- $ cd r2 $ graphlog "log before editing" % log before editing @ 5 652413bf663ef2a641cab26574e46d5f5a64a55a "f" | o 4 e860deea161a2f77de56603b340ebbb4536308ae "e" | o 3 055a42cdd88768532f9cf79daa407fc8d138de9b "d" | o 2 177f92b773850b59254aa5e923436f921b55483b "c" | o 1 d2ae7f538514cd87c17547b0de4cea71fe1af9fb "b" | o 0 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b "a" $ startediting 1,2 3 "(not changing anything)" # edit the 1st two of 3 changesets % start editing the history (not changing anything) | edit 055a42cdd887 3 d | edit e860deea161a 4 e | pick 652413bf663e 5 f 0 files updated, 0 files merged, 3 files removed, 0 files unresolved Make changes as needed, you may commit or record as needed now. When you are finished, run hg histedit --continue to resume. $ continueediting true "(leaving commit message unaltered)" % finalize changeset editing (leaving commit message unaltered) 0 files updated, 0 files merged, 0 files removed, 0 files unresolved Make changes as needed, you may commit or record as needed now. When you are finished, run hg histedit --continue to resume. $ graphlog "log after first edit" % log after first edit @ 6 e5ae3ca2f1ffdbd89ec41ebc273a231f7c3022f2 "d" | | o 5 652413bf663ef2a641cab26574e46d5f5a64a55a "f" | | | o 4 e860deea161a2f77de56603b340ebbb4536308ae "e" | | | o 3 055a42cdd88768532f9cf79daa407fc8d138de9b "d" |/ o 2 177f92b773850b59254aa5e923436f921b55483b "c" | o 1 d2ae7f538514cd87c17547b0de4cea71fe1af9fb "b" | o 0 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b "a" abort editing session, after first forcibly updating away $ hg up 0 abort: histedit in progress (use 'hg histedit --continue' or 'hg histedit --abort') [255] $ mv .hg/histedit-state .hg/histedit-state-ignore $ hg up 0 0 files updated, 0 files merged, 3 files removed, 0 files unresolved $ mv .hg/histedit-state-ignore .hg/histedit-state $ hg sum parent: 0:cb9a9f314b8b a branch: default commit: 1 added, 1 unknown (new branch head) update: 6 new changesets (update) phases: 7 draft hist: 2 remaining (histedit --continue) $ hg histedit --abort 2>&1 | fixbundle [1] modified files should survive the abort when we've moved away already $ hg st A e ? edit.sh $ graphlog "log after abort" % log after abort o 5 652413bf663ef2a641cab26574e46d5f5a64a55a "f" | o 4 e860deea161a2f77de56603b340ebbb4536308ae "e" | o 3 055a42cdd88768532f9cf79daa407fc8d138de9b "d" | o 2 177f92b773850b59254aa5e923436f921b55483b "c" | o 1 d2ae7f538514cd87c17547b0de4cea71fe1af9fb "b" | @ 0 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b "a" $ cd ..