[Python-checkins] CVS: python/dist/src/Tools/scripts ndiff.py,1.5,1.6

Tim Peters python-dev@python.org
Fri, 8 Dec 2000 21:03:25 -0800


Update of /cvsroot/python/python/dist/src/Tools/scripts
In directory slayer.i.sourceforge.net:/tmp/cvs-serv1727/python/dist/src/tools/scripts

Modified Files:
	ndiff.py 
Log Message:
SF bug 124051:  ndiff "?" lines can be confusing.  Well, they still can, but
after implementing it I liked Gregor's two-"?" line idea a lot.


Index: ndiff.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/ndiff.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** ndiff.py	2000/11/01 02:51:27	1.5
--- ndiff.py	2000/12/09 05:03:22	1.6
***************
*** 1,7 ****
  #! /usr/bin/env python
  
! # Module ndiff version 1.5.0
! # Released to the public domain 08-Oct-2000,
! # by Tim Peters (tim_one@email.msn.com).
  
  # Provided as-is; use at your own risk; no warranty; no promises; enjoy!
--- 1,7 ----
  #! /usr/bin/env python
  
! # Module ndiff version 1.6.0
! # Released to the public domain 08-Dec-2000,
! # by Tim Peters (tim.one@home.com).
  
  # Provided as-is; use at your own risk; no warranty; no promises; enjoy!
***************
*** 409,419 ****
          print tag, x[i],
  
- # figure out which mark to stick under characters in lines that
- # have changed (blank = same, - = deleted, + = inserted, ^ = replaced)
- _combine = { '  ': ' ',
-              '. ': '-',
-              ' .': '+',
-              '..': '^' }
- 
  def plain_replace(a, alo, ahi, b, blo, bhi):
      assert alo < ahi and blo < bhi
--- 409,412 ----
***************
*** 492,496 ****
      aelt, belt = a[best_i], b[best_j]
      if eqi is None:
!         # pump out a '-', '+', '?' triple for the synched lines;
          atags = btags = ""
          cruncher.set_seqs(aelt, belt)
--- 485,489 ----
      aelt, belt = a[best_i], b[best_j]
      if eqi is None:
!         # pump out a '-', '?', '+', '?' quad for the synched lines
          atags = btags = ""
          cruncher.set_seqs(aelt, belt)
***************
*** 498,519 ****
              la, lb = ai2 - ai1, bj2 - bj1
              if tag == 'replace':
!                 atags = atags + '.' * la
!                 btags = btags + '.' * lb
              elif tag == 'delete':
!                 atags = atags + '.' * la
              elif tag == 'insert':
!                 btags = btags + '.' * lb
              elif tag == 'equal':
!                 atags = atags + ' ' * la
!                 btags = btags + ' ' * lb
              else:
                  raise ValueError, 'unknown tag ' + `tag`
!         la, lb = len(atags), len(btags)
!         if la < lb:
!             atags = atags + ' ' * (lb - la)
!         elif lb < la:
!             btags = btags + ' ' * (la - lb)
!         combined = map(lambda x,y: _combine[x+y], atags, btags)
!         printq(aelt, belt, string.rstrip(string.join(combined, '')))
      else:
          # the synch pair is identical
--- 491,506 ----
              la, lb = ai2 - ai1, bj2 - bj1
              if tag == 'replace':
!                 atags += '^' * la
!                 btags += '^' * lb
              elif tag == 'delete':
!                 atags += '-' * la
              elif tag == 'insert':
!                 btags += '+' * lb
              elif tag == 'equal':
!                 atags += ' ' * la
!                 btags += ' ' * lb
              else:
                  raise ValueError, 'unknown tag ' + `tag`
!         printq(aelt, belt, atags, btags)
      else:
          # the synch pair is identical
***************
*** 535,544 ****
  # probably help most of the time.
  
! def printq(aline, bline, qline):
      common = min(count_leading(aline, "\t"),
                   count_leading(bline, "\t"))
!     common = min(common, count_leading(qline[:common], " "))
!     qline = "\t" * common + qline[common:]
!     print '-', aline, '+', bline, '?', qline
  
  def count_leading(line, ch):
--- 522,535 ----
  # probably help most of the time.
  
! def printq(aline, bline, atags, btags):
      common = min(count_leading(aline, "\t"),
                   count_leading(bline, "\t"))
!     common = min(common, count_leading(atags[:common], " "))
!     print "-", aline,
!     if count_leading(atags, " ") < len(atags):
!         print "?", "\t" * common + atags[common:]
!     print "+", bline,
!     if count_leading(btags, " ") < len(btags):
!         print "?", "\t" * common + btags[common:]
  
  def count_leading(line, ch):