Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives to GNU diff?

Tags:

diff

diff usually produces rather clueless output. Here's a good example. If we start with this:

class World
  def hello
    puts "Hello, world"
  end
  def goodbye
    puts "Goodbye, world"
  end
end

Drop the second method and change the first:

class World
  def hello
    puts "Hello, #{self}"
  end
end

diff -u will be a total mess - suggesting two methods have been merged:

 class World
   def hello
-    puts "Hello, world"
-  end
-  def goodbye
-    puts "Goodbye, world"
+    puts "Hello, #{self}"
   end
 end

Instead of much more reasonable:

 class World
   def hello
-    puts "Hello, world"
+    puts "Hello, #{self}"
   end
-  def goodbye
-    puts "Goodbye, world"
-  end
 end

This is just a toy example, so diff's output is still possible to understand - in practice it usually gets a lot worse.

Are there any alternatives to diff that might be somewhat smarter?

like image 418
taw Avatar asked Jul 29 '10 04:07

taw


2 Answers

The rfcdiff (Draft Diff Tool) reported this:

enter image description here

The tool uses GNU diff and wdiff.

like image 131
linuxbuild Avatar answered Sep 27 '22 22:09

linuxbuild


You might consider our SD Smart Differencer. It provides differences based on the structure of the code rather than "line differences", so it is focused on language elements (expressions, statements, blocks, methods) and editing actions (delete, insert, copy, replace, rename).

It is language specific; it has to be to use language structure as a guide. It uses an explicit langauge definition. I can't quite tell what langauge you are using (Python?). There are Smart Differencer tools for many langauges, including C, C++, C#, Java, Python, Fortran, COBOL, ...

like image 29
Ira Baxter Avatar answered Sep 27 '22 21:09

Ira Baxter