Mercurial > public > mercurial-scm > hg-stable
diff mercurial/cmdutil.py @ 39432: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 | 1cbe19eb496d |
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)