##// END OF EJS Templates
phabricator: treat non-utf-8 text files as binary as phabricator requires...
Ian Moody -
r43557:06a33a50 default
parent child Browse files
Show More
@@ -697,6 +697,23 b' def makebinary(pchange, fctx):'
697 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 717 def addremoved(pdiff, ctx, removed):
701 718 """add removed files to the phabdiff. Shouldn't include moves"""
702 719 for fname in removed:
@@ -705,7 +722,7 b' def addremoved(pdiff, ctx, removed):'
705 722 )
706 723 pchange.addoldmode(gitmode[ctx.p1()[fname].flags()])
707 724 fctx = ctx.p1()[fname]
708 if not fctx.isbinary():
725 if not (fctx.isbinary() or notutf8(fctx)):
709 726 maketext(pchange, ctx, fname)
710 727
711 728 pdiff.addchange(pchange)
@@ -722,7 +739,7 b' def addmodified(pdiff, ctx, modified):'
722 739 pchange.addoldmode(originalmode)
723 740 pchange.addnewmode(filemode)
724 741
725 if fctx.isbinary():
742 if fctx.isbinary() or notutf8(fctx):
726 743 makebinary(pchange, fctx)
727 744 addoldbinary(pchange, fctx, fname)
728 745 else:
@@ -781,7 +798,7 b' def addadded(pdiff, ctx, added, removed)'
781 798 pchange.addnewmode(gitmode[fctx.flags()])
782 799 pchange.type = DiffChangeType.ADD
783 800
784 if fctx.isbinary():
801 if fctx.isbinary() or notutf8(fctx):
785 802 makebinary(pchange, fctx)
786 803 if renamed:
787 804 addoldbinary(pchange, fctx, originalfname)
General Comments 0
You need to be logged in to leave comments. Login now