Mercurial > hg
changeset 39405:cb70501d8b71
revert: fix the inconsistency of status msgs in --interactive mode
Before this patch we were priting every action msg before actually
performing that action and that was resulting in inconsistencies;
like in --interactive session if user decided to not revert any
changes in a file foo, still there will be a msg on console saying
"reverting foo".
To fix this, I have made some changes to print status msg just
before the action it is going to perform, no matter if --interactive
or not.
Changes made in test-revert-interactive.t reflect the changed behavior.
There are also some changes in test-revert.t because of change in the
order of messages.
Differential Revision: https://phab.mercurial-scm.org/D4380
author | Sushil khanchi <sushilkhanchi97@gmail.com> |
---|---|
date | Fri, 31 Aug 2018 23:28:09 +0530 |
parents | 90afd61ef8a2 |
children | b3572f733dbd |
files | mercurial/cmdutil.py tests/test-backout.t tests/test-confused-revert.t tests/test-fileset-generated.t tests/test-import-git.t tests/test-import.t tests/test-issue660.t tests/test-largefiles-misc.t tests/test-largefiles.t tests/test-lfs-test-server.t tests/test-merge-remove.t tests/test-revert-interactive.t tests/test-revert.t |
diffstat | 13 files changed, 100 insertions(+), 84 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Mon Sep 03 10:44:52 2018 +0530 +++ b/mercurial/cmdutil.py Fri Aug 31 23:28:09 2018 +0530 @@ -3019,8 +3019,9 @@ util.copyfile(target, bakname) else: util.rename(target, bakname) - if ui.verbose or not exact: - ui.status(msg % rel) + if opts.get('dry_run'): + if ui.verbose or not exact: + ui.status(msg % rel) elif exact: ui.warn(msg % rel) break @@ -3033,7 +3034,8 @@ prefetch(repo, [ctx.rev()], matchfiles(repo, [f for sublist in oplist for f in sublist])) - _performrevert(repo, parents, ctx, actions, interactive, tobackup) + _performrevert(repo, parents, ctx, names, actions, interactive, + tobackup) if targetsubs: # Revert the subrepos on the revert list @@ -3045,7 +3047,7 @@ raise error.Abort("subrepository '%s' does not exist in %s!" % (sub, short(ctx.node()))) -def _performrevert(repo, parents, ctx, actions, interactive=False, +def _performrevert(repo, parents, ctx, names, actions, interactive=False, tobackup=None): """function that actually perform all the actions computed for revert @@ -3070,16 +3072,23 @@ pass repo.dirstate.remove(f) + def prntstatusmsg(action, f): + rel, exact = names[f] + if repo.ui.verbose or not exact: + repo.ui.status(actions[action][1] % rel) + audit_path = pathutil.pathauditor(repo.root, cached=True) for f in actions['forget'][0]: if interactive: choice = repo.ui.promptchoice( _("forget added file %s (Yn)?$$ &Yes $$ &No") % f) if choice == 0: + prntstatusmsg('forget', f) repo.dirstate.drop(f) else: excluded_files.append(f) else: + prntstatusmsg('forget', f) repo.dirstate.drop(f) for f in actions['remove'][0]: audit_path(f) @@ -3087,13 +3096,16 @@ choice = repo.ui.promptchoice( _("remove added file %s (Yn)?$$ &Yes $$ &No") % f) if choice == 0: + prntstatusmsg('remove', f) doremove(f) else: excluded_files.append(f) else: + prntstatusmsg('remove', f) doremove(f) for f in actions['drop'][0]: audit_path(f) + prntstatusmsg('drop', f) repo.dirstate.remove(f) normal = None @@ -3140,14 +3152,21 @@ tobackup = set() # Apply changes fp = stringio() + # `fnames` keeps track of filenames for which we have initiated changes, + # to make sure that we print status msg only once per file. + fnames = set() for c in chunks: - # Create a backup file only if this hunk should be backed up - if ishunk(c) and c.header.filename() in tobackup: + if ishunk(c): abs = c.header.filename() - target = repo.wjoin(abs) - bakname = scmutil.origpath(repo.ui, repo, m.rel(abs)) - util.copyfile(target, bakname) - tobackup.remove(abs) + if abs not in fnames: + fnames.add(abs) + prntstatusmsg('revert', abs) + # Create a backup file only if this hunk should be backed up + if c.header.filename() in tobackup: + target = repo.wjoin(abs) + bakname = scmutil.origpath(repo.ui, repo, m.rel(abs)) + util.copyfile(target, bakname) + tobackup.remove(abs) c.write(fp) dopatch = fp.tell() fp.seek(0) @@ -3159,6 +3178,7 @@ del fp else: for f in actions['revert'][0]: + prntstatusmsg('revert', f) checkout(f) if normal: normal(f) @@ -3166,6 +3186,7 @@ for f in actions['add'][0]: # Don't checkout modified files, they are already created by the diff if f not in newlyaddedandmodifiedfiles: + prntstatusmsg('add', f) checkout(f) repo.dirstate.add(f) @@ -3173,6 +3194,7 @@ if node == parent and p2 == nullid: normal = repo.dirstate.normal for f in actions['undelete'][0]: + prntstatusmsg('undelete', f) checkout(f) normal(f)
--- a/tests/test-backout.t Mon Sep 03 10:44:52 2018 +0530 +++ b/tests/test-backout.t Fri Aug 31 23:28:09 2018 +0530 @@ -147,8 +147,8 @@ $ hg debugstate --nodates n 644 12 set c $ hg backout -d '6 0' -m 'to be rollback-ed soon' -r . + removing c adding b - removing c changeset 6:4bfec048029d backs out changeset 5:fac0b729a654 $ hg rollback -q $ hg status -A
--- a/tests/test-confused-revert.t Mon Sep 03 10:44:52 2018 +0530 +++ b/tests/test-confused-revert.t Fri Aug 31 23:28:09 2018 +0530 @@ -14,8 +14,8 @@ R a $ hg revert --all + forgetting b undeleting a - forgetting b Should show b unknown and a back to normal: @@ -66,8 +66,8 @@ Revert should be ok now: $ hg revert -r2 --all + forgetting b undeleting a - forgetting b Should show b unknown and a marked modified (merged):
--- a/tests/test-fileset-generated.t Mon Sep 03 10:44:52 2018 +0530 +++ b/tests/test-fileset-generated.t Fri Aug 31 23:28:09 2018 +0530 @@ -187,11 +187,11 @@ undeleting missing_content2_missing-untracked $ hg revert 'set:deleted()' + forgetting content1_missing_missing-tracked + forgetting missing_missing_missing-tracked reverting content1_content1_missing-tracked reverting content1_content2_missing-tracked - forgetting content1_missing_missing-tracked reverting missing_content2_missing-tracked - forgetting missing_missing_missing-tracked $ hg revert 'set:unknown()'
--- a/tests/test-import-git.t Mon Sep 03 10:44:52 2018 +0530 +++ b/tests/test-import-git.t Fri Aug 31 23:28:09 2018 +0530 @@ -615,8 +615,8 @@ Prefix with strip, renames, creates etc $ hg revert -aC + forgetting b undeleting a - forgetting b $ rm b $ mkdir -p dir/dir2 $ echo b > dir/dir2/b @@ -715,10 +715,10 @@ $ hg revert -aC forgetting dir/a + forgetting dir/dir2/b2 + reverting dir/dir2/c undeleting dir/d undeleting dir/dir2/b - forgetting dir/dir2/b2 - reverting dir/dir2/c $ rm dir/a dir/dir2/b2 $ hg import --similarity 90 --no-commit - <<EOF > diff --git a/a b/b
--- a/tests/test-import.t Mon Sep 03 10:44:52 2018 +0530 +++ b/tests/test-import.t Fri Aug 31 23:28:09 2018 +0530 @@ -1014,8 +1014,8 @@ a R a $ hg revert -a + forgetting b undeleting a - forgetting b $ cat b mod b $ rm b
--- a/tests/test-issue660.t Mon Sep 03 10:44:52 2018 +0530 +++ b/tests/test-issue660.t Fri Aug 31 23:28:09 2018 +0530 @@ -66,9 +66,9 @@ Revert all - should succeed: $ hg revert --all - undeleting a forgetting a/a forgetting b + undeleting a undeleting b/b $ hg st
--- a/tests/test-largefiles-misc.t Mon Sep 03 10:44:52 2018 +0530 +++ b/tests/test-largefiles-misc.t Fri Aug 31 23:28:09 2018 +0530 @@ -1135,8 +1135,8 @@ ? large.orig $ hg revert --all + forgetting .hglf/dir/subdir2/large.bin undeleting .hglf/dir/subdir/large.bin - forgetting .hglf/dir/subdir2/large.bin reverting subrepo no-largefiles $ hg status -C @@ -1214,8 +1214,8 @@ large $ hg revert --all + forgetting .hglf/dir2/subdir/large.bin undeleting .hglf/dir/subdir/large.bin - forgetting .hglf/dir2/subdir/large.bin reverting subrepo no-largefiles $ hg status -C
--- a/tests/test-largefiles.t Mon Sep 03 10:44:52 2018 +0530 +++ b/tests/test-largefiles.t Fri Aug 31 23:28:09 2018 +0530 @@ -1513,9 +1513,9 @@ $ cat sub/large4 large4-modified $ hg revert -a --no-backup - undeleting .hglf/sub2/large6 forgetting .hglf/sub2/large8 reverting normal3 + undeleting .hglf/sub2/large6 $ hg status ? sub/large4.orig ? sub/normal4.orig
--- a/tests/test-lfs-test-server.t Mon Sep 03 10:44:52 2018 +0530 +++ b/tests/test-lfs-test-server.t Fri Aug 31 23:28:09 2018 +0530 @@ -694,10 +694,6 @@ $ rm * $ hg revert --all -r 1 --debug http auth: user foo, password *** - adding a - reverting b - reverting c - reverting d http auth: user foo, password *** Status: 200 Content-Length: 905 (git-server !) @@ -778,9 +774,13 @@ lfs: adding d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 to the usercache lfs: processed: d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 lfs: downloaded 3 files (51 bytes) + reverting b lfs: found 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b in the local lfs store + reverting c lfs: found d11e1a642b60813aee592094109b406089b8dff4cb157157f753418ec7857998 in the local lfs store + reverting d lfs: found 37a65ab78d5ecda767e8622c248b5dbff1e68b1678ab0e730d5eb8601ec8ad19 in the local lfs store + adding a lfs: found 31cf46fbc4ecd458a0943c5b4881f1f5a6dd36c53d6167d5b69ac45149b38e5b in the local lfs store Check error message when the remote missed a blob:
--- a/tests/test-merge-remove.t Mon Sep 03 10:44:52 2018 +0530 +++ b/tests/test-merge-remove.t Fri Aug 31 23:28:09 2018 +0530 @@ -69,8 +69,8 @@ $ hg revert -vr . foo1 bar saving current version of bar as bar.orig + saving current version of foo1 as foo1.orig reverting bar - saving current version of foo1 as foo1.orig reverting foo1 $ hg debugstate --nodates
--- a/tests/test-revert-interactive.t Mon Sep 03 10:44:52 2018 +0530 +++ b/tests/test-revert-interactive.t Fri Aug 31 23:28:09 2018 +0530 @@ -51,11 +51,8 @@ > n > n > EOF - reverting f - reverting folder1/g + remove added file folder1/i (Yn)? y removing folder1/i - reverting folder2/h - remove added file folder1/i (Yn)? y diff --git a/f b/f 2 hunks, 2 lines changed examine changes to 'f'? [Ynesfdaq?] y @@ -115,6 +112,8 @@ 2 hunks, 2 lines changed examine changes to 'folder2/h'? [Ynesfdaq?] n + reverting folder1/g + reverting f $ cat f 1 2 @@ -140,8 +139,6 @@ Test that --interactive lift the need for --all $ echo q | hg revert -i -r 2 - reverting folder1/g - reverting folder2/h diff --git a/folder1/g b/folder1/g 1 hunks, 1 lines changed examine changes to 'folder1/g'? [Ynesfdaq?] q @@ -197,10 +194,6 @@ > n > n > EOF - reverting f - reverting folder1/g - removing folder1/i - reverting folder2/h remove added file folder1/i (Yn)? n diff --git a/f b/f 2 hunks, 2 lines changed @@ -250,6 +243,8 @@ 2 hunks, 2 lines changed examine changes to 'folder2/h'? [Ynesfdaq?] n + reverting folder1/g + reverting f $ cat f 1 2 @@ -354,7 +349,6 @@ > y > e > EOF - reverting k diff --git a/k b/k 1 hunks, 2 lines changed examine changes to 'k'? [Ynesfdaq?] y @@ -365,6 +359,7 @@ +2 discard this change to 'k'? [Ynesfdaq?] e + reverting k $ cat k 42 @@ -378,15 +373,14 @@ $ hg revert -i <<EOF > n > EOF - forgetting newfile forget added file newfile (Yn)? n $ hg status A newfile $ hg revert -i <<EOF > y > EOF + forget added file newfile (Yn)? y forgetting newfile - forget added file newfile (Yn)? y $ hg status ? newfile @@ -406,7 +400,6 @@ > y > y > EOF - reverting a diff --git a/a b/a 1 hunks, 1 lines changed examine changes to 'a'? [Ynesfdaq?] y @@ -417,6 +410,7 @@ \ No newline at end of file apply this change to 'a'? [Ynesfdaq?] y + reverting a $ cat a 0
--- a/tests/test-revert.t Mon Sep 03 10:44:52 2018 +0530 +++ b/tests/test-revert.t Fri Aug 31 23:28:09 2018 +0530 @@ -129,9 +129,9 @@ ---------------------------------- $ hg revert --all -r0 - adding a + forgetting z removing d - forgetting z + adding a revert explicitly to parent (--rev) ----------------------------------- @@ -283,8 +283,8 @@ $ echo foo > newdir/newfile $ hg add newdir/newfile $ hg revert b newdir + forgetting newdir/newfile reverting b/b - forgetting newdir/newfile $ echo foobar > b/b $ hg revert . reverting b/b @@ -368,9 +368,9 @@ $ hg update '.^' 1 files updated, 0 files merged, 2 files removed, 0 files unresolved $ hg revert -rtip -a + removing ignored adding allyour adding base - removing ignored $ hg status -C A allyour ignored @@ -790,28 +790,28 @@ check revert output $ hg revert --all - undeleting content1_content1_content1-untracked - reverting content1_content1_content3-tracked - undeleting content1_content1_content3-untracked - reverting content1_content1_missing-tracked - undeleting content1_content1_missing-untracked - reverting content1_content2_content1-tracked - undeleting content1_content2_content1-untracked - undeleting content1_content2_content2-untracked - reverting content1_content2_content3-tracked - undeleting content1_content2_content3-untracked - reverting content1_content2_missing-tracked - undeleting content1_content2_missing-untracked forgetting content1_missing_content1-tracked forgetting content1_missing_content3-tracked forgetting content1_missing_missing-tracked - undeleting missing_content2_content2-untracked - reverting missing_content2_content3-tracked - undeleting missing_content2_content3-untracked - reverting missing_content2_missing-tracked - undeleting missing_content2_missing-untracked forgetting missing_missing_content3-tracked forgetting missing_missing_missing-tracked + reverting content1_content1_content3-tracked + reverting content1_content1_missing-tracked + reverting content1_content2_content1-tracked + reverting content1_content2_content3-tracked + reverting content1_content2_missing-tracked + reverting missing_content2_content3-tracked + reverting missing_content2_missing-tracked + undeleting content1_content1_content1-untracked + undeleting content1_content1_content3-untracked + undeleting content1_content1_missing-untracked + undeleting content1_content2_content1-untracked + undeleting content1_content2_content2-untracked + undeleting content1_content2_content3-untracked + undeleting content1_content2_missing-untracked + undeleting missing_content2_content2-untracked + undeleting missing_content2_content3-untracked + undeleting missing_content2_missing-untracked Compare resulting directory with revert target. @@ -847,28 +847,28 @@ check revert output $ hg revert --all --rev 'desc(base)' - undeleting content1_content1_content1-untracked - reverting content1_content1_content3-tracked - undeleting content1_content1_content3-untracked - reverting content1_content1_missing-tracked - undeleting content1_content1_missing-untracked - undeleting content1_content2_content1-untracked - reverting content1_content2_content2-tracked - undeleting content1_content2_content2-untracked - reverting content1_content2_content3-tracked - undeleting content1_content2_content3-untracked - reverting content1_content2_missing-tracked - undeleting content1_content2_missing-untracked - adding content1_missing_content1-untracked - reverting content1_missing_content3-tracked - adding content1_missing_content3-untracked - reverting content1_missing_missing-tracked - adding content1_missing_missing-untracked + forgetting missing_missing_content3-tracked + forgetting missing_missing_missing-tracked removing missing_content2_content2-tracked removing missing_content2_content3-tracked removing missing_content2_missing-tracked - forgetting missing_missing_content3-tracked - forgetting missing_missing_missing-tracked + reverting content1_content1_content3-tracked + reverting content1_content1_missing-tracked + reverting content1_content2_content2-tracked + reverting content1_content2_content3-tracked + reverting content1_content2_missing-tracked + reverting content1_missing_content3-tracked + reverting content1_missing_missing-tracked + adding content1_missing_content1-untracked + adding content1_missing_content3-untracked + adding content1_missing_missing-untracked + undeleting content1_content1_content1-untracked + undeleting content1_content1_content3-untracked + undeleting content1_content1_missing-untracked + undeleting content1_content2_content1-untracked + undeleting content1_content2_content2-untracked + undeleting content1_content2_content3-untracked + undeleting content1_content2_missing-untracked Compare resulting directory with revert target. @@ -1120,8 +1120,8 @@ M A A B $ hg revert --rev 1 --all + removing B reverting A - removing B $ hg status --rev 1 From the other parents @@ -1140,8 +1140,8 @@ M A A B $ hg revert --rev 1 --all + removing B reverting A - removing B $ hg status --rev 1 $ cd ..