~abentley/bzrtools/bzrtools.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/perl
## Copyright (C) 2004 Jan Hudec
##
## See the file "COPYING" for further information about
## the copyright and warranty status of this work.

%color = (
    black => 30,
    red => 31,
    green => 32,
    yellow => 33,
    blue => 34,
    magenta => 35,
    cyan => 36,
    white => 37,
    bk => 30,
    re => 31,
    gr => 32,
    ye => 33,
    bl => 34,
    ma => 35,
    cy => 36,
    wh => 37
);

sub bold {
    my ($color, $string) = @_;
    $color = $color{$color} if exists $color{$color};
    print "\e[${color};1m${string}\e[0m\n";
}

sub norm {
    my ($color, $string) = @_;
    $color = $color{$color} if exists $color{$color};
    print "\e[${color}m${string}\e[0m\n";
}

sub exe {
    if($] >= 5.008) { # 5.8 has a sane syntax...
	open STDIN, '-|', qw(tla changes --diffs), @_ or die "Can't run tla";
    } else { # 5.6's weird syntax...
	open(STDIN, '-|') || exec(qw(tla changes --diffs), @_) || die "Can't run tla";
    }
    eval {
	open WP, "|diffstat";
    } or open WP, ">/dev/null";

    $| = 1;
    while(<STDIN>) {
	$o = $_;
	chomp $_;
	/^(\*\s)/		? bold wh => $_ :
	/^(?:\+\+\+|---)/	? norm gr => $_ :
	/^\+/		? bold cy => $_ :
	/^-/		? bold re => $_ :
	/^!/		? bold bl => $_ :
	/^diff/		? norm cy => $_ :
	/(\@\@.*\@\@)(.*)/	? print "\e[$color{ye};1m$1\e[$color{wh};1m$2\e[0m\n" :
			      print $_, "\n";
	print WP $o;
    }

    print "---------------------\n";
    close WP;
    wait;
    wait;
}

sub desc {
    printf "%28s : %s\n", 'cdiff', "tla changes --diffs with pretty colors and summary";
}

sub help {
    print "Generate changes report with pretty colored diffs and diffs summary.\n";
}

sub ext_help {
    help;
    print <<EOS
It is similar to tla changes --diffs, but colorizes the diff and adds output of
diffstat (if you have it) to the end.
Highlighting colours headers green, additions cyan, deletions red and tla
messages (those with * at the beginning) just bold (everything is bold).
EOS
}

if ($ARGV[0] eq 'desc') {
    desc;
} elsif ($ARGV[0] eq 'exec') {
    if ($ARGV[1] eq '-h' or $ARGV[1] eq '--help') {
	help;
    } elsif ($ARGV[1] eq '-H') {
	ext_help;
    } else {
	exe(@ARGV[1 .. $#ARGV]);
    }
} else {
    die "Invalid parameters. This script is designed to be run by aba only."
}

# arch-tag: 689f32af-bac3-4621-8697-fd29951bb777