]> git.donarmstrong.com Git - debbugs.git/commitdiff
* Add control owner function
authorDon Armstrong <don@donarmstrong.com>
Fri, 1 Aug 2008 04:23:05 +0000 (21:23 -0700)
committerDon Armstrong <don@donarmstrong.com>
Fri, 1 Aug 2008 04:23:05 +0000 (21:23 -0700)
 * Use new merged bug locking function
 * Add control stub example

Debbugs/Control.pm

index 493125102e242d267ab06d1b094e9acbe3f2036e..1ca18ac77120a8860edad1c70394a76fb64082f0 100644 (file)
@@ -64,7 +64,7 @@ the above information is faked, and appended to the log file. When it
 is true, the above options must be present, and their values are used.
 
 
-=head1 FUNCTIONS
+=head1 GENERAL FUNCTIONS
 
 =cut
 
@@ -93,6 +93,7 @@ use Debbugs::Common qw(:lock buglog :misc get_hashname);
 use Debbugs::Status qw(bug_archiveable :read :hook writebug);
 use Debbugs::CGI qw(html_escape);
 use Debbugs::Log qw(:misc);
+use Debbugs::Recipients qw(:add);
 
 use Params::Validate qw(validate_with :types);
 use File::Path qw(mkpath);
@@ -118,7 +119,10 @@ my %common_options = (debug       => {type => SCALARREF|HANDLE,
                                        optional => 1,
                                       },
                      recipients    => {type => HASHREF,
-                                       optional => 1,
+                                       default => {},
+                                      },
+                     limit         => {type => HASHREF,
+                                       default => {},
                                       },
                     );
 
@@ -148,6 +152,118 @@ my %append_action_options =
      );
 
 
+# this is just a generic stub for Debbugs::Control functions.
+# sub foo {
+#     my %param = validate_with(params => \@_,
+#                            spec   => {bug => {type   => SCALAR,
+#                                               regex  => qr/^\d+$/,
+#                                              },
+#                                       # specific options here
+#                                       %common_options,
+#                                       %append_action_options,
+#                                      },
+#                           );
+#     our $locks = 0;
+#     $locks = 0;
+#     local $SIG{__DIE__} = sub {
+#      if ($locks) {
+#          for (1..$locks) { unfilelock(); }
+#          $locks = 0;
+#      }
+#     };
+#     my ($debug,$transcript) = __handle_debug_transcript(%param);
+#     my (@data);
+#     ($locks, @data) = lock_read_all_merged_bugs($param{bug});
+#     add_recipients(data => \@data,
+#                   recipients => $param{recipients}
+#                  );
+# }
+
+=head1 OWNER FUNCTIONS
+
+=head2 owner
+
+     eval {
+           owner(bug          => $ref,
+                 transcript   => $transcript,
+                 ($dl > 0 ? (debug => $transcript):()),
+                 requester    => $header{from},
+                 request_addr => $controlrequestaddr,
+                 message      => \@log,
+                 recipients   => \%recipients,
+                 owner        => undef,
+                );
+       };
+       if ($@) {
+           $errors++;
+           print {$transcript} "Failed to mark $ref as not having an owner: $@";
+       }
+
+Handles all setting of the owner field; given an owner of undef or of
+no length, indicates that a bug is not owned by anyone.
+
+=cut
+
+sub owner {
+    my %param = validate_with(params => \@_,
+                             spec   => {bug => {type   => SCALAR,
+                                                regex  => qr/^\d+$/,
+                                               },
+                                        owner => {type => SCALAR|UNDEF,
+                                                 },
+                                        %common_options,
+                                        %append_action_options,
+                                       },
+                            );
+    our $locks = 0;
+    $locks = 0;
+    local $SIG{__DIE__} = sub {
+       if ($locks) {
+           for (1..$locks) { unfilelock(); }
+           $locks = 0;
+       }
+    };
+    my ($debug,$transcript) = __handle_debug_transcript(%param);
+    my (@data);
+    ($locks, @data) = lock_read_all_merged_bugs($param{bug});
+    @data and defined $data[0] or die "No bug found for $param{bug}";
+    add_recipients(data => \@data,
+                  recipients => $param{recipients}
+                 );
+    my $action = '';
+    for my $data (@data) {
+       if (not defined $param{owner} or not length $param{owner}) {
+           $param{owner} = '';
+           $action = "Removed annotation that $gBug was owned by " .
+               "$data->{owner}.";
+       }
+       else {
+           if (length $data->{owner}) {
+               $action = "Owner changed from $data->{owner} to $param{owner}.";
+           }
+           else {
+               $action = "Owner recorded as $param{owner}."
+           }
+       }
+       $data->{owner} = $param{owner};
+       append_action_to_log(bug => $data->{bug_num},
+                            get_lock => 0,
+                            __return_append_to_log_options(
+                                %param,
+                                action => $action,
+                               ),
+                           )
+           if not exists $param{append_log} or $param{append_log};
+    }
+    if ($locks) {
+       for (1..$locks) { unfilelock(); }
+    }
+}
+
+
+=head1 ARCHIVE FUNCTIONS
+
+
 =head2 bug_archive
 
      my $error = '';
@@ -204,6 +320,7 @@ sub bug_archive {
                                         },
                              );
      our $locks = 0;
