Added configurable DateIsInRange() function, and fixed off-by-one error.

This commit is contained in:
Bradley M. Kuhn 2010-06-26 14:09:46 -04:00
parent 7acc424f94
commit c60ad63df1
3 changed files with 19 additions and 6 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
*~ *~
date-range-1.pl

8
date-range-all.pl Normal file
View file

@ -0,0 +1,8 @@
use strict;
use warnings;
sub DateIsInRange ($) {
return 1;
}
1;

View file

@ -25,10 +25,14 @@
use strict; use strict;
use warnings; use warnings;
if (@ARGV != 1) { if (@ARGV != 2) {
print STDERR "usage: $0 <GIT_COMMAND_STRING>\n"; print STDERR "usage: $0 <GIT_COMMAND_STRING> <DATE_RANGE_CODE_FILE>\n";
exit 1;
} }
my($GIT_CMD) = @ARGV; my($GIT_CMD, $DATE_RANGE_CODE_FILE) = @ARGV;
# DATE_RANGE_CODE_FILE must define a one-arg function called DateIsInRange()
require "$DATE_RANGE_CODE_FILE";
$GIT_CMD .= " --no-color"; $GIT_CMD .= " --no-color";
$GIT_CMD .= " --date=rfc" unless $GIT_CMD =~ /--date/; $GIT_CMD .= " --date=rfc" unless $GIT_CMD =~ /--date/;
@ -38,16 +42,16 @@ open(GIT_OUTPUT, "-|", $GIT_CMD) or die "unable to run \"$GIT_CMD\": $!";
my $currentCommit = ""; my $currentCommit = "";
my $skipThisOne = 1; my $skipThisOne = 1;
while (my $line = <GIT_OUTPUT>) { while (my $line = <GIT_OUTPUT>) {
if ($line =~ /^\s*commit\s+/i) { if ($line =~ /^\s*commit\s+([\dA-F]+)\s*$/i) {
print $currentCommit unless $skipThisOne; print $currentCommit unless $skipThisOne;
$skipThisOne = 0; $skipThisOne = 0;
$currentCommit = ""; $currentCommit = "";
} elsif ($line =~ /^\s*Date\s*:\s*(\S+)\s*,/i) { #Warning: assumes --date=rfc } elsif ($line =~ /^\s*Date\s*:\s*(\S+)\s*,/i) { #Warning: assumes --date=rfc
my $day = $1; $skipThisOne = not DateIsInRange($1);
$skipThisOne = ($day !~ /(Sat|Sun)/i);
} }
$currentCommit .= $line; $currentCommit .= $line;
} }
print $currentCommit unless $skipThisOne;
close GIT_OUTPUT; close GIT_OUTPUT;
die "non-zero exit code on \"$GIT_CMD\": $!" unless $? == 0; die "non-zero exit code on \"$GIT_CMD\": $!" unless $? == 0;
############################################################################### ###############################################################################