[PATCH] patiencediff.py/unified_diff: do not insert trailing whitespace if filedate is empty

John Arbash Meinel john at arbash-meinel.com
Tue Jan 6 16:17:48 GMT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John Arbash Meinel wrote:
> Adeodato Simó wrote:
>> Hi there.
> 
>> When using unified_diff from bzrlib.patiencediff and writing the result
>> through a colordiff.DiffWriter object, the +++/--- lines were signaled
>> as having trailing whitespace.
> 
>> The attached patch fixes this nuisance, it would be great if you could
>> apply it in bzr.dev. Feel free to drop the str()'s if you feel that's
>> too much pedantry.
> 
>> Thanks,
> 
>> (Please CC me on replies.)
> 
> 
> 
> Just to mention, you changed the patience diff code itself, but you
> didn't actually fix the tests associated with it.
> 
> Attached is code that includes your fix, and then updates the tests to
> match. Which I'm submitting now.
> 
> John
> =:->

So it turns out that this is not sufficient, yet. Specifically, we have
this code in "bzrlib/diff.py":

    # work around for difflib emitting random spaces after the label
    ud[0] = ud[0][:-2] + '\n'
    ud[1] = ud[1][:-2] + '\n'


So when using "internal_diff" it actually was automatically stripping
that trailing whitespace and newline, and then adding the newline back.

It does this, because the internals aren't really able to pass around
the date in the right places, so we actually modify the "filename"
parameter to be filename = filename + '\t' + date

The weirdest part was how the tests failed. Namely they started failing
because the last digit of the timestamp was getting truncated, so you
were getting:

+000 instead of +0000.

So in the end, since we are supposed to be using a '\t' to separate the
filename and datestamp anyway, I went ahead with the attached patch.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkljhCwACgkQJdeBCYSNAANM4wCfR2XykhbnOmxLTpBhQeGf+BMh
dQkAoK05vup4VjG3+QHiQeFGS7twXBes
=8i1P
-----END PGP SIGNATURE-----
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pdiff_unified_diff.patch
Url: https://lists.ubuntu.com/archives/bazaar/attachments/20090106/3f28cf14/attachment-0001.diff 


More information about the bazaar mailing list