Kaydet (Commit) 0d430e28 authored tarafından Tim Peters's avatar Tim Peters

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.
üst 24ec6fbc
#! /usr/bin/env python #! /usr/bin/env python
# Module ndiff version 1.4.0 # Module ndiff version 1.5.0
# Released to the public domain 27-Mar-1999, # Released to the public domain 08-Oct-2000,
# by Tim Peters (tim_one@email.msn.com). # by Tim Peters (tim_one@email.msn.com).
# Provided as-is; use at your own risk; no warranty; no promises; enjoy! # Provided as-is; use at your own risk; no warranty; no promises; enjoy!
...@@ -28,14 +28,14 @@ Each remaining line begins with a two-letter code: ...@@ -28,14 +28,14 @@ Each remaining line begins with a two-letter code:
"? " line not present in either input file "? " line not present in either input file
Lines beginning with "? " attempt to guide the eye to intraline Lines beginning with "? " attempt to guide the eye to intraline
differences, and were not present in either input file. These lines can differences, and were not present in either input file. These lines can be
be confusing if the source files contain tab characters. confusing if the source files contain tab characters.
The first file can be recovered by retaining only lines that begin with The first file can be recovered by retaining only lines that begin with
" " or "- ", and deleting those 2-character prefixes; use ndiff with -r1. " " or "- ", and deleting those 2-character prefixes; use ndiff with -r1.
The second file can be recovered similarly, but by retaining only " " The second file can be recovered similarly, but by retaining only " " and
and "+ " lines; use ndiff with -r2; or, on Unix, the second file can be "+ " lines; use ndiff with -r2; or, on Unix, the second file can be
recovered by piping the output through recovered by piping the output through
sed -n '/^[+ ] /s/^..//p' sed -n '/^[+ ] /s/^..//p'
...@@ -43,7 +43,7 @@ recovered by piping the output through ...@@ -43,7 +43,7 @@ recovered by piping the output through
See module comments for details and programmatic interface. See module comments for details and programmatic interface.
""" """
__version__ = 1, 4, 0 __version__ = 1, 5, 0
# SequenceMatcher tries to compute a "human-friendly diff" between # SequenceMatcher tries to compute a "human-friendly diff" between
# two sequences (chiefly picturing a file as a sequence of lines, # two sequences (chiefly picturing a file as a sequence of lines,
...@@ -514,8 +514,7 @@ def fancy_replace(a, alo, ahi, b, blo, bhi): ...@@ -514,8 +514,7 @@ def fancy_replace(a, alo, ahi, b, blo, bhi):
elif lb < la: elif lb < la:
btags = btags + ' ' * (la - lb) btags = btags + ' ' * (la - lb)
combined = map(lambda x,y: _combine[x+y], atags, btags) combined = map(lambda x,y: _combine[x+y], atags, btags)
print '-', aelt, '+', belt, '?', \ printq(aelt, belt, string.rstrip(string.join(combined, '')))
string.rstrip(string.join(combined, ''))
else: else:
# the synch pair is identical # the synch pair is identical
print ' ', aelt, print ' ', aelt,
...@@ -532,6 +531,22 @@ def fancy_helper(a, alo, ahi, b, blo, bhi): ...@@ -532,6 +531,22 @@ def fancy_helper(a, alo, ahi, b, blo, bhi):
elif blo < bhi: elif blo < bhi:
dump('+', b, 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): def fail(msg):
import sys import sys
out = sys.stderr.write out = sys.stderr.write
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment