[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

diff wish

From: Neels J Hofmeyr <neels_at_elego.de>
Date: Tue, 14 Jun 2011 17:21:27 +0200

Hi Johan,

it's been a while and I still haven't sent you my diff wish we briefly
touched on the Subversion hackathon.

Here is a fabricated example of why I don't like diff to match empty lines:

[[[
Index: x
===================================================================
--- x (revision 1)
+++ x (working copy)
@@ -4,11 +4,13 @@

 void aaa()
 {
- if (x)
- do(things);
+ while (x || y)
+ {
+ check(something);
+ notify(stuff);

- if (y)
- do(stuff);
+ try(somethingelse);
+ }

   bb(b);
 }
]]]

A couple of lines get replaced by completely different ones. By matching the
blank line in the middle, it becomes far less readable, IMHO. In my fantasy
dream world, this diff would print:

[[[
Index: x
===================================================================
--- x (revision 1)
+++ x (working copy)
@@ -4,11 +4,13 @@

 void aaa()
 {
- if (x)
- do(things);
-
- if (y)
- do(stuff);
+ while (x || y)
+ {
+ check(something);
+ notify(stuff);
+
+ try(somethingelse);
+ }

   bb(b);
 }
]]]

I can immediately see the semantics of the modification here. The empty
lines that matched in the middle are simply spacers in unrelated code.

Such empty line spacers appear *everywhere*. So even if two entirely
unrelated huge functions get shifted around in roughly the same place, diff
will always match at the empty lines and create a diff salad du chef.

One day a long time ago, I modded the diff code so that it glued empty lines
to their preceding non-empty line. So that

[[[
  do(things);

]]]

is regarded "as a single line" when dividing the chunks into matching and
non-matching lines.

The adverse effects of that is that any single line change shows any
following empty lines as also changed:

[[[
 context
-foo
-
-
+foobar
+
+
 Context
]]]

and that empty-line-changes also show their preceding non-empty line as
changed even if it hasn't:

[[[
 context
-foo
-
+foo
+
+
 Context
]]]

so my mod should only glue empty lines to the preceding non-empty line if
there are more mismatching lines all around it, or something... if you catch
my drift.

I hope this slightly clarifies what I was thinking of. I should be able to
remember the trivial modification to the diff code that glued empty lines to
non-empty lines (just not right now). Anyway, it was quite trivial.

What do you think about this?

~Neels

Received on 2011-06-14 17:22:11 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.