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

Tim Peters python-dev@python.org
Tue, 31 Oct 2000 18:51:30 -0800


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

Modified Files:
	ndiff.py 
Log Message:
Hack ndiff to display lines w/ leading tabs more intuitively.  This synchs
ndiff w/ a custom version I made for Guido during the pre-2.0 freeze.


Index: ndiff.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/ndiff.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** ndiff.py	1999/03/28 17:55:32	1.4
--- ndiff.py	2000/11/01 02:51:27	1.5
***************
*** 1,6 ****
  #! /usr/bin/env python
  
! # Module ndiff version 1.4.0
! # Released to the public domain 27-Mar-1999,
  # by Tim Peters (tim_one@email.msn.com).
  
--- 1,6 ----
  #! /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).
  
***************
*** 29,40 ****
  
  Lines beginning with "? " attempt to guide the eye to intraline
! differences, and were not present in either input file.  These lines can
! be confusing if the source files contain tab characters.
  
  The first file can be recovered by retaining only lines that begin with
  "  " or "- ", and deleting those 2-character prefixes; use ndiff with -r1.
  
! The second file can be recovered similarly, but by retaining only "  "
! and "+ " lines; use ndiff with -r2; or, on Unix, the second file can be
  recovered by piping the output through
  
--- 29,40 ----
  
  Lines beginning with "? " attempt to guide the eye to intraline
! differences, and were not present in either input file.  These lines can be
! confusing if the source files contain tab characters.
  
  The first file can be recovered by retaining only lines that begin with
  "  " or "- ", and deleting those 2-character prefixes; use ndiff with -r1.
  
! The second file can be recovered similarly, but by retaining only "  " and
! "+ " lines; use ndiff with -r2; or, on Unix, the second file can be
  recovered by piping the output through
  
***************
*** 44,48 ****
  """
  
! __version__ = 1, 4, 0
  
  # SequenceMatcher tries to compute a "human-friendly diff" between
--- 44,48 ----
  """
  
! __version__ = 1, 5, 0
  
  # SequenceMatcher tries to compute a "human-friendly diff" between
***************
*** 515,520 ****
              btags = btags + ' ' * (la - lb)
          combined = map(lambda x,y: _combine[x+y], atags, btags)
!         print '-', aelt, '+', belt, '?', \
!               string.rstrip(string.join(combined, ''))
      else:
          # the synch pair is identical
--- 515,519 ----
              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
***************
*** 532,535 ****
--- 531,550 ----
      elif blo < bhi:
          dump('+', b, blo, bhi)
+ 
+ # Crap to deal with leading tabs in "?" output.  Can hurt, but will
+ # 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):
+     i, n = 0, len(line)
+     while i < n and line[i] == ch:
+         i += 1
+     return i
  
  def fail(msg):