Diff Error

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Diff Error

Bill McCarthy
Hello Vim Developers,

I used diff to compare two files.  Each file has twelve
columns of numbers.  Only the 3rd, 7th and 11th columns
are different.  The vim diff result looks very strange.

I have included the two small files named 'l' and 'r'.
You can compare them with:

    gvim -u NONE -N -d L R "+se co=125"

Then make the two sides equal with: <C-W>=

The same odd result can be seen in either 6.3.80 or in
7.0aa.0108.

--
Best regards,
Bill
Reply | Threaded
Open this post in threaded view
|

Re: Diff Error

A.J.Mechelynck
----- Original Message -----
From: "Bill McCarthy" <[hidden email]>
To: "Vim Developers" <[hidden email]>
Sent: Wednesday, July 13, 2005 4:55 AM
Subject: Diff Error


> Hello Vim Developers,
>
> I used diff to compare two files.  Each file has twelve
> columns of numbers.  Only the 3rd, 7th and 11th columns
> are different.  The vim diff result looks very strange.
>
> I have included the two small files named 'l' and 'r'.
> You can compare them with:
>
>    gvim -u NONE -N -d L R "+se co=125"
>
> Then make the two sides equal with: <C-W>=
>
> The same odd result can be seen in either 6.3.80 or in
> 7.0aa.0108.
>
> --
> Best regards,
> Bill

Diff (or vimdiff) compares lines, not columns. Since no line is the same in
both files (for instance, the 3rd, 7th and 11th numbers in each line are all
zero in R.dat, all nonzero in L.dat) I would expect vimdiff to create a
single fold containing the whole file contents, or diff to create a patch
saying, in effect, "remove all lines from this, add all lines like that".

What are you seeing?


Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: Diff Error

Bill McCarthy
On Tue 12-Jul-05 10:21pm -0500, Tony Mechelynck wrote:

> From: "Bill McCarthy" <[hidden email]>
> To: "Vim Developers" <[hidden email]>
> Sent: Wednesday, July 13, 2005 4:55 AM
> Subject: Diff Error
>
>
>> Hello Vim Developers,
>>
>> I used diff to compare two files.  Each file has twelve
>> columns of numbers.  Only the 3rd, 7th and 11th columns
>> are different.  The vim diff result looks very strange.
>>
>> I have included the two small files named 'l' and 'r'.
>> You can compare them with:
>>
>>    gvim -u NONE -N -d L R "+se co=125"
>>
>> Then make the two sides equal with: <C-W>=
>>
>> The same odd result can be seen in either 6.3.80 or in
>> 7.0aa.0108.
>>
>> --
>> Best regards,
>> Bill
>
> Diff (or vimdiff) compares lines, not columns.

Vim diff does compare columns, but only to a fairly
minor degree.  It shows the left portion that is the
same and the right portion that is the same.  The first
character that is different through the last character
that is different are in a different color - it doesn't
matter whether characters between those points are the
same or different.

I was wrong, I thought it did more.

--
Best regards,
Bill


Reply | Threaded
Open this post in threaded view
|

Re: Diff Error

A.J.Mechelynck
----- Original Message -----
From: "Bill McCarthy" <[hidden email]>
To: "Tony Mechelynck" <[hidden email]>
Cc: "Vim Developers" <[hidden email]>
Sent: Wednesday, July 13, 2005 6:05 AM
Subject: Re: Diff Error
[...]

> Vim diff does compare columns, but only to a fairly
> minor degree.  It shows the left portion that is the
> same and the right portion that is the same.  The first
> character that is different through the last character
> that is different are in a different color - it doesn't
> matter whether characters between those points are the
> same or different.
>
> I was wrong, I thought it did more.
>
> --
> Best regards,
> Bill

Even that is more than I thought it did. -- Thanks anyway: after answering
your post I installed a diff program in the Windows PATH and found a
behaviour similar to what you are describing. However in the first two
lines -- for some reason which I can't fathom -- I see the middle part (in
DiffText highlight) extend up to but not including the 00 at the very end.
(The left and right parts seem to be in DiffChange highlight). IIUC how
these are set is hardcoded; you can only change the colours via the
'highlight' option.

Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: Diff Error

