[Tools 1/2] winetest/build-index: Factorize the Git commit info and date formatting code.

Francois Gouget fgouget at codeweavers.com
Mon Mar 20 18:08:19 CDT 2017


This clarifies the code, removes a bit of duplication and makes it
easier to reuse that code elsewhere.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---

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 "  <tr><td class=\"build\"><a href=\"../%s\" title=\"%s\">%s</a></td>\n",
                    $build->{name}, $build->{name}, substr($build->{name},0,12);
-        printf OUT "  <td class=\"date\">%s</td>", strftime("%b %d", gmtime($build->{date}));
+        printf OUT "  <td class=\"date\">%s</td>", short_date($build->{date});
         foreach my $group (@groups)
         {
             next unless defined $used_group{$group->{name}};
@@ -252,7 +279,7 @@ print OUT "<th colspan=\"3\">Failures</th><th></th></tr></thead>\n";
 foreach my $build (@builds)
 {
     printf OUT "  <tr><td class=\"build\"><a href=\"%s\" title=\"%s\">%s</a></td>\n", $build->{name}, $build->{name}, substr($build->{name},0,12);
-    printf OUT "  <td class=\"date\">%s</td>", strftime("%b %d", gmtime($build->{date}));
+    printf OUT "  <td class=\"date\">%s</td>", short_date($build->{date});
     my ($total_runs, $total_tests, $total_errors, $total_todos);
     foreach my $ver (@groups)
     {
@@ -336,7 +363,7 @@ print OUT "<table class=\"report\"><thead><tr><th class=\"date\">Date</th><th cl
 
 foreach my $err (sort { $b->{date} <=> $a->{date}; } @errors)
 {
-    printf OUT "<tr><td class=\"date\">%s</td>\n", strftime("%b %d %H:%M:%S", gmtime($err->{date}));
+    printf OUT "<tr><td class=\"date\">%s</td>\n", long_date($err->{date});
     printf OUT "<td class=\"commitlink\"><a href=\"%s\">%s</a></td></tr>\n", $err->{url}, escapeHTML($err->{msg});
 }
 print OUT "</table>", end_html();
-- 
2.11.0




More information about the wine-patches mailing list