Mercurial > hg-stable
changeset 21576:33395a7e5527
revert: group action into a single dictionary
We had 4 different variables to hold the list of the 4 possibles
actions. I'm grouping them in a single dictionary for a few reasons.
First, it makes it clearer they are all related and meant to be the
final actions performed by revert. Second this simplifies the parameter
of the _performrevert function. Finally the two elements in each entry
(list and message) have a different consumers in different functions,
this change will make it easier to split them in a later commit.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Tue, 13 May 2014 16:42:31 -0700 |
parents | 8262c2a39ab8 |
children | c62c5ce750ee |
files | mercurial/cmdutil.py |
diffstat | 1 files changed, 20 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Tue May 13 16:29:42 2014 -0700 +++ b/mercurial/cmdutil.py Tue May 13 16:42:31 2014 -0700 @@ -2318,10 +2318,10 @@ # action to be actually performed by revert # (<list of file>, message>) tuple - revert = ([], _('reverting %s\n')) - add = ([], _('adding %s\n')) - remove = ([], removeforget) - undelete = ([], _('undeleting %s\n')) + actions = {'revert': ([], _('reverting %s\n')), + 'add': ([], _('adding %s\n')), + 'remove': ([], removeforget), + 'undelete': ([], _('undeleting %s\n'))} disptable = ( # dispatch table: @@ -2330,10 +2330,10 @@ # action if not in target manifest # make backup if in target manifest # make backup if not in target manifest - (modified, revert, remove, True, True), - (added, revert, remove, True, False), - (removed, undelete, None, True, False), - (deleted, revert, remove, False, False), + (modified, actions['revert'], actions['remove'], True, True), + (added, actions['revert'], actions['remove'], True, False), + (removed, actions['undelete'], None, True, False), + (deleted, actions['revert'], actions['remove'], False, False), ) for abs, (rel, exact) in sorted(names.items()): @@ -2374,7 +2374,7 @@ # file is unknown in parent, restore older version or ignore. if abs not in repo.dirstate: if mfentry: - handle(add, True) + handle(actions['add'], True) elif exact: ui.warn(_('file not managed: %s\n') % rel) continue @@ -2394,11 +2394,12 @@ # manifests, do nothing if (pmf[abs] != mfentry or pmf.flags(abs) != mf.flags(abs)): - handle(revert, False) + handle(actions['revert'], False) else: - handle(remove, False) + handle(actions['remove'], False) + if not opts.get('dry_run'): - _performrevert(repo, parents, ctx, revert, add, remove, undelete) + _performrevert(repo, parents, ctx, actions) if targetsubs: # Revert the subrepos on the revert list @@ -2407,8 +2408,8 @@ finally: wlock.release() -def _performrevert(repo, parents, ctx, revert, add, remove, undelete): - """function that actually perform all the action computed for revert +def _performrevert(repo, parents, ctx, actions): + """function that actually perform all the actions computed for revert This is an independent function to let extension to plug in and react to the imminent revert. @@ -2422,7 +2423,7 @@ repo.wwrite(f, fc.data(), fc.flags()) audit_path = pathutil.pathauditor(repo.root) - for f in remove[0]: + for f in actions['remove'][0]: if repo.dirstate[f] == 'a': repo.dirstate.drop(f) continue @@ -2442,25 +2443,25 @@ normal = repo.dirstate.normallookup else: normal = repo.dirstate.normal - for f in revert[0]: + for f in actions['revert'][0]: checkout(f) if normal: normal(f) - for f in add[0]: + for f in actions['add'][0]: checkout(f) repo.dirstate.add(f) normal = repo.dirstate.normallookup if node == parent and p2 == nullid: normal = repo.dirstate.normal - for f in undelete[0]: + for f in actions['undelete'][0]: checkout(f) normal(f) copied = copies.pathcopies(repo[parent], ctx) - for f in add[0] + undelete[0] + revert[0]: + for f in actions['add'][0] + actions['undelete'][0] + actions['revert'][0]: if f in copied: repo.dirstate.copy(copied[f], f)