Bill McCarthy
On Tue 12-Jul-05 11:40pm -0500, Tony Mechelynck wrote:

> However in the first two lines -- for some reason
> which I can't fathom -- I see the middle part (in
> DiffText highlight) extend up to but not including
> the 00 at the very end.

Good eye!  That was a creation error on my part.  Both
files were created as extracts from two very large
files.  I transposed the first two rows of the `L` file
in the process.

Reverse those first two rows in `L` and the vimdiff
result looks consistent again.

Now that you have a diff utility installed, I think
you'll enjoy using vimdiff.  Although I've been using
it for years to compare versions of program code, I am
just now understanding what it actually does :-)

--
Best regards,
Bill


Reply | Threaded
Open this post in threaded view
|

vimdiff improvement idea was: Re: Diff Error

Milan Vancura
Hi all,

an idea for improvement: if there is :vimgrep as an alternative to :!grep, what
about :viminternaldiff as an alternative to :!diff ? (The command :vimdiff
will still be working as in nowadays).

Two benefits what we can get with this:

1. faster and OS independent :vimdiff

2. diff algoritm will be implemented in vim itself, so there is a possibility
to apply it for comparation of different lines - so the colorizing of changes
in line will be better (it can compare two lines instead of two files looking
for chars instead of lines, but the algoritm will stay the same)

A disadvantage is obvious also - we can't reimplement all unix utilities in vim
:-)

So what do you think about it?

Milan Vancura
Reply | Threaded
Open this post in threaded view
|

Re: vimdiff improvement idea was: Re: Diff Error

Antony Scriven
On Jul 13, Milan Vancura wrote:

 > Hi all,
 >
 > an idea for improvement: if there is :vimgrep as an
 > alternative to :!grep, what about :viminternaldiff as an
 > alternative to :!diff ? (The command :vimdiff will still
 > be working as in nowadays).
 >
 > [...]
 >
 > So what do you think about it?

:!emacs

Antony
Reply | Threaded
Open this post in threaded view
|

Re: Diff Error

A.J.Mechelynck
In reply to this post by Bill McCarthy
----- Original Message -----
From: "Bill McCarthy" <[hidden email]>
To: "Tony Mechelynck" <[hidden email]>
Cc: "Vim Developers" <[hidden email]>
Sent: Wednesday, July 13, 2005 2:42 PM
Subject: Re: Diff Error
[...]

> Now that you have a diff utility installed, I think
> you'll enjoy using vimdiff.  Although I've been using
> it for years to compare versions of program code, I am
> just now understanding what it actually does :-)

Now that I'm starting to understand what its output looks like, I may also
use it to produce unified diffs for the 'patch' utility -- e.g. when
suggesting a change in a vim helpfile (I don't mess with vim program code --  
yet?)

Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: vimdiff improvement idea was: Re: Diff Error

A.J.Mechelynck
In reply to this post by Milan Vancura
----- Original Message -----
From: "Milan Vancura" <[hidden email]>
To: "Vim development list" <[hidden email]>
Sent: Wednesday, July 13, 2005 3:54 PM
Subject: vimdiff improvement idea was: Re: Diff Error


> Hi all,
>
> an idea for improvement: if there is :vimgrep as an alternative to :!grep,
> what
> about :viminternaldiff as an alternative to :!diff ? (The command :vimdiff
> will still be working as in nowadays).
>
> Two benefits what we can get with this:
>
> 1. faster and OS independent :vimdiff
>
> 2. diff algoritm will be implemented in vim itself, so there is a
> possibility
> to apply it for comparation of different lines - so the colorizing of
> changes
> in line will be better (it can compare two lines instead of two files
> looking
> for chars instead of lines, but the algoritm will stay the same)
>
> A disadvantage is obvious also - we can't reimplement all unix utilities
> in vim
> :-)
>
> So what do you think about it?
>
> Milan Vancura

IIUC, there is no ":vimdiff" Vim command, just (on some systems) a "vimdiff"
shell command which can be (on systems which support them) a soft link or a
shell alias for vim -d or even (IIUC) for vim.

