]> xenbits.xensource.com Git - people/aperard/osstest.git/commitdiff
sg-check-tested: Lift work into new `search' sub, and indirect output
authorIan Jackson <ian.jackson@eu.citrix.com>
Fri, 9 Dec 2016 19:08:14 +0000 (19:08 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Mon, 12 Dec 2016 11:35:01 +0000 (11:35 +0000)
* Replace open-coded prints to stdout with calls to new `ouput' sub
* Move main body into new `search' sub
* Exit from `search' with `return' rather than `exit 0'

Overall, no functional change.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
sg-check-tested

index 43f2854a6f049753b82cbeaf26f7aa373e68e587..8f2a2640890a7eae56abd47a68e9328e3b3bdb99 100755 (executable)
@@ -149,57 +149,65 @@ sub prepare_execute ($@) {
     return $q;
 }
 
-my $q = prepare_execute($qtxt, @conds_vars);
-
 sub massage ($) { local ($_) = @_; s/^\d+\://; $_; }
 
-FLIGHT:
-while (my $row= $q->fetchrow_hashref()) {
-    my $flight= $row->{flight};
-    if (!defined $prrev) {
-       print DEBUG "==========YES\n";
-        print $flight,"\n" or die $!;
-        exit 0;
-    } else {
-       my $valsq;
-       if ($prrev eq 'osstest') {
-           $valsq= prepare_execute(<<END, $flight);
-                SELECT DISTINCT harness AS val
-                  FROM flights_harness_touched
-                 WHERE flight=?
-END
+sub output {
+    print @_ or die $!;
+}
+
+sub search () {
+    my $q = prepare_execute($qtxt, @conds_vars);
+
+    FLIGHT:
+    while (my $row= $q->fetchrow_hashref()) {
+       my $flight= $row->{flight};
+       if (!defined $prrev) {
+           print DEBUG "==========YES\n";
+           output $flight,"\n";
+           return;
        } else {
-            $valsq= prepare_execute(<<END,
-               SELECT DISTINCT val
-                 FROM runvars
-                WHERE flight=?
-                 AND   ${\ main_revision_job_cond('job') }
-                AND   (name=? OR name=?)
+           my $valsq;
+           if ($prrev eq 'osstest') {
+               $valsq= prepare_execute(<<END, $flight);
+                   SELECT DISTINCT harness AS val
+                     FROM flights_harness_touched
+                    WHERE flight=?
 END
-                                   $flight,
-                                   "revision_$prrev",
-                                   "built_revision_$prrev");
-       }
-        my $row1= $valsq->fetchrow_hashref();
-        next unless defined $row1->{val} && length $row1->{val};
-       my $val1 = massage($row1->{val});
-        print DEBUG "got $val1\n";
-       while (my $row2 = $valsq->fetchrow_hashref()) {
-           my $val2 = massage($row2->{val});
-           next if $val2 eq $val1;
-           print DEBUG "also $val2\n";
-           next FLIGHT;
-       }
-       if (defined $ancestorof) {
-           if (!$ancestors{$val1}) {
-               print DEBUG "not an ancestor of $ancestorof\n";
+           } else {
+               $valsq= prepare_execute(<<END,
+                   SELECT DISTINCT val
+                     FROM runvars
+                    WHERE flight=?
+                    AND   ${\ main_revision_job_cond('job') }
+                    AND   (name=? OR name=?)
+END
+                                      $flight,
+                                      "revision_$prrev",
+                                      "built_revision_$prrev");
+           }
+           my $row1= $valsq->fetchrow_hashref();
+           next unless defined $row1->{val} && length $row1->{val};
+           my $val1 = massage($row1->{val});
+           print DEBUG "got $val1\n";
+           while (my $row2 = $valsq->fetchrow_hashref()) {
+               my $val2 = massage($row2->{val});
+               next if $val2 eq $val1;
+               print DEBUG "also $val2\n";
                next FLIGHT;
            }
+           if (defined $ancestorof) {
+               if (!$ancestors{$val1}) {
+                   print DEBUG "not an ancestor of $ancestorof\n";
+                   next FLIGHT;
+               }
+           }
+           output "$val1\n";
+           exit 0;
        }
-        print "$val1\n";
-        exit 0;
     }
+    print DEBUG "==========NO\n";
 }
 
-print DEBUG "==========NO\n";
+search();
+
 exit 0;