+     $locks = 0;
      local $SIG{__DIE__} = sub {
          if ($locks) {
               for (1..$locks) { unfilelock(); }
@@ -220,49 +337,30 @@ sub bug_archive {
          die "Bug $param{bug} cannot be archived";
      }
      print {$debug} "$param{bug} considering\n";
-     my ($data);
-     ($locks, $data) = lockreadbugmerge($param{bug});
+     my (@data);
+     ($locks, @data) = lock_read_all_merged_bugs($param{bug});
      print {$debug} "$param{bug} read $locks\n";
-     defined $data or die "No bug found for $param{bug}";
-     print {$debug} "$param{bug} read ok (done $data->{done})\n";
+     @data and defined $data[0] or die "No bug found for $param{bug}";
      print {$debug} "$param{bug} read done\n";
 
      if (not $param{archive_unarchived} and
-        not exists $data->{unarchived}
+        not exists $data[0]{unarchived}
        ) {
          print {$transcript} "$param{bug} has not been archived previously\n";
          die "$param{bug} has not been archived previously";
      }
-
-     my @bugs = ($param{bug});
-     # my %bugs;
-     # @bugs{@bugs} = (1) x @bugs;
-     if (length($data->{mergedwith})) {
-         push(@bugs,split / /,$data->{mergedwith});
-     }
+     add_recipients(recipients => $param{recipients},
+                   data => \@data,
+                  );
+     my @bugs = map {$_->{bug_num}} @data;
      print {$debug} "$param{bug} bugs ".join(' ',@bugs)."\n";
      for my $bug (@bugs) {
-         my $newdata;
-         print {$debug} "$param{bug} $bug check\n";
-         if ($bug != $param{bug}) {
-              print {$debug} "$param{bug} $bug reading\n";
-              $newdata = lockreadbug($bug) || die "huh $bug ?";
-              print {$debug} "$param{bug} $bug read ok\n";
-              $locks++;
-         } else {
-              $newdata = $data;
-         }
-         print {$debug} "$param{bug} $bug read/not\n";
-         my $expectmerge= join(' ',grep($_ != $bug, sort { $a <=> $b } @bugs));
-         $newdata->{mergedwith} eq $expectmerge ||
-              die "$param{bug} differs from $bug: ($newdata->{mergedwith}) vs. ($expectmerge) (".join(' ',@bugs).")";
-         print {$debug} "$param{bug} $bug merge-ok\n";
-         if ($param{check_archiveable}) {
-              die "Bug $bug cannot be archived (but $param{bug} can?)"
-                   unless bug_archiveable(bug=>$bug,
-                                          ignore_time => $param{ignore_time},
-                                         );
-         }
+        if ($param{check_archiveable}) {
+            die "Bug $bug cannot be archived (but $param{bug} can?)"
+                unless bug_archiveable(bug=>$bug,
+                                       ignore_time => $param{ignore_time},
+                                      );
+        }
      }
      # If we get here, we can archive/remove this bug
      print {$debug} "$param{bug} removing\n";
@@ -330,45 +428,27 @@ sub bug_unarchive {
                                          %append_action_options,
                                         },
                              );
+     our $locks = 0;
+     local $SIG{__DIE__} = sub {
+         if ($locks) {
+              for (1..$locks) { unfilelock(); }
+              $locks = 0;
+         }
+     };
      my $action = "$config{bug} unarchived.";
      my ($debug,$transcript) = __handle_debug_transcript(%param);
      print {$debug} "$param{bug} considering\n";
-     my ($locks, $data) = lockreadbugmerge($param{bug},'archive');
+     my @data = ();
+     ($locks, @data) = lock_read_all_merged_bugs($param{bug},'archive');
      print {$debug} "$param{bug} read $locks\n";
-     if (not defined $data) {
-         print {$transcript} "No bug found for $param{bug}\n";
-         die "No bug found for $param{bug}";
+     if (not @data or not defined $data[0]) {
+        print {$transcript} "No bug found for $param{bug}\n";
+        die "No bug found for $param{bug}";
      }
-     print {$debug} "$param{bug} read ok (done $data->{done})\n";
      print {$debug} "$param{bug} read done\n";
-     my @bugs = ($param{bug});
-     # my %bugs;
-     # @bugs{@bugs} = (1) x @bugs;
-     if (length($data->{mergedwith})) {
-         push(@bugs,split / /,$data->{mergedwith});
-     }
+     my @bugs = map {$_->{bug_num}} @data;
      print {$debug} "$param{bug} bugs ".join(' ',@bugs)."\n";
-     for my $bug (@bugs) {
-         my $newdata;
-         print {$debug} "$param{bug} $bug check\n";
-         if ($bug != $param{bug}) {
-              print {$debug} "$param{bug} $bug reading\n";
-              $newdata = lockreadbug($bug,'archive') or die "huh $bug ?";
-              print {$debug} "$param{bug} $bug read ok\n";
-              $locks++;
-         } else {
-              $newdata = $data;
-         }
-         print {$debug} "$param{bug} $bug read/not\n";
-         my $expectmerge= join(' ',grep($_ != $bug, sort { $a <=> $b } @bugs));
-         if ($newdata->{mergedwith} ne $expectmerge ) {
-              print {$transcript} "$param{bug} differs from $bug: ($newdata->{mergedwith}) vs. ($expectmerge) (@bugs)";
-              die "$param{bug} differs from $bug: ($newdata->{mergedwith}) vs. ($expectmerge) (@bugs)";
-         }
-         print {$debug} "$param{bug} $bug merge-ok\n";
-     }
-     # If we get here, we can archive/remove this bug
-     print {$debug} "$param{bug} removing\n";
+     print {$debug} "$param{bug} unarchiving\n";
      my @files_to_remove;
      for my $bug (@bugs) {
          print {$debug} "$param{bug} removing $bug\n";
@@ -402,6 +482,9 @@ sub bug_unarchive {
                              )
               if not exists $param{append_log} or $param{append_log};
          writebug($bug,$newdata);
+         add_recipients(recipients => $param{recipients},
+                        data       => $newdata,
+                       );
      }
      print {$debug} "$param{bug} unlocking $locks\n";
      if ($locks) {