http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88960

Revision: 88960
Author:   happydog
Date:     2011-05-27 08:45:57 +0000 (Fri, 27 May 2011)
Log Message:
-----------
[CodeReview] Follow-up to r83345.  I've updated svnImport.php to use 
CodeRepository::getDiffErrorMessage() when reporting the diff caching result, 
as it was basically duplicating the code from that function inline.

I've also tweaked getDiffErrorMessage() in the following ways:
* We now allow for the fact that the argument might actually be a valid diff, 
and in these cases we return an empty string (though I've added a TODO, for 
someone to check, as this may not be the best value to return).
* I've updated the function argument name to reflect the fact that it's not 
necessarily an error code any more.
* Added a case statement to handle DIFFRESULT_NothingToCompare, which was 
missing.
* Updated the strings to use the versions from svnImport, as these were a 
little more informative.
* Changed order of varname/type in documentation, as per wiki 
(http://www.mediawiki.org/wiki/Manual:Coding_conventions#Inline), due to 
Doxygen bug (https://bugzilla.gnome.org/show_bug.cgi?id=613185), and updated.

Modified Paths:
--------------
    trunk/extensions/CodeReview/backend/CodeRepository.php
    trunk/extensions/CodeReview/svnImport.php

Modified: trunk/extensions/CodeReview/backend/CodeRepository.php
===================================================================
--- trunk/extensions/CodeReview/backend/CodeRepository.php      2011-05-27 
06:25:21 UTC (rev 88959)
+++ trunk/extensions/CodeReview/backend/CodeRepository.php      2011-05-27 
08:45:57 UTC (rev 88960)
@@ -523,21 +523,31 @@
 
        /**
         * @static
-        * @param int $error
-        * @return string
+        * @param $diff int (error code) or string (diff text), as returned 
from getDiff()
+        * @return string (error message, or empty string if valid diff)
         */
-       public static function getDiffErrorMessage( $error ) {
-               switch( $error ) {
-                       case self::DIFFRESULT_BadRevision:
-                               return 'Bad revision specified.';
-                       case self::DIFFRESULT_TooManyPaths:
-                               return 'Too many paths returned to diff';
-                       case self::DIFFRESULT_NoDataReturned:
-                               return 'No data returned for diff';
-                       case self::DIFFRESULT_NotInCache:
-                               return 'Not in cache';
-                       default:
-                               return 'Unknown';
+       public static function getDiffErrorMessage( $diff ) {
+               global $wgCodeReviewMaxDiffPaths;
+
+               if ( is_integer( $diff ) ) {
+                       switch( $diff ) {
+                               case self::DIFFRESULT_BadRevision:
+                                       return 'Bad revision';
+                               case self::DIFFRESULT_NothingToCompare:
+                                       return 'Nothing to compare';
+                               case self::DIFFRESULT_TooManyPaths:
+                                       return 'Too many paths 
($wgCodeReviewMaxDiffPaths = '
+                                              . $wgCodeReviewMaxDiffPaths . 
')';
+                               case self::DIFFRESULT_NoDataReturned:
+                                       return 'No data returned - no diff 
data, or connection lost';
+                               case self::DIFFRESULT_NotInCache:
+                                       return 'Not in cache';
+                               default:
+                                       return 'Unknown reason!';
+                       }
                }
+               
+               // TODO: Should this return "", $diff or a message string, e.g. 
"OK"?
+               return "";
        }
 }

Modified: trunk/extensions/CodeReview/svnImport.php
===================================================================
--- trunk/extensions/CodeReview/svnImport.php   2011-05-27 06:25:21 UTC (rev 
88959)
+++ trunk/extensions/CodeReview/svnImport.php   2011-05-27 08:45:57 UTC (rev 
88960)
@@ -50,7 +50,7 @@
         * @param $start Int Revision to begin the import from (Default: null, 
means last stored revision);
         */
        private function importRepo( $repoName, $start = null, $cacheSize = 0 ) 
{
-               global $wgCodeReviewImportBatchSize, $wgCodeReviewMaxDiffPaths;
+               global $wgCodeReviewImportBatchSize;
 
                $repo = CodeRepository::newFromName( $repoName );
 
@@ -154,25 +154,7 @@
                                $diff = $repo->getDiff( $row->cr_id ); // 
trigger caching
                                $msg = "Diff r{$row->cr_id} ";
                                if ( is_integer( $diff ) ) {
-                                       $msg .= "Skipped: ";
-                                       switch ($diff) {
-                                               case 
CodeRepository::DIFFRESULT_BadRevision:
-                                                       $msg .= "Bad revision";
-                                                       break;
-                                               case 
CodeRepository::DIFFRESULT_NothingToCompare:
-                                                       $msg .= "Nothing to 
compare";
-                                                       break;
-                                               case 
CodeRepository::DIFFRESULT_TooManyPaths:
-                                                       $msg .= "Too many paths 
(\$wgCodeReviewMaxDiffPaths = " 
-                                                             . 
$wgCodeReviewMaxDiffPaths . ")";
-                                                       break;
-                                               case 
CodeRepository::DIFFRESULT_NoDataReturned:
-                                                       $msg .= "No data 
returned - no diff data, or connection lost.";
-                                                       break;
-                                               default:
-                                                       $msg .= "Unknown 
reason!";
-                                                       break;
-                                       }
+                                       $msg .= "Skipped: " . 
CodeRepository::getDiffErrorMessage( $diff );
                                } else {
                                        $msg .= "done";
                                }


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to