changeset 52032:09a54892b7ee

mergestate: reduce the number of attribute lookups This code is called a lot during updates, this is a very small but also very easy thing to do.
author Raphaël Gomès <rgomes@octobus.net>
date Wed, 21 Aug 2024 09:48:14 +0200
parents 921b8ad3feae
children 88aa21d654e5
files mercurial/mergestate.py
diffstat 1 files changed, 31 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/mergestate.py	Mon Oct 21 11:48:09 2024 -0400
+++ b/mercurial/mergestate.py	Wed Aug 21 09:48:14 2024 +0200
@@ -780,45 +780,46 @@
 
 def recordupdates(repo, actions, branchmerge, getfiledata):
     """record merge actions to the dirstate"""
+    dirstate = repo.dirstate
+    update_file = dirstate.update_file
+
     # remove (must come first)
     for f, args, msg in actions.get(ACTION_REMOVE, []):
         if branchmerge:
-            repo.dirstate.update_file(f, p1_tracked=True, wc_tracked=False)
+            update_file(f, p1_tracked=True, wc_tracked=False)
         else:
-            repo.dirstate.update_file(f, p1_tracked=False, wc_tracked=False)
+            update_file(f, p1_tracked=False, wc_tracked=False)
 
     # forget (must come first)
     for f, args, msg in actions.get(ACTION_FORGET, []):
-        repo.dirstate.update_file(f, p1_tracked=False, wc_tracked=False)
+        update_file(f, p1_tracked=False, wc_tracked=False)
 
     # resolve path conflicts
     for f, args, msg in actions.get(ACTION_PATH_CONFLICT_RESOLVE, []):
         (f0, origf0) = args
-        repo.dirstate.update_file(f, p1_tracked=False, wc_tracked=True)
-        repo.dirstate.copy(origf0, f)
+        update_file(f, p1_tracked=False, wc_tracked=True)
+        dirstate.copy(origf0, f)
         if f0 == origf0:
-            repo.dirstate.update_file(f0, p1_tracked=True, wc_tracked=False)
+            update_file(f0, p1_tracked=True, wc_tracked=False)
         else:
-            repo.dirstate.update_file(f0, p1_tracked=False, wc_tracked=False)
+            update_file(f0, p1_tracked=False, wc_tracked=False)
 
     # re-add
     for f, args, msg in actions.get(ACTION_ADD, []):
-        repo.dirstate.update_file(f, p1_tracked=False, wc_tracked=True)
+        update_file(f, p1_tracked=False, wc_tracked=True)
 
     # re-add/mark as modified
     for f, args, msg in actions.get(ACTION_ADD_MODIFIED, []):
         if branchmerge:
-            repo.dirstate.update_file(
+            update_file(
                 f, p1_tracked=True, wc_tracked=True, possibly_dirty=True
             )
         else:
-            repo.dirstate.update_file(f, p1_tracked=False, wc_tracked=True)
+            update_file(f, p1_tracked=False, wc_tracked=True)
 
     # exec change
     for f, args, msg in actions.get(ACTION_EXEC, []):
-        repo.dirstate.update_file(
-            f, p1_tracked=True, wc_tracked=True, possibly_dirty=True
-        )
+        update_file(f, p1_tracked=True, wc_tracked=True, possibly_dirty=True)
 
     # keep
     for f, args, msg in actions.get(ACTION_KEEP, []):
@@ -836,9 +837,9 @@
     for f, args, msg in actions.get(ACTION_GET, []):
         if branchmerge:
             # tracked in p1 can be True also but update_file should not care
-            old_entry = repo.dirstate.get_entry(f)
+            old_entry = dirstate.get_entry(f)
             p1_tracked = old_entry.any_tracked and not old_entry.added
-            repo.dirstate.update_file(
+            update_file(
                 f,
                 p1_tracked=p1_tracked,
                 wc_tracked=True,
@@ -846,7 +847,7 @@
             )
         else:
             parentfiledata = getfiledata[f] if getfiledata else None
-            repo.dirstate.update_file(
+            update_file(
                 f,
                 p1_tracked=True,
                 wc_tracked=True,
@@ -860,7 +861,7 @@
             # We've done a branch merge, mark this file as merged
             # so that we properly record the merger later
             p1_tracked = f1 == f
-            repo.dirstate.update_file(
+            update_file(
                 f,
                 p1_tracked=p1_tracked,
                 wc_tracked=True,
@@ -868,13 +869,11 @@
             )
             if f1 != f2:  # copy/rename
                 if move:
-                    repo.dirstate.update_file(
-                        f1, p1_tracked=True, wc_tracked=False
-                    )
+                    update_file(f1, p1_tracked=True, wc_tracked=False)
                 if f1 != f:
-                    repo.dirstate.copy(f1, f)
+                    dirstate.copy(f1, f)
                 else:
-                    repo.dirstate.copy(f2, f)
+                    dirstate.copy(f2, f)
         else:
             # We've update-merged a locally modified file, so
             # we set the dirstate to emulate a normal checkout
@@ -882,30 +881,28 @@
             # merge will appear as a normal local file
             # modification.
             if f2 == f:  # file not locally copied/moved
-                repo.dirstate.update_file(
+                update_file(
                     f, p1_tracked=True, wc_tracked=True, possibly_dirty=True
                 )
             if move:
-                repo.dirstate.update_file(
-                    f1, p1_tracked=False, wc_tracked=False
-                )
+                update_file(f1, p1_tracked=False, wc_tracked=False)
 
     # directory rename, move local
     for f, args, msg in actions.get(ACTION_DIR_RENAME_MOVE_LOCAL, []):
         f0, flag = args
         if branchmerge:
-            repo.dirstate.update_file(f, p1_tracked=False, wc_tracked=True)
-            repo.dirstate.update_file(f0, p1_tracked=True, wc_tracked=False)
-            repo.dirstate.copy(f0, f)
+            update_file(f, p1_tracked=False, wc_tracked=True)
+            update_file(f0, p1_tracked=True, wc_tracked=False)
+            dirstate.copy(f0, f)
         else:
-            repo.dirstate.update_file(f, p1_tracked=True, wc_tracked=True)
-            repo.dirstate.update_file(f0, p1_tracked=False, wc_tracked=False)
+            update_file(f, p1_tracked=True, wc_tracked=True)
+            update_file(f0, p1_tracked=False, wc_tracked=False)
 
     # directory rename, get
     for f, args, msg in actions.get(ACTION_LOCAL_DIR_RENAME_GET, []):
         f0, flag = args
         if branchmerge:
-            repo.dirstate.update_file(f, p1_tracked=False, wc_tracked=True)
-            repo.dirstate.copy(f0, f)
+            update_file(f, p1_tracked=False, wc_tracked=True)
+            dirstate.copy(f0, f)
         else:
-            repo.dirstate.update_file(f, p1_tracked=True, wc_tracked=True)
+            update_file(f, p1_tracked=True, wc_tracked=True)