Show More
@@ -697,6 +697,23 b' def makebinary(pchange, fctx):' | |||||
697 | gitmode = {b'l': b'120000', b'x': b'100755', b'': b'100644'} |
|
697 | gitmode = {b'l': b'120000', b'x': b'100755', b'': b'100644'} | |
698 |
|
698 | |||
699 |
|
699 | |||
|
700 | def notutf8(fctx): | |||
|
701 | """detect non-UTF-8 text files since Phabricator requires them to be marked | |||
|
702 | as binary | |||
|
703 | """ | |||
|
704 | try: | |||
|
705 | fctx.data().decode('utf-8') | |||
|
706 | if fctx.parents(): | |||
|
707 | fctx.p1().data().decode('utf-8') | |||
|
708 | return False | |||
|
709 | except UnicodeDecodeError: | |||
|
710 | fctx.repo().ui.write( | |||
|
711 | _(b'file %s detected as non-UTF-8, marked as binary\n') | |||
|
712 | % fctx.path() | |||
|
713 | ) | |||
|
714 | return True | |||
|
715 | ||||
|
716 | ||||
700 | def addremoved(pdiff, ctx, removed): |
|
717 | def addremoved(pdiff, ctx, removed): | |
701 | """add removed files to the phabdiff. Shouldn't include moves""" |
|
718 | """add removed files to the phabdiff. Shouldn't include moves""" | |
702 | for fname in removed: |
|
719 | for fname in removed: | |
@@ -705,7 +722,7 b' def addremoved(pdiff, ctx, removed):' | |||||
705 | ) |
|
722 | ) | |
706 | pchange.addoldmode(gitmode[ctx.p1()[fname].flags()]) |
|
723 | pchange.addoldmode(gitmode[ctx.p1()[fname].flags()]) | |
707 | fctx = ctx.p1()[fname] |
|
724 | fctx = ctx.p1()[fname] | |
708 | if not fctx.isbinary(): |
|
725 | if not (fctx.isbinary() or notutf8(fctx)): | |
709 | maketext(pchange, ctx, fname) |
|
726 | maketext(pchange, ctx, fname) | |
710 |
|
727 | |||
711 | pdiff.addchange(pchange) |
|
728 | pdiff.addchange(pchange) | |
@@ -722,7 +739,7 b' def addmodified(pdiff, ctx, modified):' | |||||
722 | pchange.addoldmode(originalmode) |
|
739 | pchange.addoldmode(originalmode) | |
723 | pchange.addnewmode(filemode) |
|
740 | pchange.addnewmode(filemode) | |
724 |
|
741 | |||
725 | if fctx.isbinary(): |
|
742 | if fctx.isbinary() or notutf8(fctx): | |
726 | makebinary(pchange, fctx) |
|
743 | makebinary(pchange, fctx) | |
727 | addoldbinary(pchange, fctx, fname) |
|
744 | addoldbinary(pchange, fctx, fname) | |
728 | else: |
|
745 | else: | |
@@ -781,7 +798,7 b' def addadded(pdiff, ctx, added, removed)' | |||||
781 | pchange.addnewmode(gitmode[fctx.flags()]) |
|
798 | pchange.addnewmode(gitmode[fctx.flags()]) | |
782 | pchange.type = DiffChangeType.ADD |
|
799 | pchange.type = DiffChangeType.ADD | |
783 |
|
800 | |||
784 | if fctx.isbinary(): |
|
801 | if fctx.isbinary() or notutf8(fctx): | |
785 | makebinary(pchange, fctx) |
|
802 | makebinary(pchange, fctx) | |
786 | if renamed: |
|
803 | if renamed: | |
787 | addoldbinary(pchange, fctx, originalfname) |
|
804 | addoldbinary(pchange, fctx, originalfname) |
General Comments 0
You need to be logged in to leave comments.
Login now