From: Francois Gouget Subject: [Tools 1/2] winetest/build-index: Factorize the Git commit info and date formatting code. Message-Id: Date: Tue, 21 Mar 2017 00:08:19 +0100 (CET) This clarifies the code, removes a bit of duplication and makes it easier to reuse that code elsewhere. Signed-off-by: Francois Gouget --- I plan on reusing (aka copy/pasting) this code in gather and dissect. I'm not entirely sure if the call to utime should stay out of get_build_info() or not given that this code will be copy/pasted. Resetting it there ensure the directory has the date we want pretty much at all times but it's also likely overkill. I'm also not entirely sure this date matters all that much since we should really only be dealing with valid build ids. If anyone has advice... The use of a relative-path and hardcoded 'data' directory is also questionable but there is a lot more to do on that front so I'll fix that in a later patch. Still, as far as behavior goes this patch should be a no-op. winetest/build-index | 59 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/winetest/build-index b/winetest/build-index index e15792c..9a67d15 100755 --- a/winetest/build-index +++ b/winetest/build-index @@ -23,7 +23,6 @@ use strict; use warnings; use open ':utf8'; use CGI qw(:standard); -use POSIX qw(strftime); sub BEGIN { @@ -43,6 +42,41 @@ binmode STDOUT, ':utf8'; $ENV{GIT_DIR} = $gitdir; +sub get_build_info($) +{ + my ($build) = @_; + my ($date, $subject); + + my $commit = `git log --max-count=1 --pretty="format:%ct %s" "$build^0" 2>/dev/null` if ($build =~ /^[0-9a-f]{40}$/); + if ($commit && $commit =~ /^(\d+) (.*)$/) + { + ($date, $subject) = ($1, $2); + # Make sure the directory's mtime matches the commit time + utime $date, $date, "data/$build"; + } + else + { + $date = (stat "./data/$build")[9]; + $subject = ""; + } + return ($date, $subject); +} + +use POSIX qw(strftime); + +sub short_date($) +{ + my ($date) = @_; + return strftime("%b %d", gmtime($date)); +} + +sub long_date($) +{ + my ($date) = @_; + return strftime("%b %d %H:%M:%S", gmtime($date)); +} + + my %w95 = (name => "Win95"); my %w98 = (name => "Win98"); my %me = (name => "Me"); @@ -81,23 +115,16 @@ foreach my $build (readdir(DIR)) next unless $build =~ /^[-.0-9a-zA-Z]+$/; next unless -f "./data/$build/index.html"; - my ($commit, $date, $subject); - $commit = `git log --max-count=1 --pretty="format:%ct %s" "$build^0" 2>/dev/null` if ($build =~ /^[0-9a-f]{40}$/); - if ($commit && $commit =~ /^(\d+) (.*)$/) + my ($date, $subject) = get_build_info($build); + if (time() - $date > 60 * 24 * 60 * 60) { - $date = $1; - $subject = $2; - # make sure the file mtime matches the commit time - utime $date, $date, "data/$build"; + # Archive builds older than 60 days + push @too_old, $build; } else { - $date = (stat "./data/$build")[9]; - $subject = ""; + push @builds, { name => $build, date => $date, subj => $subject }; } - # archive builds older than 2 months - if (time() - $date > 60 * 24 * 60 * 60) { push @too_old, $build; } - else { push @builds, { name => $build, date => $date, subj => $subject }; } } closedir(DIR); @@ -204,7 +231,7 @@ EOF next unless defined $alltests{$test}->{$build->{name}}; printf OUT " %s\n", $build->{name}, $build->{name}, substr($build->{name},0,12); - printf OUT " %s", strftime("%b %d", gmtime($build->{date})); + printf OUT " %s", short_date($build->{date}); foreach my $group (@groups) { next unless defined $used_group{$group->{name}}; @@ -252,7 +279,7 @@ print OUT "Failures\n"; foreach my $build (@builds) { printf OUT " %s\n", $build->{name}, $build->{name}, substr($build->{name},0,12); - printf OUT " %s", strftime("%b %d", gmtime($build->{date})); + printf OUT " %s", short_date($build->{date}); my ($total_runs, $total_tests, $total_errors, $total_todos); foreach my $ver (@groups) { @@ -336,7 +363,7 @@ print OUT "\n", strftime("%b %d %H:%M:%S", gmtime($err->{date})); + printf OUT "\n", long_date($err->{date}); printf OUT "\n", $err->{url}, escapeHTML($err->{msg}); } print OUT "
Date{date} <=> $a->{date}; } @errors) { - printf OUT "
%s
%s%s
", end_html(); -- 2.11.0