From: Todd C. Miller Date: Sun, 10 Dec 2017 20:39:41 +0000 (-0700) Subject: Use log size instead of using a separator between the log entry and X-Git-Tag: SUDO_1_8_22^2~43 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a388ddbcf5c5e3ab074b9f57b5e65a42c83e45a6;p=sudo Use log size instead of using a separator between the log entry and the file names. --- diff --git a/log2cl.pl b/log2cl.pl index de3502d7a..af3eddc64 100755 --- a/log2cl.pl +++ b/log2cl.pl @@ -19,7 +19,7 @@ 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); open(LOG, '-|', @cmd) || die "$0: unable to run git log: $!"; @@ -28,53 +28,50 @@ my $body; my @files; my $key_date = ""; my $log_size = 0; -my $state = 0; +my @lines; while () { chomp; if (/^log size (\d+)$/) { - # XXX - should use log_size to make sure we get the entire entry $log_size = $1; # Print previous entry if there is one print_entry($hash, $body, @files) if defined($hash); # Init new entry - $state = 1; undef $hash; undef $body; undef @files; + undef @lines; - # Check for continued entry - $_ = ; - last unless defined($_); - chomp; + # Read entry and split on newlines + read(LOG, my $buf, $log_size) || + die "$0: unable to read $log_size bytes: $!\n"; + @lines = split(/\r?\n/, $buf); + + # Check for continued entry (duplicate Date + Author) + $_ = shift(@lines); if ($_ ne $key_date) { # New entry print "$_\n\n"; $key_date = $_; } - } elsif (/^FILES:$/) { - $state = 3; - } else { - if ($state == 1) { - # hash - $hash = $_; - $state++; - } elsif ($state == 2) { - # multi-line message body + + # Hash comes first + $hash = shift(@lines); + + # Commit message body (multi-line) + foreach (@lines) { if (defined($body)) { $_ = "\r" if $_ eq ""; $body .= " $_"; } else { $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 ""; } }