Skip to content

Commit

Permalink
similar: En-repo a quick diffing tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosuav committed Oct 3, 2015
1 parent 539241a commit 87e8f6f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions similar.pike
@@ -0,0 +1,17 @@
//Find the most similar pair of a set of files
//All arguments that can be statted are files; all others are passed on to diff(1).
//All pairs of files are tested exhaustively (though only 'forwards' - the same files
//in the other order won't be tested), and whichever pair results in the least bytes
//of diff output is printed to stdout.
int main(int argc,array(string) argv)
{
array(string) files=filter(argv[1..],file_stat);
array(string) args=argv[1..]-files;
string bestoutput;
foreach (files;int i;string fn1) foreach (files[i+1..],string fn2)
{
string output=Process.run(({"diff"})+args+({fn1,fn2}))->stdout;
if (!bestoutput || sizeof(bestoutput)>sizeof(output)) bestoutput=output;
}
write(bestoutput);
}

0 comments on commit 87e8f6f

Please sign in to comment.