changeset 45454:037e88d453fa

commit: pass mergestate into _filecommit() instead of re-reading it mergestate reading although cheap is not free. Let's read mergestate once on top and pass it into `_filecommit()`. In upcoming patches, we will be reading mergestate more in `_filecommit()`. Differential Revision: https://phab.mercurial-scm.org/D8984
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 03 Sep 2020 14:14:04 +0530
parents c6e332a451d0
children f6c67bb4ca03
files mercurial/commit.py tests/test-annotate.t tests/test-fastannotate-hg.t
diffstat 3 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commit.py	Fri Sep 11 13:04:05 2020 +0530
+++ b/mercurial/commit.py	Thu Sep 03 14:14:04 2020 +0530
@@ -157,6 +157,7 @@
     m = mctx.read()
     m1 = m1ctx.read()
     m2 = m2ctx.read()
+    ms = mergestate.mergestate.read(repo)
 
     files = metadata.ChangingFiles()
 
@@ -175,7 +176,7 @@
             else:
                 added.append(f)
                 m[f], is_touched = _filecommit(
-                    repo, fctx, m1, m2, linkrev, tr, writefilecopymeta,
+                    repo, fctx, m1, m2, linkrev, tr, writefilecopymeta, ms
                 )
                 if is_touched:
                     if is_touched == 'added':
@@ -211,7 +212,7 @@
 
 
 def _filecommit(
-    repo, fctx, manifest1, manifest2, linkrev, tr, includecopymeta,
+    repo, fctx, manifest1, manifest2, linkrev, tr, includecopymeta, ms,
 ):
     """
     commit an individual file as part of a larger transaction
@@ -226,6 +227,7 @@
         includecopymeta: boolean, set to False to skip storing the copy data
                     (only used by the Google specific feature of using
                     changeset extra as copy source of truth).
+        ms:         mergestate object
 
     output: (filenode, touched)
 
@@ -324,8 +326,10 @@
             fparent2 = nullid
         elif not fparentancestors:
             # TODO: this whole if-else might be simplified much more
-            ms = mergestate.mergestate.read(repo)
-            if ms.extras(fname).get(b'filenode-source') == b'other':
+            if (
+                ms.active()
+                and ms.extras(fname).get(b'filenode-source') == b'other'
+            ):
                 fparent1, fparent2 = fparent2, nullid
 
     # is the file changed?
--- a/tests/test-annotate.t	Fri Sep 11 13:04:05 2020 +0530
+++ b/tests/test-annotate.t	Thu Sep 03 14:14:04 2020 +0530
@@ -481,7 +481,7 @@
   > from __future__ import absolute_import
   > from mercurial import commit, error, extensions, node
   > def _filecommit(orig, repo, fctx, manifest1, manifest2,
-  >                 linkrev, tr, includecopymeta):
+  >                 linkrev, tr, includecopymeta, ms):
   >     fname = fctx.path()
   >     text = fctx.data()
   >     flog = repo.file(fname)
--- a/tests/test-fastannotate-hg.t	Fri Sep 11 13:04:05 2020 +0530
+++ b/tests/test-fastannotate-hg.t	Thu Sep 03 14:14:04 2020 +0530
@@ -484,7 +484,7 @@
   > from __future__ import absolute_import
   > from mercurial import commit, error, extensions, node
   > def _filecommit(orig, repo, fctx, manifest1, manifest2,
-  >                 linkrev, tr, includecopymeta):
+  >                 linkrev, tr, includecopymeta, ms):
   >     fname = fctx.path()
   >     text = fctx.data()
   >     flog = repo.file(fname)