in.diff 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. commit 15bfa564b9db08fb277a343a3d0a01d377800606
  2. Author: Matthew Wang <XXXXXXX@gmail.com>
  3. Date: Thu Jan 31 15:27:17 2013 +0800
  4. Default width is now 80
  5. diff --git a/src/cdiff.py b/src/cdiff.py
  6. index 13f725f..bf15ef1 100755
  7. --- a/src/cdiff.py
  8. +++ b/src/cdiff.py
  9. @@ -128,9 +128,7 @@ class Diff(object):
  10. yield self._markup_common(' ' + old[1])
  11. def markup_side_by_side(self, width):
  12. - """width of 0 means infinite width, None means auto detect. Returns a
  13. - generator
  14. - """
  15. + """Returns a generator"""
  16. def _normalize(line):
  17. return line.replace('\t', ' ' * 8).replace('\n', '')
  18. @@ -147,7 +145,8 @@ class Diff(object):
  19. return markup
  20. # Setup line width and number width
  21. - if not width: width = 80
  22. + if width <= 0:
  23. + width = 80
  24. (start, offset) = self._hunks[-1].get_old_addr()
  25. max1 = start + offset - 1
  26. (start, offset) = self._hunks[-1].get_new_addr()
  27. @@ -430,13 +429,10 @@ if __name__ == '__main__':
  28. parser = optparse.OptionParser(usage)
  29. parser.add_option('-s', '--side-by-side', action='store_true',
  30. help=('show in side-by-side mode'))
  31. - parser.add_option('-w', '--width', type='int', default=None,
  32. - help='set line width (side-by-side mode only)')
  33. + parser.add_option('-w', '--width', type='int', default=80,
  34. + help='set line width (side-by-side mode only), default is 80')
  35. opts, args = parser.parse_args()
  36. - if opts.width and opts.width < 0:
  37. - opts.width = 0
  38. -
  39. if len(args) >= 1:
  40. diff_hdl = open(args[0], 'r')
  41. elif sys.stdin.isatty():