Mercurial > public > mercurial-scm > hg
comparison mercurial/context.py @ 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 | 4dc8a2ee0f4f |
children | 0c812885586b |
comparison
equal
deleted
inserted
replaced
34684:5d98674df18a | 34685:6036e6e205ca |
---|---|
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 from __future__ import absolute_import | 8 from __future__ import absolute_import |
9 | 9 |
10 import errno | 10 import errno |
11 import filecmp | |
11 import os | 12 import os |
12 import re | 13 import re |
13 import stat | 14 import stat |
14 | 15 |
15 from .i18n import _ | 16 from .i18n import _ |
2552 | 2553 |
2553 class arbitraryfilectx(object): | 2554 class arbitraryfilectx(object): |
2554 """Allows you to use filectx-like functions on a file in an arbitrary | 2555 """Allows you to use filectx-like functions on a file in an arbitrary |
2555 location on disk, possibly not in the working directory. | 2556 location on disk, possibly not in the working directory. |
2556 """ | 2557 """ |
2557 def __init__(self, path): | 2558 def __init__(self, path, repo=None): |
2559 # Repo is optional because contrib/simplemerge uses this class. | |
2560 self._repo = repo | |
2558 self._path = path | 2561 self._path = path |
2559 | 2562 |
2560 def cmp(self, otherfilectx): | 2563 def cmp(self, fctx): |
2561 return self.data() != otherfilectx.data() | 2564 if isinstance(fctx, workingfilectx) and self._repo: |
2565 # Add a fast-path for merge if both sides are disk-backed. | |
2566 # Note that filecmp uses the opposite return values as cmp. | |
2567 return not filecmp.cmp(self.path(), self._repo.wjoin(fctx.path())) | |
2568 return self.data() != fctx.data() | |
2562 | 2569 |
2563 def path(self): | 2570 def path(self): |
2564 return self._path | 2571 return self._path |
2565 | 2572 |
2566 def flags(self): | 2573 def flags(self): |