-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhglogsummary
More file actions
executable file
·233 lines (212 loc) · 5.89 KB
/
hglogsummary
File metadata and controls
executable file
·233 lines (212 loc) · 5.89 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/env perl
#
# This script will accept an hg log as input on stdin, and produce an output
# which can be copied and pasted into the debian/changelog, as a series of
# bulletpoints.
#
use Getopt::Std;
use strict;
use warnings;
use diagnostics;
use constant EXIT_SUCCESS => (0);
use constant EXIT_FAILURE => (1);
use constant TRUE => (1);
use constant FALSE => (0);
use constant CHANGESET_LINE => qr/^changeset\:\s+(\d+)\:([0-9a-f]{12})$/;
use constant SUMMARY_LINE => qr/^summary\:\s+(.*)$/;
use constant DESC_LINE => qr/^description:/;
use constant PARENT_LINE => qr/^parent\:\s+\d+\:([0-9a-f]{12})$/;
use constant BRANCH_LINE => qr/^branch\:\s+(.*)$/;
use constant USER_LINE => qr/^user\:\s+(.*)\s+\<.*\>$/;
use constant DATE_LINE => qr/^date\:\s*(.*)$/;
my $LimitChangeSetReached = 0;
my $ChangeSetsPrinted = 0;
sub PrintLog(@);
sub Process($$$$$$$$$$$$$);
sub Main();
sub PrintLog(@)
{
my $info = '';
my %Params = @_;
return 0 if ( $LimitChangeSetReached );
return 0 if ( $Params{'ParentCount'} < 2 && $Params{'MergesOnly'} );
if ( $Params{'Criteria'} ) {
if (index($Params{'Summary'}, $Params{'Criteria'}) == -1) {
return 0;
}
}
if ( $Params{'BranchRestrict'} ) {
if ( $Params{'BranchRestrict'} ne $Params{'Branch'} ) {
return 0;
}
}
if ( $Params{'UserRestrict'} ) {
if ( $Params{'UserRestrict'} ne $Params{'User'} ) {
return 0;
}
}
if ( $Params{'LimitLogCount'} && $ChangeSetsPrinted == $Params{'LimitLogCount'} ) {
$LimitChangeSetReached = 1;
return 0;
}
$ChangeSetsPrinted++;
$info .= $Params{'User'} . ', ' if ( $Params{'ShowUser'} );
$info .= $Params{'Date'} . ', ' if ( $Params{'ShowDate'} );
$info .= $Params{'ChangeLocalId'} . ':' if ( $Params{'IncludeLocal'} );
$info .= $Params{'ChangeId'};
$info .= ' (' . $Params{'Branch'} . ')' if ( $Params{'ShowBranch'} );
push(@{ $Params{'Output'} }, sprintf(" * %s: %s\n", $info, $Params{'Summary'}));
if ( $Params{'LimitChangeSet'} && $Params{'LimitChangeSet'} eq $Params{'ChangeId'} ) {
$LimitChangeSetReached = 1;
}
return 1;
}
sub Process($$$$$$$$$$$$$)
{
my (
$Output, $Input, $MergesOnly, $BranchRestrict, $LimitChangeSet,
$LimitLogCount, $ShowUser, $User, $IncludeLocal, $RealBranch,
$ShowBranch, $ShowDate, $Criteria,
) = @_;
my ( $inChangeSet, $mergeSet, $thisBranch, $thisUser, $thisDate ) = ( 0, 0, 'default', 'nobody', 'epoch' );
my $chId = '0' x 12;
my $chLocalId = -1;
my $inDesc = 0;
my $printLog = 0;
my $desc = '';
$BranchRestrict = $RealBranch if ( $BranchRestrict && $BranchRestrict eq '.' );
foreach my $inputLine ( @$Input ) {
chomp($inputLine);
if ( $inChangeSet && $inDesc ) {
$inDesc = 0;
$desc = $inputLine;
$printLog++;
}
if ( !$inChangeSet && $inputLine =~ CHANGESET_LINE() ) {
$chLocalId = $1;
$chId = $2;
$inChangeSet = 1;
$mergeSet = 0;
$thisBranch = 'default';
next;
}
if ( $inChangeSet && ( $inputLine =~ SUMMARY_LINE() || $inputLine =~ DESC_LINE() && ($inDesc = 1)) ) {
if ( !$inDesc ) {
$desc = $1;
$printLog++;
$inChangeSet = 0;
}
next;
}
if ( $printLog ) {
PrintLog(
'Output' => $Output, 'ChangeId' => $chId, 'Summary' => $desc,
'MergesOnly' => $MergesOnly, 'ParentCount' => $mergeSet,
'BranchRestrict' => $BranchRestrict, Branch => $thisBranch,
'LimitChangeSet' => $LimitChangeSet, 'LimitLogCount' => $LimitLogCount,
'IncludeLocal' => $IncludeLocal,
'User' => $thisUser, 'ShowUser' => $ShowUser,
'UserRestrict' => $User, 'ChangeLocalId' => $chLocalId,
'ShowBranch' => $ShowBranch, 'ShowDate' => $ShowDate, 'Date' => $thisDate,
'Criteria' => $Criteria,
);
$printLog = 0;
$desc = '';
$inChangeSet = 0;
}
next unless ( $inChangeSet );
if ( $inputLine =~ PARENT_LINE() ) {
$mergeSet++;
} elsif ( $inputLine =~ BRANCH_LINE() ) {
$thisBranch = $1;
} elsif ( $inputLine =~ USER_LINE() ) {
$thisUser = $1;
} elsif ( $inputLine =~ DATE_LINE() ) {
$thisDate = $1;
}
}
}
sub realBranch() {
if ( open(my $h, '<', '.hg/branch') ) {
my $realBranch = <$h>;
chomp($realBranch);
close($h);
return $realBranch;
}
return 'default';
}
sub Main()
{
my $readStdin = 0;
my (@input, @output);
my %opts = ( );
my ( $limitChangeSet, $limitLogCount ) = ( undef, 0 );
my $realBranch = realBranch();
if ( !$realBranch ) {
printf(STDERR "Error reading branch name: %s\n", $!);
return EXIT_FAILURE();
}
# -u restrict to user
# -B show branch
# -U show user
# -l limit,
# -b branch,
# -i input,
# -o output (defaults to stdin/stdout).
# -m Merges only,
# -L Include local changeset IDs,
# -k key (summary grep)
getopts('Bu:Ul:b:i:o:mLDk:', \%opts);
foreach (@ARGV) {
if ($_ eq '-') {
$readStdin++;
last;
}
}
if ( defined($opts{'l'}) ) {
my $l = $opts{'l'};
if ( $l =~ m/^[0-9a-f]{12}$/ ) {
$limitChangeSet = $l; # A changeset which sets a barrier on reporting
} elsif ( $l =~ m/^\d+$/ ) {
$limitLogCount = $l; # A limit of number of printed summaries
} else {
printf(STDERR "Error: Invalid -l parameter, must be changeset hash or numeric limit: %s\n", $l);
return EXIT_FAILURE();
}
}
if ( defined($opts{'i'}) && length($opts{'i'}) ) {
if ( open(my $f, '<', $opts{'i'}) ) {
@input = <$f>;
close($f);
} else {
printf(STDERR "Error reading \'%s\' - %s\n", $opts{'i'}, $!);
return EXIT_FAILURE();
}
} else {
if ($readStdin) {
@input = <STDIN>;
} else {
@input = `hg log`;
}
}
Process(\@output, \@input, $opts{'m'}, $opts{'b'}, $limitChangeSet, $limitLogCount, $opts{'U'}, $opts{'u'}, $opts{'L'}, $realBranch, $opts{'B'}, $opts{'D'}, $opts{k});
if ( defined($opts{'o'}) && length($opts{'o'}) ) {
my $err = TRUE();
if ( open(my $f, '>', $opts{'o'}) ) {
$err = FALSE();
if ( !print($f @output) ) {
$err = TRUE();
last;
}
close($f);
}
if ( $err ) {
printf(STDERR "Error writing \'%s\' - %s\n", $opts{'o'}, $!);
return EXIT_FAILURE();
}
} else {
print @output;
}
return EXIT_SUCCESS();
}
exit(Main());