[PATCH 5 of 7] revert: group related data in tuple in the dispatch table

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Mon May 19 10:58:04 CDT 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1400027299 25200
#      Tue May 13 17:28:19 2014 -0700
# Node ID b76ab6980b95e67d4e71162da416de47864b03a1
# Parent  eaff5c46777081a267917ab8631e74f7f51780d3
revert: group related data in tuple in the dispatch table

The dispatch table used to be:

- action if in target manifest
- action if not in target manifest
- make backup if in target manifest
- make backup if not in target manifest

We turn this into two (action, make backup) tuples.

This helps both readability of the dispatch table and handling of each case.

This also prepares a refactoring where the different actions we performs, whether
"file is in target manifest" or not, are determined before reaching this loop.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2318,14 +2318,18 @@ def revert(ui, repo, ctx, parents, *pats
             #   file state
             #   action if in target manifest
             #   action if not in target manifest
             #   make backup if in target manifest
             #   make backup if not in target manifest
-            (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),
+            (modified, (actions['revert'],   True),
+                       (actions['remove'],   True)),
+            (added,    (actions['revert'],   True),
+                       (actions['remove'],   False)),
+            (removed,  (actions['undelete'], True),
+                       (None,                False)),
+            (deleted,  (actions['revert'], False),
+                       (actions['remove'], False)),
             )
 
         for abs, (rel, exact) in sorted(names.items()):
             # hash on file in target manifest (or None if missing from target)
             mfentry = mf.get(abs)
@@ -2347,18 +2351,18 @@ def revert(ui, repo, ctx, parents, *pats
                         msg = msg(abs)
                     ui.status(msg % rel)
             # search the entry in the dispatch table.
             # if the file is in any of this sets, it was touched in the working
             # directory parent and we are sure it needs to be reverted.
-            for table, hitlist, misslist, backuphit, backupmiss in disptable:
+            for table, hit, miss in disptable:
                 if abs not in table:
                     continue
                 # file has changed in dirstate
                 if mfentry:
-                    handle(hitlist, backuphit)
-                elif misslist is not None:
-                    handle(misslist, backupmiss)
+                    handle(*hit)
+                elif miss[0] is not None:
+                    handle(*miss)
                 break
             else:
                 # Not touched in current dirstate.
 
                 # file is unknown in parent, restore older version or ignore.


More information about the Mercurial-devel mailing list