diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -3018,10 +3018,11 @@ util.copyfile(target, bakname) else: util.rename(target, bakname) - if ui.verbose or not exact: - if not isinstance(msg, bytes): - msg = msg(abs) - ui.status(msg % rel) + if opts.get('dry_run'): + if ui.verbose or not exact: + if not isinstance(msg, bytes): + msg = msg(abs) + ui.status(msg % rel) elif exact: ui.warn(msg % rel) break @@ -3034,7 +3035,19 @@ prefetch(repo, [ctx.rev()], matchfiles(repo, [f for sublist in oplist for f in sublist])) - _performrevert(repo, parents, ctx, actions, interactive, tobackup) + # give status messages for actions to be performed + acts = "add drop undelete forget remove revert".split() + if interactive: + # exclude ("forget", "remove", "revert") as status msg for these + # actions will be handled in interactive session. + acts = acts[:3] + for act in acts: + for f in actions[act][0]: + rel, exact = names[f] + if ui.verbose or not exact: + ui.status(actions[act][1] % rel) + _performrevert(repo, parents, ctx, names, actions, interactive, + tobackup) if targetsubs: # Revert the subrepos on the revert list @@ -3046,7 +3059,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 @@ -3077,6 +3090,9 @@ choice = repo.ui.promptchoice( _("forget added file %s (Yn)?$$ &Yes $$ &No") % f) if choice == 0: + rel, exact = names[f] + if repo.ui.verbose or not exact: + repo.ui.status(actions['forget'][1] % rel) repo.dirstate.drop(f) else: excluded_files.append(f) @@ -3088,6 +3104,9 @@ choice = repo.ui.promptchoice( _("remove added file %s (Yn)?$$ &Yes $$ &No") % f) if choice == 0: + rel, exact = names[f] + if repo.ui.verbose or not exact: + repo.ui.status(actions['remove'][1] % rel) doremove(f) else: excluded_files.append(f) @@ -3141,14 +3160,23 @@ 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) + rel, exact = names[abs] + if repo.ui.verbose or not exact: + repo.ui.status(actions['revert'][1] % rel) + # 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) diff --git a/tests/test-revert-interactive.t b/tests/test-revert-interactive.t --- a/tests/test-revert-interactive.t +++ b/tests/test-revert-interactive.t @@ -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 f + reverting folder1/g $ 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 f + reverting folder1/g $ 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 < n > EOF - forgetting newfile forget added file newfile (Yn)? n $ hg status A newfile $ hg revert -i < 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 diff --git a/tests/test-revert.t b/tests/test-revert.t --- a/tests/test-revert.t +++ b/tests/test-revert.t @@ -130,15 +130,15 @@ $ hg revert --all -r0 adding a + forgetting z removing d - forgetting z revert explicitly to parent (--rev) ----------------------------------- $ hg revert --all -rtip + undeleting d forgetting a - undeleting d $ rm a *.orig revert to another revision (--rev) and exact match @@ -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 @@ -335,10 +335,10 @@ -------------------------------------------- $ hg revert -a --no-backup + undeleting ignoreddir/removed + undeleting removed reverting ignored reverting ignoreddir/file - undeleting ignoreddir/removed - undeleting removed $ hg st -mardi $ hg up -qC @@ -384,9 +384,9 @@ remove any pending change $ hg revert --all + undeleting ignored forgetting allyour forgetting base - undeleting ignored $ hg purge --all --config extensions.purge= Adds a new commit @@ -791,27 +791,27 @@ $ 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 + undeleting missing_content2_content2-untracked + undeleting missing_content2_content3-untracked + undeleting missing_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 Compare resulting directory with revert target. @@ -847,28 +847,28 @@ check revert output $ hg revert --all --rev 'desc(base)' + adding content1_missing_content1-untracked + adding content1_missing_content3-untracked + adding content1_missing_missing-untracked + removing missing_content2_content3-tracked + removing missing_content2_missing-tracked 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 - 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 + removing missing_content2_content2-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 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 ..