Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find the patience diff implemented?

It is well-answered on this site that Bram Cohen's patience diff is found in bazaar as the default diff and as an option with git diff, but I am finding it difficult to source an independent standalone program that implements this particular diff algorithm.

For example I'd like to apply patience diff to perforce diffs, and it's pretty clear with the canonical "frobnitz" code example how patience diff is better:

enter image description here

The terminal on the right has invoked the git diff with the --patience flag.

I also have set up the diff-highlight perl script, whose job it is to invert colors on matched-up lines between the first and last different sections of those lines. The left side has an example where this doesn't quite help so much but I'll let it slide because at least there is that semicolon there... Anyway, making improvements to the diff-highlight script is not the subject of this question.

In addition to the question of where to find a standalone patience diff, if anybody knows how to make perforce p4 use an external diff program, that's also something that has to be done.

like image 806
Steven Lu Avatar asked Apr 17 '13 17:04

Steven Lu


People also ask

What is patience diff?

patience: Patience diff and longest increasing subsequence Patience diff computes the difference between two lists, for example the lines of two versions of a source file. It provides a good balance of performance, nice output for humans, and implementation simplicity.

What is diff algorithm?

A diff algorithm outputs the set of differences between two inputs. These algorithms are the basis of a number of commonly used developer tools. Yet understanding the inner workings of diff algorithms is rarely necessary to use said tools.


2 Answers

For a javascript implementation, with enhancements to PatienceDiff to determine the lines that likely moved (dubbed "PatienceDiffPlus"), see https://github.com/jonTrent/PatienceDiff.

like image 123
Trentium Avatar answered Sep 19 '22 08:09

Trentium


It's perhaps not as ideal as I'd like it, but the solution is perfectly good from a practical perspective (and thats a damn good perspective to have).

git diff --no-index --patience file1 file2 does the job. (thanks @StevenPenny)

$P4DIFF variable defines the external diff... we just stuff git diff --patience --no-index into that.

like image 23
Steven Lu Avatar answered Sep 18 '22 08:09

Steven Lu