-
Notifications
You must be signed in to change notification settings - Fork 4
/
sortcvs
executable file
·102 lines (87 loc) · 2.49 KB
/
sortcvs
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
102
#!/usr/bin/env perl
#==============================================================================
# sortcvs
# File ID: 440141ba-5d44-11df-8e85-90e6ba3022ac
# Sorts the output from "cvs log" into chronological order.
# Made by Øyvind A. Holm <sunny@sunbase.org>
# License: GNU General Public License version 2 or later.
#==============================================================================
use strict;
use warnings;
use Getopt::Std;
our ($opt_a, $opt_h) =
( 0, 0);
getopts('ah');
$opt_h && print_help(0);
my ($curr_date, $curr_rev) = ("", "");
my @Curr = ();
my %Entry = ();
my $Rev = "";
my $Line = "";
while (<>) {
$Line = $_;
if ($Line =~ /^----------------------------$/) {
if (length($Rev) && scalar(@Curr)) {
$Entry{$Rev} = join("", @Curr);
}
@Curr = ();
push(@Curr, $Line);
$Line = <>;
if ($Line =~ /^revision (\S+)/) {
$curr_rev = $1;
} else {
warn("Expected \"revision: \", got \"$Line\".\"");
}
push(@Curr, $Line);
$Line = <>;
if ($Line =~ /^date: (\S+\s+\S+) .*/) {
$curr_date = $1;
} else {
warn("Expected \"date: \", got \"$Line\".\"");
}
push(@Curr, $Line);
# $Rev = unpack("H*", "$curr_date$curr_rev");
$Rev = "$curr_date$curr_rev";
} elsif ($Line =~ /^=============================================================================$/ && !$opt_a) {
if (length($Rev) && scalar(@Curr)) {
$Entry{$Rev} = join("", @Curr);
}
my @Arr = ();
while (my ($l_name, $l_val) = each %Entry) {
push(@Arr, $l_name);
}
for (sort @Arr) {
print($Entry{$_});
}
($curr_date, $curr_rev, $Rev) = ("", "", "");
%Entry = ();
@Curr = ();
print("$Line");
} else {
if (length($Rev)) {
push(@Curr, $_);
} else {
print("$Line");
}
}
}
sub print_help {
my $Retval = shift;
print("No help yet.\n");
exit($Retval);
}
=pod
=head1 LICENCE
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
=cut
__END__