|
@@ -36,6 +36,12 @@ import select
|
36
|
36
|
import difflib
|
37
|
37
|
|
38
|
38
|
|
|
39
|
+try:
|
|
40
|
+ unicode
|
|
41
|
+except NameError:
|
|
42
|
+ unicode = str
|
|
43
|
+
|
|
44
|
+
|
39
|
45
|
COLORS = {
|
40
|
46
|
'reset' : '\x1b[0m',
|
41
|
47
|
'underline' : '\x1b[4m',
|
|
@@ -248,7 +254,7 @@ class PatchStreamForwarder(object):
|
248
|
254
|
def _forward_line(self):
|
249
|
255
|
try:
|
250
|
256
|
line = next(self._istream)
|
251
|
|
- self._in.write(line.encode('utf-8'))
|
|
257
|
+ self._in.write(line)
|
252
|
258
|
except StopIteration:
|
253
|
259
|
self._in.close()
|
254
|
260
|
|
|
@@ -643,11 +649,17 @@ def revision_control_log(args):
|
643
|
649
|
|
644
|
650
|
def decode(line):
|
645
|
651
|
"""Decode UTF-8 if necessary."""
|
646
|
|
- try:
|
647
|
|
- return line.decode('utf-8')
|
648
|
|
- except (AttributeError, UnicodeDecodeError):
|
|
652
|
+ if isinstance(line, unicode):
|
649
|
653
|
return line
|
650
|
654
|
|
|
655
|
+ for encoding in ['utf-8', 'latin1']:
|
|
656
|
+ try:
|
|
657
|
+ return line.decode(encoding)
|
|
658
|
+ except UnicodeDecodeError:
|
|
659
|
+ pass
|
|
660
|
+
|
|
661
|
+ return '*** cdiff: undecodable bytes ***\n'
|
|
662
|
+
|
651
|
663
|
|
652
|
664
|
def main():
|
653
|
665
|
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
|
@@ -715,7 +727,8 @@ def main():
|
715
|
727
|
parser.print_help()
|
716
|
728
|
return 1
|
717
|
729
|
else:
|
718
|
|
- diff_hdl = sys.stdin
|
|
730
|
+ diff_hdl = (sys.stdin.buffer if hasattr(sys.stdin, 'buffer')
|
|
731
|
+ else sys.stdin)
|
719
|
732
|
|
720
|
733
|
stream = PatchStream(diff_hdl)
|
721
|
734
|
|
|
@@ -730,8 +743,11 @@ def main():
|
730
|
743
|
# pipe out stream untouched to make sure it is still a patch
|
731
|
744
|
if sys.hexversion < 0x03000000:
|
732
|
745
|
reload(sys).setdefaultencoding('utf8')
|
|
746
|
+
|
|
747
|
+ byte_output = (sys.stdout.buffer if hasattr(sys.stdout, 'buffer')
|
|
748
|
+ else sys.stdout)
|
733
|
749
|
for line in stream:
|
734
|
|
- sys.stdout.write(decode(line))
|
|
750
|
+ byte_output.write(line)
|
735
|
751
|
|
736
|
752
|
if diff_hdl is not sys.stdin:
|
737
|
753
|
diff_hdl.close()
|