xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Jackson <ian.jackson@eu.citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>
Subject: [OSSTEST PATCH 2/4] cs-adjust-flight: Lift notspec_exfn out of for_things
Date: Fri, 2 Dec 2016 11:55:38 +0000	[thread overview]
Message-ID: <1480679740-32372-2-git-send-email-ian.jackson@eu.citrix.com> (raw)
In-Reply-To: <1480679740-32372-1-git-send-email-ian.jackson@eu.citrix.com>

We are going to want to reuse this, so abstract it away.
As a side effect we now support negated exact matches.

No other functional change, except to debug output.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
---
 cs-adjust-flight | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/cs-adjust-flight b/cs-adjust-flight
index 02fd2cf..33ff9df 100755
--- a/cs-adjust-flight
+++ b/cs-adjust-flight
@@ -90,6 +90,28 @@ sub spec_re ($) {
     return undef;
 }
 
+sub notspec_exfn ($$) {
+    my ($what, $spec) = @_;
+    # returns ($fn, $exact)
+    # where $exact is undef, or a thing that can be tested with eq
+    #   and $fn->($candidate) will be boolish
+    my $not = ($spec =~ s/^\!//) ? 'NOT' : '';
+    my $re = spec_re($spec);
+    debug("$what $not \`$spec' RE ",
+          (defined($re) ? "/$re/" : "<undef>"), "\n");
+    if (defined $re) {
+	debug("$what  REMATCHER\n");
+	return (sub { $_[0] =~ qr{$re} xor $not },
+		undef);
+    } elsif ($not) {
+	return (sub { $_[0] ne $spec },
+		undef);
+    } else {
+	return (sub { $_[0] eq $spec },
+		$spec);
+    }
+}
+
 sub debug { print STDERR @_ if $debug; }
 
 sub verbose (@) { $verbose_buffer .= $_ foreach @_; }
@@ -109,20 +131,16 @@ sub for_things ($$$$$$$) {
     my $things_q = $things_q{$table} ||= $dbh_tests->prepare
         ("SELECT * FROM $table WHERE $basecond");
 
-    my $not = ($spec =~ s/^\!//) ? 'NOT' : '';
-    my $re = spec_re($spec);
-    debug("FOR_THINGS $table.$keycol $not \`$spec' RE ",
-          (defined($re) ? "/$re/" : "<undef>"), "\n");
-    if (!defined $re) {
-	die "cannot negate <foo-name>" if $not;
-        $thing_q->execute(@$basecondvals, $spec);
+    my ($specfn,$exact) = notspec_exfn("FOR_THINGS $table.$keycol",$spec);
+    if (defined $exact) {
+        $thing_q->execute(@$basecondvals, $exact);
         my $row = $thing_q->fetchrow_hashref();
         if ($row) {
             debug("FOR_THINGS $table.$keycol \`$spec' EXACT\n");
-            $fn->($spec,$row);
+            $fn->($exact,$row);
         } elsif ($ifnone) {
             debug("FOR_THINGS $table.$keycol \`$spec' MISSING REPORT\n");
-            $ifnone->($spec);
+            $ifnone->($exact);
         } else {
             debug("FOR_THINGS $table.$keycol \`$spec' MISSING IGNORED\n");
         }
@@ -130,8 +148,8 @@ sub for_things ($$$$$$$) {
         $things_q->execute(@$basecondvals);
         while (my $row = $things_q->fetchrow_hashref()) {
             my $thing = $row->{$keycol};
-            next unless $thing =~ m/$re/ xor $not;
-            debug("FOR_THINGS $table.$keycol $not \`$spec' FOUND $row->{$keycol}\n");
+            next unless $specfn->($thing);
+            debug("FOR_THINGS $table.$keycol \`$spec' FOUND $row->{$keycol}\n");
             $fn->($thing, $row);
         }
     }
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2016-12-02 11:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-02 11:55 [OSSTEST PATCH 1/4] cs-ajust-flight: Use qr{} syntax Ian Jackson
2016-12-02 11:55 ` Ian Jackson [this message]
2016-12-02 11:55 ` [OSSTEST PATCH 3/4] cs-ajust-flight: Provide runvar-build-set Ian Jackson
2016-12-02 11:55 ` [OSSTEST PATCH 4/4] ts-xtf-*: Provide for host specs on command line Ian Jackson
2016-12-02 11:57   ` Wei Liu
2017-02-05 16:42   ` Wei Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1480679740-32372-2-git-send-email-ian.jackson@eu.citrix.com \
    --to=ian.jackson@eu.citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).