Monday, 1 February 2010

Colorised svn diffs

With the help of colordiff my svn diffing just got a whole lot prettier:
% svn diff --diff-cmd colordiff -x -w files |\
    less -RS
(I like to pass -w to the diff-er to ignore whitespace changes). Piping through less in raw mode (-r/-R) interprets the colour escape-sequences correctly.

Thanks to commandlinefu for the idea.

1 comment:

  1. Thanks for the great tip Mat.

    I was wondering whether this could get put into ~/.subversion/config somehow so that you just had to do a

    svn diff file

    command. From what I can see the labels have to be parsed to put then in quotes.

    So I created a little perl script (see below) called mydiff.pl which I put in my binary area "~/bin", and edited my ~/.subversion/config so that it contains the line:

    diff-cmd = /bin/mydiff.pl


    Anyway here is the perl script:

    #!/usr/bin/perl

    my @args = ();
    my $L = 0;
    my $carg='';

    while (<@ARGV>) {
    if ($L==1) {
    $carg = $_;
    $carg ="\"".$carg;
    $L++;
    next;
    } elsif ($L>1) {
    $carg = $carg." ".$_;
    if (m/\)$/) {
    $carg = $carg."\" ";
    $L = 0;
    } else {
    next;
    }
    } else {
    $carg = $_;
    if (m/^\-L/) {$L++;}
    }
    push @args,$carg;
    }

    system ("/usr/bin/colordiff -x -w -B @args");

    ReplyDelete

NAG moderates all replies and reserves the right to not publish posts that are deemed inappropriate.