revert: group related data in tuple in the dispatch table
authorPierre-Yves David <pierre-yves.david@fb.com>
Tue, 13 May 2014 17:28:19 -0700
changeset 21577 c62c5ce750ee
parent 21576 33395a7e5527
child 21578 7cfe51661e98
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.
mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Tue May 13 16:42:31 2014 -0700
+++ b/mercurial/cmdutil.py	Tue May 13 17:28:19 2014 -0700
@@ -2330,10 +2330,14 @@
             #   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()):
@@ -2359,14 +2363,14 @@
             # 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.