Mercurial > hg
changeset 32187:e62cf13e0858
diff: use fctx.isbinary() to test binary
The end goal is to avoid calling fctx.data() when unnecessary. For example,
if diff.nobinary=1 and files are binary, the expected behavior is to print
"Binary file has changed". That could avoid reading fctx.data() sometimes.
This is mainly to enable an external LFS extension to skip expensive binary
file loading sometimes (read: most of the time with diff.nobinary=1 and
diff.text=0), without any behavior changes to mercurial (i.e. whether a file
is LFS or not does not change any behavior, LFS could be 100% transparent to
users).
author | Jun Wu <quark@fb.com> |
---|---|
date | Wed, 03 May 2017 22:16:54 -0700 |
parents | 76f9a0009b4b |
children | 776127b29a5c |
files | mercurial/patch.py |
diffstat | 1 files changed, 7 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/patch.py Thu Apr 20 22:16:12 2017 +0900 +++ b/mercurial/patch.py Wed May 03 22:16:54 2017 -0700 @@ -2523,19 +2523,23 @@ for f1, f2, copyop in _filepairs(modified, added, removed, copy, opts): content1 = None content2 = None + fctx1 = None + fctx2 = None flag1 = None flag2 = None if f1: - content1 = getfilectx(f1, ctx1).data() + fctx1 = getfilectx(f1, ctx1) + content1 = fctx1.data() if opts.git or losedatafn: flag1 = ctx1.flags(f1) if f2: - content2 = getfilectx(f2, ctx2).data() + fctx2 = getfilectx(f2, ctx2) + content2 = fctx2.data() if opts.git or losedatafn: flag2 = ctx2.flags(f2) binary = False if opts.git or losedatafn: - binary = util.binary(content1) or util.binary(content2) + binary = any(f.isbinary() for f in [fctx1, fctx2] if f is not None) if losedatafn and not opts.git: if (binary or