comparison mercurial/patch.py @ 32233: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 51fdedd29b0a
children 776127b29a5c
comparison
equal deleted inserted replaced
32232:76f9a0009b4b 32233:e62cf13e0858
2521 "file %s doesn't start with relroot %s" % (f, relroot)) 2521 "file %s doesn't start with relroot %s" % (f, relroot))
2522 2522
2523 for f1, f2, copyop in _filepairs(modified, added, removed, copy, opts): 2523 for f1, f2, copyop in _filepairs(modified, added, removed, copy, opts):
2524 content1 = None 2524 content1 = None
2525 content2 = None 2525 content2 = None
2526 fctx1 = None
2527 fctx2 = None
2526 flag1 = None 2528 flag1 = None
2527 flag2 = None 2529 flag2 = None
2528 if f1: 2530 if f1:
2529 content1 = getfilectx(f1, ctx1).data() 2531 fctx1 = getfilectx(f1, ctx1)
2532 content1 = fctx1.data()
2530 if opts.git or losedatafn: 2533 if opts.git or losedatafn:
2531 flag1 = ctx1.flags(f1) 2534 flag1 = ctx1.flags(f1)
2532 if f2: 2535 if f2:
2533 content2 = getfilectx(f2, ctx2).data() 2536 fctx2 = getfilectx(f2, ctx2)
2537 content2 = fctx2.data()
2534 if opts.git or losedatafn: 2538 if opts.git or losedatafn:
2535 flag2 = ctx2.flags(f2) 2539 flag2 = ctx2.flags(f2)
2536 binary = False 2540 binary = False
2537 if opts.git or losedatafn: 2541 if opts.git or losedatafn:
2538 binary = util.binary(content1) or util.binary(content2) 2542 binary = any(f.isbinary() for f in [fctx1, fctx2] if f is not None)
2539 2543
2540 if losedatafn and not opts.git: 2544 if losedatafn and not opts.git:
2541 if (binary or 2545 if (binary or
2542 # copy/rename 2546 # copy/rename
2543 f2 in copy or 2547 f2 in copy or