D5472: merge: extract helper for creating empty "actions" dict

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Sat Dec 22 02:36:18 EST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG54c3b4bd01f2: merge: extract helper for creating empty "actions" dict (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5472?vs=12943&id=12947

REVISION DETAIL
  https://phab.mercurial-scm.org/D5472

AFFECTED FILES
  hgext/narrow/narrowcommands.py
  mercurial/merge.py
  mercurial/sparse.py

CHANGE DETAILS

diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -7,7 +7,6 @@
 
 from __future__ import absolute_import
 
-import collections
 import hashlib
 import os
 
@@ -247,7 +246,7 @@
             actions.append((file, None, message))
             dropped.append(file)
 
-    typeactions = collections.defaultdict(list)
+    typeactions = mergemod.emptyactions()
     typeactions['r'] = actions
     mergemod.applyupdates(repo, typeactions, repo[None], repo['.'], False)
 
@@ -380,7 +379,7 @@
                 fctx = repo[None][file]
                 actions.append((file, (fctx.flags(), False), message))
 
-        typeactions = collections.defaultdict(list)
+        typeactions = mergemod.emptyactions()
         typeactions['g'] = actions
         mergemod.applyupdates(repo, typeactions, repo[None], repo['.'],
                               False)
@@ -483,11 +482,8 @@
                 dropped.append(file)
 
     # Apply changes to disk
-    typeactions = dict((m, [])
-                       for m in 'a f g am cd dc r dm dg m e k p pr'.split())
+    typeactions = mergemod.emptyactions()
     for f, (m, args, msg) in actions.iteritems():
-        if m not in typeactions:
-            typeactions[m] = []
         typeactions[m].append((f, args, msg))
 
     mergemod.applyupdates(repo, typeactions, repo[None], repo['.'], False)
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1541,6 +1541,25 @@
         return (not self.updatedcount and not self.mergedcount
                 and not self.removedcount and not self.unresolvedcount)
 
+def emptyactions():
+    """create an actions dict, to be populated and passed to applyupdates()"""
+    return dict((m, [])
+                for m in (
+                    ACTION_ADD,
+                    ACTION_ADD_MODIFIED,
+                    ACTION_FORGET,
+                    ACTION_GET,
+                    ACTION_CHANGED_DELETED,
+                    ACTION_DELETED_CHANGED,
+                    ACTION_REMOVE,
+                    ACTION_DIR_RENAME_MOVE_LOCAL,
+                    ACTION_LOCAL_DIR_RENAME_GET,
+                    ACTION_MERGE,
+                    ACTION_EXEC,
+                    ACTION_KEEP,
+                    ACTION_PATH_CONFLICT,
+                    ACTION_PATH_CONFLICT_RESOLVE))
+
 def applyupdates(repo, actions, wctx, mctx, overwrite, labels=None):
     """apply the merge action list to the working directory
 
@@ -2090,22 +2109,7 @@
                     del actionbyfile[f]
 
         # Convert to dictionary-of-lists format
-        actions = dict((m, [])
-                       for m in (
-                           ACTION_ADD,
-                           ACTION_ADD_MODIFIED,
-                           ACTION_FORGET,
-                           ACTION_GET,
-                           ACTION_CHANGED_DELETED,
-                           ACTION_DELETED_CHANGED,
-                           ACTION_REMOVE,
-                           ACTION_DIR_RENAME_MOVE_LOCAL,
-                           ACTION_LOCAL_DIR_RENAME_GET,
-                           ACTION_MERGE,
-                           ACTION_EXEC,
-                           ACTION_KEEP,
-                           ACTION_PATH_CONFLICT,
-                           ACTION_PATH_CONFLICT_RESOLVE))
+        actions = emptyactions()
         for f, (m, args, msg) in actionbyfile.iteritems():
             if m not in actions:
                 actions[m] = []
diff --git a/hgext/narrow/narrowcommands.py b/hgext/narrow/narrowcommands.py
--- a/hgext/narrow/narrowcommands.py
+++ b/hgext/narrow/narrowcommands.py
@@ -316,7 +316,7 @@
                         transactiongetter=tgetter)
 
         repo.setnewnarrowpats()
-        actions = {k: [] for k in 'a am f g cd dc r dm dg m e k p pr'.split()}
+        actions = merge.emptyactions()
         addgaction = actions['g'].append
 
         mf = repo['.'].manifest().matches(newmatch)



To: martinvonz, durin42, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list