comparison mercurial/patch.py @ 32191:31f42e683321

diff: add a fast path to avoid loading binary contents When diffing binary contents, with certain configs, we can show "Binary file <name> has changed" without actual content. That allows a fast path where we could avoid providing actual binary contents. Note: in that case we still need to test if two contents are the same, that's done by using "filectx.cmp", which could have its own fast path.
author Jun Wu <quark@fb.com>
date Wed, 03 May 2017 23:50:41 -0700
parents 0c67ab3d77d5
children 4462a981e8df
comparison
equal deleted inserted replaced
32190:0c67ab3d77d5 32191:31f42e683321
2530 fctx2 = None 2530 fctx2 = None
2531 flag1 = None 2531 flag1 = None
2532 flag2 = None 2532 flag2 = None
2533 if f1: 2533 if f1:
2534 fctx1 = getfilectx(f1, ctx1) 2534 fctx1 = getfilectx(f1, ctx1)
2535 content1 = fctx1.data()
2536 if opts.git or losedatafn: 2535 if opts.git or losedatafn:
2537 flag1 = ctx1.flags(f1) 2536 flag1 = ctx1.flags(f1)
2538 if f2: 2537 if f2:
2539 fctx2 = getfilectx(f2, ctx2) 2538 fctx2 = getfilectx(f2, ctx2)
2540 content2 = fctx2.data()
2541 if opts.git or losedatafn: 2539 if opts.git or losedatafn:
2542 flag2 = ctx2.flags(f2) 2540 flag2 = ctx2.flags(f2)
2543 # if binary is True, output "summary" or "base85", but not "text diff" 2541 # if binary is True, output "summary" or "base85", but not "text diff"
2544 binary = not opts.text and any(f.isbinary() 2542 binary = not opts.text and any(f.isbinary()
2545 for f in [fctx1, fctx2] if f is not None) 2543 for f in [fctx1, fctx2] if f is not None)
2593 # yes | no yes yes 0 | summary | no 2591 # yes | no yes yes 0 | summary | no
2594 # yes | no yes yes >0 | summary | semi [1] 2592 # yes | no yes yes >0 | summary | semi [1]
2595 # yes | yes * * * | text diff | yes 2593 # yes | yes * * * | text diff | yes
2596 # no | * * * * | text diff | yes 2594 # no | * * * * | text diff | yes
2597 # [1]: hash(fctx.data()) is outputted. so fctx.data() cannot be faked 2595 # [1]: hash(fctx.data()) is outputted. so fctx.data() cannot be faked
2596 if binary and (not opts.git or (opts.git and opts.nobinary and not
2597 opts.index)):
2598 # fast path: no binary content will be displayed, content1 and
2599 # content2 are only used for equivalent test. cmp() could have a
2600 # fast path.
2601 if fctx1 is not None:
2602 content1 = b'\0'
2603 if fctx2 is not None:
2604 if fctx1 is not None and not fctx1.cmp(fctx2):
2605 content2 = b'\0' # not different
2606 else:
2607 content2 = b'\0\0'
2608 else:
2609 # normal path: load contents
2610 if fctx1 is not None:
2611 content1 = fctx1.data()
2612 if fctx2 is not None:
2613 content2 = fctx2.data()
2614
2598 if binary and opts.git and not opts.nobinary: 2615 if binary and opts.git and not opts.nobinary:
2599 text = mdiff.b85diff(content1, content2) 2616 text = mdiff.b85diff(content1, content2)
2600 if text: 2617 if text:
2601 header.append('index %s..%s' % 2618 header.append('index %s..%s' %
2602 (gitindex(content1), gitindex(content2))) 2619 (gitindex(content1), gitindex(content2)))