0

I want to diff -u python code files, where the target version got some tidy-up, mostly little white space change due to PEP8, yet mixed with little substantial changes (including indentation; and even white space in strings).

How do I best get a diff for reviewing only the substantial changes, or for creating a ham-only patch?

Test example diff SOURCE:

def f(a, b = 0):
    c = a*2
    c+=b%37
    if a//7 + ( b&0x3 ) ==7 :
        c+= 8
    print "indentlevel"
    return a^b+c

and diff TARGET:

def f(a, b=0):
    c = a * 2
    c += b % 37
    if a // 7 + (b & 0x3) == 7:
        if a - b > 5:
            c += 8
    print "indent level"
    return a ^ b + c

GNU diff's --ignore-tab-expansion, --ignore-trailing-space, --ignore-space-change, --ignore-all-space, --ignore-blank-lines do not work satisfactory for that.

Note: the requirement of mixed changes is given. (2-step editing is not even practical in future in many cases)

kxr
  • 4,841
  • 1
  • 49
  • 32
  • 1
    What about [`git diff -w`](http://stackoverflow.com/a/4350724/4653485)? – Jérôme Mar 15 '16 at 13:59
  • 1
    Isnt that the --ignore-all-space that he mentioned? – Mathias711 Mar 15 '16 at 14:08
  • 2
    Can't you pass both codes by [autopep8](https://pypi.python.org/pypi/autopep8) and then diff it? – Bernardo Meurer Mar 15 '16 at 14:14
  • @Bernard, that does indeed rather good for the first task (substantial change review), when there is no inherently tolerant diff method. Just it can't create possibly a patch, which can be applied to an original / SOURCE-like file (e.g. of a non-pep'ed master tree). Even `patch --ignore-whitespace --force` failed on all test hunks here, though it was just an issue of in-line whitespace.? – kxr Mar 16 '16 at 10:28

0 Answers0