]> git.donarmstrong.com Git - debbugs.git/commitdiff
[project @ 2003-08-06 18:45:41 by cjwatson]
authorcjwatson <>
Thu, 7 Aug 2003 01:45:41 +0000 (17:45 -0800)
committercjwatson <>
Thu, 7 Aug 2003 01:45:41 +0000 (17:45 -0800)
Avoid triplication of the format of .status files by creating a separate
makestatus() function which writebug() and bughook() use. bughook() now
takes a status hash rather than the formatted contents so that it can
extract fields more easily.

scripts/errorlib.in
scripts/service.in

index 3eba877ddf41296488c9684c1d203eadcca4e482..a13bb9f67799c30a154842ef7a52c8777f4f7c27 100755 (executable)
@@ -1,5 +1,5 @@
 # -*- perl -*-
-# $Id: errorlib.in,v 1.32 2003/06/23 11:23:35 cjwatson Exp $
+# $Id: errorlib.in,v 1.33 2003/08/06 18:45:41 cjwatson Exp $
 
 use Mail::Address;
 
@@ -101,13 +101,9 @@ sub lockreadbug {
     return $data;
 }
 
-sub writebug {
-    local ($ref, $data, $location) = @_;
-    my $change;
-    my $status = getbugcomponent($ref, 'status', $location);
-    &quit("can't find location for $ref") unless defined $status;
-    open(S,"> $status.new") || &quit("opening $status.new: $!");
-    print(S
+sub makestatus {
+    my $data = shift;
+    my $contents = 
           "$data->{originator}\n".
           "$data->{date}\n".
           "$data->{subject}\n".
@@ -119,28 +115,25 @@ sub writebug {
           "$data->{mergedwith}\n".
           "$data->{severity}\n".
           "$data->{versions}\n".
-          "$data->{fixed_versions}\n") || &quit("writing $status.new: $!");
+          "$data->{fixed_versions}\n";
+    return $contents;
+}
+
+sub writebug {
+    local ($ref, $data, $location) = @_;
+    my $change;
+    my $status = getbugcomponent($ref, 'status', $location);
+    &quit("can't find location for $ref") unless defined $status;
+    open(S,"> $status.new") || &quit("opening $status.new: $!");
+    print(S makestatus($data)) || &quit("writing $status.new: $!");
     close(S) || &quit("closing $status.new: $!");
     if (-e $status) {
         $change = 'change';
     } else {
         $change = 'new';
     }
-    rename("$status.new",$status) ||
-        &quit("installing new $status: $!");
-        &bughook($change,$ref,
-          "$data->{originator}\n".
-          "$data->{date}\n".
-          "$data->{subject}\n".
-          "$data->{msgid}\n".
-          "$data->{package}\n".
-          "$data->{keywords}\n".
-          "$data->{done}\n".
-          "$data->{forwarded}\n".
-          "$data->{mergedwith}\n".
-          "$data->{severity}\n".
-          "$data->{versions}\n".
-          "$data->{fixed_versions}\n");
+    rename("$status.new",$status) || &quit("installing new $status: $!");
+    &bughook($change,$ref,$data);
 }
 
 sub unlockwritebug {
@@ -263,25 +256,23 @@ sub bughook_archive {
 }      
 
 sub bughook {
-       my ( $type, $ref ) = ( shift, shift );
+       my ( $type, $ref, $data ) = @_;
        &filelock("debbugs.trace.lock");
 
-       &appendfile("debbugs.trace","$type $ref\n",@_);
-
-       my @stuff=split /\n/, "$_[0]\n\n\n\n\n\n\n";
+       &appendfile("debbugs.trace","$type $ref\n",makestatus($data));
 
        my $whendone = "open";
        my $severity = $gDefaultSeverity;
-       (my $pkglist = $stuff[4]) =~ s/[,\s]+/,/g;
+       (my $pkglist = $data->{package}) =~ s/[,\s]+/,/g;
        $pkglist =~ s/^,+//;
        $pkglist =~ s/,+$//;
-       $whendone = "forwarded" if length $stuff[7];
-       $whendone = "done" if length $stuff[6];
-       $severity = $stuff[9] if length $stuff[9];
+       $whendone = "forwarded" if length $data->{forwarded};
+       $whendone = "done" if length $data->{done};
+       $severity = $data->{severity} if length $data->{severity};
 
        my $k = sprintf "%s %d %d %s [%s] %s %s\n",
-                       $pkglist, $ref, $stuff[1], $whendone, $stuff[0],
-                       $severity, $stuff[5];
+                       $pkglist, $ref, $data->{date}, $whendone,
+                       $data->{originator}, $severity, $data->{keywords};
 
        update_realtime("$gSpoolDir/index.db.realtime", $ref, $k);
 
index 9e2b5420f97cf76fe46abfd87941fb1a314abcea..e9f5807d3ce8d6dc2f0cfd93e51f931c781676e3 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/perl
-# $Id: service.in,v 1.83 2003/07/16 18:13:26 cjwatson Exp $
+# $Id: service.in,v 1.84 2003/08/06 18:45:41 cjwatson Exp $
 #
 # Usage: service <code>.nn
 # Temps:  incoming/P<code>.nn
@@ -601,7 +601,7 @@ END
                    copy("db-h/$ohash/$origref.log", "db-h/$hash/$ref.log");
                    copy("db-h/$ohash/$origref.status", "db-h/$hash/$ref.status");
                    copy("db-h/$ohash/$origref.report", "db-h/$hash/$ref.report");
-                   &bughook('new', $ref, "$data->{originator}\n$data->{date}\n$data->{subject}\n$data->{msgid}\n$data->{package}\n$data->{keywords}\n$data->{done}\n$data->{forwarded}\n$data->{mergedwith}\n$data->{severity}\n");
+                   &bughook('new', $ref, $data);
 
                    $ref++;
                }