~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to fai/aba/commands/cdiff

  • Committer: Aaron Bentley
  • Date: 2005-06-07 18:52:04 UTC
  • Revision ID: abentley@panoramicfeedback.com-20050607185204-5fc1f0e3d393b909
Added NEWS, obsoleted bzr-pull

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl
2
 
## Copyright (C) 2004 Jan Hudec
3
 
##
4
 
## See the file "COPYING" for further information about
5
 
## the copyright and warranty status of this work.
6
 
 
7
 
%color = (
8
 
    black => 30,
9
 
    red => 31,
10
 
    green => 32,
11
 
    yellow => 33,
12
 
    blue => 34,
13
 
    magenta => 35,
14
 
    cyan => 36,
15
 
    white => 37,
16
 
    bk => 30,
17
 
    re => 31,
18
 
    gr => 32,
19
 
    ye => 33,
20
 
    bl => 34,
21
 
    ma => 35,
22
 
    cy => 36,
23
 
    wh => 37
24
 
);
25
 
 
26
 
sub bold {
27
 
    my ($color, $string) = @_;
28
 
    $color = $color{$color} if exists $color{$color};
29
 
    print "\e[${color};1m${string}\e[0m\n";
30
 
}
31
 
 
32
 
sub norm {
33
 
    my ($color, $string) = @_;
34
 
    $color = $color{$color} if exists $color{$color};
35
 
    print "\e[${color}m${string}\e[0m\n";
36
 
}
37
 
 
38
 
sub exe {
39
 
    if($] >= 5.008) { # 5.8 has a sane syntax...
40
 
        open STDIN, '-|', qw(tla changes --diffs), @_ or die "Can't run tla";
41
 
    } else { # 5.6's weird syntax...
42
 
        open(STDIN, '-|') || exec(qw(tla changes --diffs), @_) || die "Can't run tla";
43
 
    }
44
 
    eval {
45
 
        open WP, "|diffstat";
46
 
    } or open WP, ">/dev/null";
47
 
 
48
 
    $| = 1;
49
 
    while(<STDIN>) {
50
 
        $o = $_;
51
 
        chomp $_;
52
 
        /^(\*\s)/               ? bold wh => $_ :
53
 
        /^(?:\+\+\+|---)/       ? norm gr => $_ :
54
 
        /^\+/           ? bold cy => $_ :
55
 
        /^-/            ? bold re => $_ :
56
 
        /^!/            ? bold bl => $_ :
57
 
        /^diff/         ? norm cy => $_ :
58
 
        /(\@\@.*\@\@)(.*)/      ? print "\e[$color{ye};1m$1\e[$color{wh};1m$2\e[0m\n" :
59
 
                              print $_, "\n";
60
 
        print WP $o;
61
 
    }
62
 
 
63
 
    print "---------------------\n";
64
 
    close WP;
65
 
    wait;
66
 
    wait;
67
 
}
68
 
 
69
 
sub desc {
70
 
    printf "%28s : %s\n", 'cdiff', "tla changes --diffs with pretty colors and summary";
71
 
}
72
 
 
73
 
sub help {
74
 
    print "Generate changes report with pretty colored diffs and diffs summary.\n";
75
 
}
76
 
 
77
 
sub ext_help {
78
 
    help;
79
 
    print <<EOS
80
 
It is similar to tla changes --diffs, but colorizes the diff and adds output of
81
 
diffstat (if you have it) to the end.
82
 
Highlighting colours headers green, additions cyan, deletions red and tla
83
 
messages (those with * at the beginning) just bold (everything is bold).
84
 
EOS
85
 
}
86
 
 
87
 
if ($ARGV[0] eq 'desc') {
88
 
    desc;
89
 
} elsif ($ARGV[0] eq 'exec') {
90
 
    if ($ARGV[1] eq '-h' or $ARGV[1] eq '--help') {
91
 
        help;
92
 
    } elsif ($ARGV[1] eq '-H') {
93
 
        ext_help;
94
 
    } else {
95
 
        exe(@ARGV[1 .. $#ARGV]);
96
 
    }
97
 
} else {
98
 
    die "Invalid parameters. This script is designed to be run by aba only."
99
 
}
100
 
 
101
 
# arch-tag: 689f32af-bac3-4621-8697-fd29951bb777