Mercurial > hg
changeset 34685:6036e6e205ca
context: add a fast-comparision for arbitraryfilectx and workingfilectx
Differential Revision: https://phab.mercurial-scm.org/D1056
author | Phil Cohen <phillco@fb.com> |
---|---|
date | Fri, 13 Oct 2017 12:40:05 -0700 |
parents | 5d98674df18a |
children | 0d1b8be8d8a8 |
files | mercurial/context.py |
diffstat | 1 files changed, 10 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/context.py Fri Oct 13 04:02:06 2017 +0530 +++ b/mercurial/context.py Fri Oct 13 12:40:05 2017 -0700 @@ -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