Implementing ":vimgrep" was (IIUC) easy once ":helpgrep" existed and worked,
using preexisting vim regexps. I suppose introducing an internal ":diff"
command would require funneling into Vim the whole source of the diff
program, to little advantage, and with the risk of bugs (e.g. typos). Also,
IIUC "diff" compares lines only; the additional comparing inside a changed
line is made by vim itself anyway. The algorithm won't "stay the same";
comparing character-by-character instead of line-by-line and deciding for
every character whether or not to match at a _different_ place (earlier or
later) would (I expect) make the whole process something like 60 times
slower if the lines are, on average, 60 characters long. Maybe even slower
than that since a single character can match at many places while a line
will only match at a few places, possibly just at one place.


Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: vimdiff improvement idea was: Re: Diff Error

Gautam Iyer
In reply to this post by Antony Scriven
On Wed, Jul 13, 2005 at 03:24:32PM +0100, Antony Scriven wrote:

>  > Hi all,
>  >
>  > an idea for improvement: if there is :vimgrep as an
>  > alternative to :!grep, what about :viminternaldiff as an
>  > alternative to :!diff ? (The command :vimdiff will still
>  > be working as in nowadays).
>  >
>  > [...]
>  >
>  > So what do you think about it?
>
> :!emacs

This one's easy:

    $ sleep 10000
    $ echo "Not enough memory"
    $ exit 1

:)

GI

--
'Budget' -- A method for going broke methodically.
Reply | Threaded
Open this post in threaded view
|

Re: vimdiff improvement idea was: Re: Diff Error

François Pinard
In reply to this post by A.J.Mechelynck
[Tony Mechelynck]

> [Milan Vancura]

> > what about :viminternaldiff as an alternative to :!diff ? [...] so
> > there is a possibility to apply it for comparation of different
> > [things than?] lines

> I suppose introducing an internal ":diff" command would require
> funneling into Vim the whole source of the diff program, to little
> advantage, and with the risk of bugs (e.g. typos).

Beware my naive reply: I did not look into this in the context of Vim.

If I had no choice but to want my own `diff' in Vim, I would liklely
try using Python library's `difflib' from within a Python-enabled
Vim.  The real problem would then be to find out how I could get all
the `diff/diff3' output processing, which is already built-in Vim, to
interface with `difflib' instead of the external `diff{,3}' programs.

I once had a very similar problem under Emacs, and then chose to hijack
that part of `emerge' which decodes the output of the `diff3' program,
turning it into a list of line references, for the remainder of `emerge'
to exclusively use afterwards.  The surgery was quite successful, and
the result, very satisfying.  I wonder if such an approach would somehow
work for Vim, nor the amount of internal changes it would imply.

--
Fran?ois Pinard   http://pinard.progiciels-bpi.ca
Reply | Threaded
Open this post in threaded view
|

vimdiff improvement idea was: Re: Diff Error

Bram Moolenaar
In reply to this post by Milan Vancura

Milan Vancura wrote:

> an idea for improvement: if there is :vimgrep as an alternative to
> :!grep, what about :viminternaldiff as an alternative to :!diff ? (The
> command :vimdiff will still be working as in nowadays).
>
> Two benefits what we can get with this:
>
> 1. faster and OS independent :vimdiff
>
> 2. diff algoritm will be implemented in vim itself, so there is a
> possibility to apply it for comparation of different lines - so the
> colorizing of changes in line will be better (it can compare two lines
> instead of two files looking for chars instead of lines, but the
> algoritm will stay the same)
>
> A disadvantage is obvious also - we can't reimplement all unix
> utilities in vim :-)
>
> So what do you think about it?

The big difference between grep and diff is that Vim already has pattern
matching code, thus implementing a grep command does not require adding
a lot of complicated code.  If you look at the source code of a diff
program you will find that it is rather complicated.  I looked into this
when adding the diff functionality, but found the extra code to be too
much to include inside Vim.  There also is no performance requirement
(like with the spell code).

The main disadvantage with an external diff program is that you need to
have one.  Mainly a problem on non-Unix systems, since it's standard on
Unix.

--
Nothing is impossible for the man who doesn't have to do it.

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\     Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html   ///