Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 32236:0c67ab3d77d5
diff: correct binary testing logic
This seems to be more correct given the table drawn in the previous patch.
Namely, "losedatafn" and "opts.git" are removed, "not opts.text" is added.
- losedatafn: diff output (binary) should not be affected by "losedatafn"
- opts.git: binary testing is helpful for detecting a fast path in the
next path. the fast path can also be used if opts.git is False
- opts.text: if it's set, we should treat the content as non-binary
author | Jun Wu <quark@fb.com> |
---|---|
date | Fri, 05 May 2017 17:20:32 -0700 |
parents | 15f10ee778f8 |
children | 31f42e683321 |
comparison
equal
deleted
inserted
replaced
32235:15f10ee778f8 | 32236:0c67ab3d77d5 |
---|---|
2538 if f2: | 2538 if f2: |
2539 fctx2 = getfilectx(f2, ctx2) | 2539 fctx2 = getfilectx(f2, ctx2) |
2540 content2 = fctx2.data() | 2540 content2 = fctx2.data() |
2541 if opts.git or losedatafn: | 2541 if opts.git or losedatafn: |
2542 flag2 = ctx2.flags(f2) | 2542 flag2 = ctx2.flags(f2) |
2543 binary = False | 2543 # if binary is True, output "summary" or "base85", but not "text diff" |
2544 if opts.git or losedatafn: | 2544 binary = not opts.text and any(f.isbinary() |
2545 binary = any(f.isbinary() for f in [fctx1, fctx2] if f is not None) | 2545 for f in [fctx1, fctx2] if f is not None) |
2546 | 2546 |
2547 if losedatafn and not opts.git: | 2547 if losedatafn and not opts.git: |
2548 if (binary or | 2548 if (binary or |
2549 # copy/rename | 2549 # copy/rename |
2550 f2 in copy or | 2550 f2 in copy or |
2593 # yes | no yes yes 0 | summary | no | 2593 # yes | no yes yes 0 | summary | no |
2594 # yes | no yes yes >0 | summary | semi [1] | 2594 # yes | no yes yes >0 | summary | semi [1] |
2595 # yes | yes * * * | text diff | yes | 2595 # yes | yes * * * | text diff | yes |
2596 # no | * * * * | text diff | yes | 2596 # no | * * * * | text diff | yes |
2597 # [1]: hash(fctx.data()) is outputted. so fctx.data() cannot be faked | 2597 # [1]: hash(fctx.data()) is outputted. so fctx.data() cannot be faked |
2598 if binary and opts.git and not opts.nobinary and not opts.text: | 2598 if binary and opts.git and not opts.nobinary: |
2599 text = mdiff.b85diff(content1, content2) | 2599 text = mdiff.b85diff(content1, content2) |
2600 if text: | 2600 if text: |
2601 header.append('index %s..%s' % | 2601 header.append('index %s..%s' % |
2602 (gitindex(content1), gitindex(content2))) | 2602 (gitindex(content1), gitindex(content2))) |
2603 hunks = (None, [text]), | 2603 hunks = (None, [text]), |