2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-22 18:08:23 +00:00

Use log size instead of using a separator between the log entry and

the file names.
This commit is contained in:
Todd C. Miller 2017-12-10 13:39:41 -07:00
parent d322caf7ac
commit a388ddbcf5

View File

@ -19,7 +19,7 @@
use warnings; use warnings;
my $format="%ad %aN <%aE>%n%h%n%B%nFILES:"; my $format="%ad %aN <%aE>%n%h%n%B%n";
my @cmd = ("git", "log", "--log-size", "--name-only", "--date=short", "--format=$format", @ARGV); my @cmd = ("git", "log", "--log-size", "--name-only", "--date=short", "--format=$format", @ARGV);
open(LOG, '-|', @cmd) || die "$0: unable to run git log: $!"; open(LOG, '-|', @cmd) || die "$0: unable to run git log: $!";
@ -28,53 +28,50 @@ my $body;
my @files; my @files;
my $key_date = ""; my $key_date = "";
my $log_size = 0; my $log_size = 0;
my $state = 0; my @lines;
while (<LOG>) { while (<LOG>) {
chomp; chomp;
if (/^log size (\d+)$/) { if (/^log size (\d+)$/) {
# XXX - should use log_size to make sure we get the entire entry
$log_size = $1; $log_size = $1;
# Print previous entry if there is one # Print previous entry if there is one
print_entry($hash, $body, @files) if defined($hash); print_entry($hash, $body, @files) if defined($hash);
# Init new entry # Init new entry
$state = 1;
undef $hash; undef $hash;
undef $body; undef $body;
undef @files; undef @files;
undef @lines;
# Check for continued entry # Read entry and split on newlines
$_ = <LOG>; read(LOG, my $buf, $log_size) ||
last unless defined($_); die "$0: unable to read $log_size bytes: $!\n";
chomp; @lines = split(/\r?\n/, $buf);
# Check for continued entry (duplicate Date + Author)
$_ = shift(@lines);
if ($_ ne $key_date) { if ($_ ne $key_date) {
# New entry # New entry
print "$_\n\n"; print "$_\n\n";
$key_date = $_; $key_date = $_;
} }
} elsif (/^FILES:$/) {
$state = 3; # Hash comes first
} else { $hash = shift(@lines);
if ($state == 1) {
# hash # Commit message body (multi-line)
$hash = $_; foreach (@lines) {
$state++;
} elsif ($state == 2) {
# multi-line message body
if (defined($body)) { if (defined($body)) {
$_ = "\r" if $_ eq ""; $_ = "\r" if $_ eq "";
$body .= " $_"; $body .= " $_";
} else { } else {
$body = $_; $body = $_;
} }
} elsif ($state == 3) {
# file list
push(@files, $_) unless $_ eq "";
} else {
warn "unexpected state $state for $_\n";
} }
} else {
# Not a log entry, must be the file list
push(@files, $_) unless $_ eq "";
} }
} }