]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Check for PatchReader as a part of the installation and disable the "Diff"
authorjkeiser%netscape.com <>
Wed, 20 Aug 2003 07:45:39 +0000 (07:45 +0000)
committerjkeiser%netscape.com <>
Wed, 20 Aug 2003 07:45:39 +0000 (07:45 +0000)
links if it is not there (bug 215268)

attachment.cgi
checksetup.pl
show_bug.cgi
template/en/default/attachment/edit.html.tmpl
template/en/default/attachment/list.html.tmpl

index 149ddfd2143cdf3fc870e4febb7ee1eae669c01c..07dbe5e51f052808831866860c14606b66bd572d 100755 (executable)
@@ -467,11 +467,11 @@ sub interdiff
   $ENV{'PATH'} = $::diffpath;
   open my $interdiff_fh, "$::interdiffbin $old_filename $new_filename|";
   binmode $interdiff_fh;
-  my ($iter, $last_iter) = setup_iterators("");
+  my ($reader, $last_reader) = setup_patch_readers("");
   if ($::FORM{'format'} eq "raw")
   {
-    require PatchIterator::DiffPrinter::raw;
-    $last_iter->sends_data_to(new PatchIterator::DiffPrinter::raw());
+    require PatchReader::DiffPrinter::raw;
+    $last_reader->sends_data_to(new PatchReader::DiffPrinter::raw());
     # Actually print out the patch
     print $cgi->header(-type => 'text/plain',
                        -expires => '+3M');
@@ -487,9 +487,9 @@ sub interdiff
     delete $vars->{attachid};
     delete $vars->{do_context};
     delete $vars->{context};
-    setup_template_iterator($iter, $last_iter);
+    setup_template_patch_reader($last_reader);
   }
-  $iter->iterate_fh($interdiff_fh, "interdiff #$::FORM{'oldid'} #$::FORM{'newid'}");
+  $reader->iterate_fh($interdiff_fh, "interdiff #$::FORM{'oldid'} #$::FORM{'newid'}");
   close $interdiff_fh;
   $ENV{'PATH'} = '';
 
@@ -505,10 +505,10 @@ sub get_unified_diff
   my ($id) = @_;
 
   # Bring in the modules we need
-  require PatchIterator::Raw;
-  require PatchIterator::FixPatchRoot;
-  require PatchIterator::DiffPrinter::raw;
-  require PatchIterator::PatchInfoGrabber;
+  require PatchReader::Raw;
+  require PatchReader::FixPatchRoot;
+  require PatchReader::DiffPrinter::raw;
+  require PatchReader::PatchInfoGrabber;
   require File::Temp;
 
   # Get the patch
@@ -520,18 +520,29 @@ sub get_unified_diff
   }
 
   # Reads in the patch, converting to unified diff in a temp file
-  my $iter = new PatchIterator::Raw;
+  my $reader = new PatchReader::Raw;
+  my $last_reader = $reader;
+
   # fixes patch root (makes canonical if possible)
-  my $fix_patch_root = new PatchIterator::FixPatchRoot(Param('cvsroot'));
-  $iter->sends_data_to($fix_patch_root);
+  if (Param('cvsroot')) {
+    my $fix_patch_root = new PatchReader::FixPatchRoot(Param('cvsroot'));
+    $last_reader->sends_data_to($fix_patch_root);
+    $last_reader = $fix_patch_root;
+  }
+
   # Grabs the patch file info
-  my $patch_info_grabber = new PatchIterator::PatchInfoGrabber();
-  $fix_patch_root->sends_data_to($patch_info_grabber);
+  my $patch_info_grabber = new PatchReader::PatchInfoGrabber();
+  $last_reader->sends_data_to($patch_info_grabber);
+  $last_reader = $patch_info_grabber;
+
   # Prints out to temporary file
   my ($fh, $filename) = File::Temp::tempfile();
