Bläddra i källkod

ignore EPIPE happens when input patch set is large

Matthew Wang 12 år sedan
förälder
incheckning
f9c4553bef
1 ändrade filer med 22 tillägg och 12 borttagningar
  1. 22
    12
      src/cdiff.py

+ 22
- 12
src/cdiff.py Visa fil

17
 
17
 
18
 import os
18
 import os
19
 import re
19
 import re
20
+import errno
20
 import difflib
21
 import difflib
21
 
22
 
22
 
23
 
451
                 yield line
452
                 yield line
452
 
453
 
453
 
454
 
455
+def markup_to_pager(stream):
456
+    markup = DiffMarkup(stream)
457
+    color_diff = markup.markup(side_by_side=opts.side_by_side,
458
+            width=opts.width)
459
+
460
+    # args stolen fron git source: github.com/git/git/blob/master/pager.c
461
+    pager = subprocess.Popen(['less', '-FRSXK'],
462
+            stdin=subprocess.PIPE, stdout=sys.stdout)
463
+    for line in color_diff:
464
+        pager.stdin.write(line.encode('utf-8'))
465
+
466
+    pager.stdin.close()
467
+    pager.wait()
468
+
469
+
454
 if __name__ == '__main__':
470
 if __name__ == '__main__':
455
     import optparse
471
     import optparse
456
     import subprocess
472
     import subprocess
491
         diff_hdl.close()
507
         diff_hdl.close()
492
 
508
 
493
     if sys.stdout.isatty():
509
     if sys.stdout.isatty():
494
-        markup = DiffMarkup(stream)
495
-        color_diff = markup.markup(side_by_side=opts.side_by_side,
496
-                width=opts.width)
497
-
498
-        # args stolen fron git source: github.com/git/git/blob/master/pager.c
499
-        pager = subprocess.Popen(['less', '-FRSXK'],
500
-                stdin=subprocess.PIPE, stdout=sys.stdout)
501
-        for line in color_diff:
502
-            pager.stdin.write(line.encode('utf-8'))
503
-
504
-        pager.stdin.close()
505
-        pager.wait()
510
+        try:
511
+            markup_to_pager(stream)
512
+        except IOError:
513
+            e = sys.exc_info()[1]
514
+            if e.errno == errno.EPIPE:
515
+                pass
506
     else:
516
     else:
507
         # pipe out stream untouched to make sure it is still a patch
517
         # pipe out stream untouched to make sure it is still a patch
508
         sys.stdout.write(''.join(stream))
518
         sys.stdout.write(''.join(stream))