Patchwork D1056: context: add a fast-comparision path between arbitraryfilectx and workingfilectx

login
register
mail settings
Submitter phabricator
Date Oct. 14, 2017, 5:36 a.m.
Message ID <aacb193b3d385d31afdbb36caa850a1c@localhost.localdomain>
Download mbox | patch
Permalink /patch/24873/
State Not Applicable
Headers show

Comments

phabricator - Oct. 14, 2017, 5:36 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG6036e6e205ca: context: add a fast-comparision for arbitraryfilectx and workingfilectx (authored by phillco, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1056?vs=2695&id=2719

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

AFFECTED FILES
  mercurial/context.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -8,6 +8,7 @@ 
 from __future__ import absolute_import
 
 import errno
+import filecmp
 import os
 import re
 import stat
@@ -2554,11 +2555,17 @@ 
     """Allows you to use filectx-like functions on a file in an arbitrary
     location on disk, possibly not in the working directory.
     """
-    def __init__(self, path):
+    def __init__(self, path, repo=None):
+        # Repo is optional because contrib/simplemerge uses this class.
+        self._repo = repo
         self._path = path
 
-    def cmp(self, otherfilectx):
-        return self.data() != otherfilectx.data()
+    def cmp(self, fctx):
+        if isinstance(fctx, workingfilectx) and self._repo:
+            # Add a fast-path for merge if both sides are disk-backed.
+            # Note that filecmp uses the opposite return values as cmp.
+            return not filecmp.cmp(self.path(), self._repo.wjoin(fctx.path()))
+        return self.data() != fctx.data()
 
     def path(self):
         return self._path