-  $patch_info_grabber->sends_data_to(new PatchIterator::DiffPrinter::raw($fh));
+  my $raw_printer = new PatchReader::DiffPrinter::raw($fh);
+  $last_reader->sends_data_to($raw_printer);
+  $last_reader = $raw_printer;
+
   # Iterate!
-  $iter->iterate_string($id, $thedata);
+  $reader->iterate_string($id, $thedata);
 
   return ($bugid, $description, $filename, $patch_info_grabber->patch_info()->{files});
 }
@@ -557,7 +568,7 @@ sub warn_if_interdiff_might_fail {
   return undef;
 }
 
-sub setup_iterators {
+sub setup_patch_readers {
   my ($diff_root) = @_;
 
   #
@@ -568,36 +579,36 @@ sub setup_iterators {
   # headers=0|1
   #
 
-  # Define the iterators
-  # The iterator that reads the patch in (whatever its format)
-  require PatchIterator::Raw;
-  my $iter = new PatchIterator::Raw;
-  my $last_iter = $iter;
+  # Define the patch readers
+  # The reader that reads the patch in (whatever its format)
+  require PatchReader::Raw;
+  my $reader = new PatchReader::Raw;
+  my $last_reader = $reader;
   # Fix the patch root if we have a cvs root
   if (Param('cvsroot'))
   {
-    require PatchIterator::FixPatchRoot;
-    $last_iter->sends_data_to(new PatchIterator::FixPatchRoot(Param('cvsroot')));
-    $last_iter->sends_data_to->diff_root($diff_root) if defined($diff_root);
-    $last_iter = $last_iter->sends_data_to;
+    require PatchReader::FixPatchRoot;
+    $last_reader->sends_data_to(new PatchReader::FixPatchRoot(Param('cvsroot')));
+    $last_reader->sends_data_to->diff_root($diff_root) if defined($diff_root);
+    $last_reader = $last_reader->sends_data_to;
   }
   # Add in cvs context if we have the necessary info to do it
   if ($::FORM{'context'} ne "patch" && $::cvsbin && Param('cvsroot_get'))
   {
-    require PatchIterator::AddCVSContext;
-    $last_iter->sends_data_to(
-        new PatchIterator::AddCVSContext($::FORM{'context'},
+    require PatchReader::AddCVSContext;
+    $last_reader->sends_data_to(
+        new PatchReader::AddCVSContext($::FORM{'context'},
                                          Param('cvsroot_get')));
-    $last_iter = $last_iter->sends_data_to;
+    $last_reader = $last_reader->sends_data_to;
   }
-  return ($iter, $last_iter);
+  return ($reader, $last_reader);
 }
 
-sub setup_template_iterator
+sub setup_template_patch_reader
 {
-  my ($iter, $last_iter) = @_;
+  my ($last_reader) = @_;
 
-  require PatchIterator::DiffPrinter::template;
+  require PatchReader::DiffPrinter::template;
 
   my $format = $::FORM{'format'};
 
@@ -614,7 +625,7 @@ sub setup_template_iterator
   # Print everything out
   print $cgi->header(-type => 'text/html',
                      -expires => '+3M');
-  $last_iter->sends_data_to(new PatchIterator::DiffPrinter::template($template,
+  $last_reader->sends_data_to(new PatchReader::DiffPrinter::template($template,
                              "attachment/diff-header.$format.tmpl",
                              "attachment/diff-file.$format.tmpl",
                              "attachment/diff-footer.$format.tmpl",
@@ -638,17 +649,17 @@ sub diff
     return;
   }
 
-  my ($iter, $last_iter) = setup_iterators();
+  my ($reader, $last_reader) = setup_patch_readers();
 
   if ($::FORM{'format'} eq "raw")
   {
-    require PatchIterator::DiffPrinter::raw;
-    $last_iter->sends_data_to(new PatchIterator::DiffPrinter::raw());
+    require PatchReader::DiffPrinter::raw;
+    $last_reader->sends_data_to(new PatchReader::DiffPrinter::raw());
     # Actually print out the patch
     use vars qw($cgi);
     print $cgi->header(-type => 'text/plain',
                        -expires => '+3M');
-    $iter->iterate_string("Attachment " . $::FORM{'id'}, $thedata);
+    $reader->iterate_string("Attachment " . $::FORM{'id'}, $thedata);
   }
   else
   {
@@ -674,9 +685,9 @@ sub diff
     $vars->{bugid} = $bugid;
     $vars->{attachid} = $::FORM{'id'};
     $vars->{description} = $description;
-    setup_template_iterator($iter, $last_iter);
+    setup_template_patch_reader($last_reader);
     # Actually print out the patch
-    $iter->iterate_string("Attachment " . $::FORM{'id'}, $thedata);
+    $reader->iterate_string("Attachment " . $::FORM{'id'}, $thedata);
   }
 }
 
@@ -937,6 +948,11 @@ sub edit
   $vars->{'attachments'} = \@bugattachments; 
   $vars->{'GetBugLink'} = \&GetBugLink;
 
+  # Determine if PatchReader is installed
+  eval {
+    require PatchReader;
+    $vars->{'patchviewerinstalled'} = 1;
+  };
   print Bugzilla->cgi->header();
 
   # Generate and return the UI (HTML page) from the appropriate template.
index 00605415dbeb7db972c23e7e2cea36195d23ba6b..cde336d7492449c5b133627a3c651ca66a7e51a2 100755 (executable)
@@ -268,6 +268,7 @@ my $chartbase   = have_vers("Chart::Base","0.99");
 my $xmlparser   = have_vers("XML::Parser",0);
 my $gdgraph     = have_vers("GD::Graph",0);
 my $gdtextalign = have_vers("GD::Text::Align",0);
+my $patchreader = have_vers("PatchReader",0);
 
 print "\n" unless $silent;
 if ((!$gd || !$chartbase) && !$silent) {
@@ -295,6 +296,17 @@ if ((!$gd || !$gdgraph || !$gdtextalign) && !$silent) {
            "-e'install \"GD::Text::Align\"'\n" if !$gdtextalign;
     print "\n";
 }
+if (!$patchreader && !$silent) {
+    print "If you want to see pretty HTML views of patches, you should ";
+    print "install the \nPatchReader module, which can be downloaded at:\n";
+    print "http://search.cpan.org/CPAN/authors/id/J/JK/JKEISER/PatchReader-0.9.2.tar.gz\n";
+    print "When you get it, do the following to install:\n";
+    print "tar xzvf PatchReader-0.9.2.tar.gz\n";
+    print "cd PatchReader-0.9.2\n";
+    print "perl Makefile.PL\n";
+    print "make install\n\n";
+}
+
 if (%missing) {
     print "\n\n";
     print "Bugzilla requires some Perl modules which are either missing from your\n",
@@ -461,6 +473,14 @@ END
 if (!LocalVarExists('interdiffbin')) {
     my $interdiff_executable = `which interdiff`;
     if ($interdiff_executable =~ /no interdiff/ || $interdiff_executable eq '') {
+        if (!$silent) {
+            print "\nOPTIONAL NOTE: If you want to ";
+            print "be able to use the\n 'difference between two patches";
+            print "feature of Bugzilla (requires\n the PatchReader Perl module";
+            print "as well), you should install\n patchutils from ";
+            print "http://cyberelk.net/tim/patchutils/\n\n";
+        }
+
         # If which didn't find it, set to blank
         $interdiff_executable = "";
     } else {
index 711b7201bcb07778ae9fe57a4b0151b7c490d831..c7a780404895e57a6df2884746e509ed5b637c77 100755 (executable)
@@ -73,6 +73,12 @@ if ($single) {
     }
 }
 
+# Determine if Patch Viewer is installed, for Diff link
+eval {
+  require PatchReader;
+  $vars->{'patchviewerinstalled'} = 1;
+};
+
 $vars->{'bugs'} = \@bugs;
 
 # Next bug in list (if there is one)
index 2cfc0e08841726ae0b14fa9ea962f79e4732ef8f..3de65766a7755a43965d3b8906079c6033826a37 100644 (file)
@@ -90,6 +90,7 @@
     {
       switchToMode('edit');
     }
+[% IF patchviewerinstalled %]
   function viewDiff()
     {
       switchToMode('diff');
         has_viewed_as_diff = 1;
       }
     }
+[% END %]
   function viewRaw()
     {
       switchToMode('raw');
         hideElementById('undoEditButton');
       } else if (current_mode == 'raw') {
         hideElementById('viewFrame');
+[% IF patchviewerinstalled %]
         hideElementById('viewDiffButton');
+[% END %]
         hideElementById(has_edited ? 'redoEditButton' : 'editButton');
         hideElementById('smallCommentFrame');
       } else if (current_mode == 'diff') {
+[% IF patchviewerinstalled %]
         hideElementById('viewDiffFrame');
+[% END %]
         hideElementById('viewRawButton');
         hideElementById(has_edited ? 'redoEditButton' : 'editButton');
         hideElementById('smallCommentFrame');
         showElementById('undoEditButton');
       } else if (mode == 'raw') {
         showElementById('viewFrame');
+[% IF patchviewerinstalled %]
         showElementById('viewDiffButton');
+[% END %]
         showElementById(has_edited ? 'redoEditButton' : 'editButton');
         showElementById('smallCommentFrame');
       } else if (mode == 'diff') {
+[% IF patchviewerinstalled %]
         showElementById('viewDiffFrame');
+[% END %]
         showElementById('viewRawButton');
         showElementById(has_edited ? 'redoEditButton' : 'editButton');
         showElementById('smallCommentFrame');
 
         <input type="submit" value="Submit"><br><br>
         <strong>Actions:</strong> <a href="attachment.cgi?id=[% attachid %]">View</a>
-        [% IF ispatch %]
+        [% IF ispatch && patchviewerinstalled %]
          | <a href="attachment.cgi?id=[% attachid %]&action=diff">Diff</a>
         [% END %]
         </small>
           <script type="application/x-javascript" language="JavaScript">
             <!--
             if (typeof document.getElementById == "function") {
+[% IF patchviewerinstalled %]
               document.write('<iframe id="viewDiffFrame" style="height: 400px; width: 100%; display: none;"></iframe>');
+[% END %]
               document.write('<button type="button" id="editButton" onclick="editAsComment();">Edit Attachment As Comment</button>');
               document.write('<button type="button" id="undoEditButton" onclick="undoEditAsComment();" style="display: none;">Undo Edit As Comment</button>');
               document.write('<button type="button" id="redoEditButton" onclick="redoEditAsComment();" style="display: none;">Redo Edit As Comment</button>');
+[% IF patchviewerinstalled %]
               document.write('<button type="button" id="viewDiffButton" onclick="viewDiff();">View Attachment As Diff</button>');
+[% END %]
               document.write('<button type="button" id="viewRawButton" onclick="viewRaw();" style="display: none;">View Attachment As Raw</button>');
             }
             //-->
index 598f8172bd3091ea49e80e3caf59498b2c0d392a..163071997e376c5d2d3c0db661564a9f017ffe73 100644 (file)
@@ -70,7 +70,7 @@
         [% IF attachment.canedit %]
           <a href="attachment.cgi?id=[% attachment.attachid %]&amp;action=edit">Edit</a>
         [% END %]
-        [% IF attachment.ispatch %]
+        [% IF attachment.ispatch && patchviewerinstalled %]
           [% IF attachment.canedit %]
             |
           [% END %]