r80822 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80821‎ | r80822 | r80823 >
Date:17:17, 23 January 2011
Author:happydog
Status:ok (Comments)
Tags:
Comment:
[CodeReview] Fixed accidental null value being returned from CodeRepository::getDiff(), from r80691 (see Brion's comment: http://www.mediawiki.org/wiki/Special:Code/MediaWiki/80691#c13341), and therefore also reverted the workaround for this which was added in r80794.

We now return the constant DIFFRESULT_NotInCache when forcing a cache hit and there's nothing there, instead of null.
Modified paths:
  • /trunk/extensions/CodeReview/CodeReview.php (modified) (history)
  • /trunk/extensions/CodeReview/backend/CodeRepository.php (modified) (history)
  • /trunk/extensions/CodeReview/ui/CodeRevisionView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/ui/CodeRevisionView.php
@@ -366,7 +366,7 @@
367367 $cache = '';
368368 }
369369 $diff = $this->mRepo->getDiff( $this->mRev->getId(), $cache );
370 - if ( (is_null($diff) || is_integer($diff)) && $deferDiffs ) {
 370+ if ( is_integer($diff) && $deferDiffs ) {
371371 // We'll try loading it by AJAX...
372372 return $this->stubDiffLoader();
373373 } elseif ( strlen( $diff ) > $wgCodeReviewMaxDiffSize ) {
Index: trunk/extensions/CodeReview/CodeReview.php
@@ -119,6 +119,7 @@
120120 define("DIFFRESULT_NothingToCompare", 1);
121121 define("DIFFRESULT_TooManyPaths", 2);
122122 define("DIFFRESULT_NoDataReturned", 3);
 123+define("DIFFRESULT_NotInCache", 4);
123124
124125 // If you can't directly access the remote SVN repo, you can set this
125126 // to an offsite proxy running this fun little proxy tool:
Index: trunk/extensions/CodeReview/backend/CodeRepository.php
@@ -260,9 +260,6 @@
261261 * @param $useCache 'skipcache' to avoid caching
262262 * 'cached' to *only* fetch if cached
263263 * @return string|int The diff text on success, a DIFFRESULT_* constant on failure.
264 - * @fixme Actually returns null if $useCache='cached' and there's no cached
265 - * data. Either add a relevant constant or fix the comment above;
266 - * caller in CodeRevisionView fixed by adding is_null check.
267264 */
268265 public function getDiff( $rev, $useCache = '' ) {
269266 global $wgMemc, $wgCodeReviewMaxDiffPaths;
@@ -331,30 +328,38 @@
332329
333330 // If the data was not already in the cache or in the DB, we need to retrieve
334331 // it from SVN.
335 - if ( !$data && $useCache !== 'cached' ) {
336 - $svn = SubversionAdaptor::newFromRepo( $this->path );
337 - $data = $svn->getDiff( '', $rev1, $rev2 );
 332+ if ( !$data ) {
 333+ // If the calling code is forcing a cache check, report that it wasn't
 334+ // in the cache.
 335+ if ( $useCache === 'cached' ) {
 336+ $data = DIFFRESULT_NotInCache;
338337
339 - // If $data is blank, report the error that no data was returned.
340 - // TODO: Currently we can't tell the difference between an SVN/connection
341 - // failure and an empty diff. See if we can remedy this!
342 - if ($data == "") {
343 - $data = DIFFRESULT_NoDataReturned;
 338+ // Otherwise, retrieve the diff using SubversionAdaptor.
344339 } else {
345 - // Otherwise, store the resulting diff to both the temporary cache and
346 - // permanent DB storage.
347 - // Store to cache
348 - $wgMemc->set( $key, $data, 3600 * 24 * 3 );
 340+ $svn = SubversionAdaptor::newFromRepo( $this->path );
 341+ $data = $svn->getDiff( '', $rev1, $rev2 );
349342
350 - // Permanent DB storage
351 - $storedData = $data;
352 - $flags = Revision::compressRevisionText( $storedData );
353 - $dbw = wfGetDB( DB_MASTER );
354 - $dbw->update( 'code_rev',
355 - array( 'cr_diff' => $storedData, 'cr_flags' => $flags ),
356 - array( 'cr_repo_id' => $this->id, 'cr_id' => $rev ),
357 - __METHOD__
358 - );
 343+ // If $data is blank, report the error that no data was returned.
 344+ // TODO: Currently we can't tell the difference between an SVN/connection
 345+ // failure and an empty diff. See if we can remedy this!
 346+ if ($data == "") {
 347+ $data = DIFFRESULT_NoDataReturned;
 348+ } else {
 349+ // Otherwise, store the resulting diff to both the temporary cache and
 350+ // permanent DB storage.
 351+ // Store to cache
 352+ $wgMemc->set( $key, $data, 3600 * 24 * 3 );
 353+
 354+ // Permanent DB storage
 355+ $storedData = $data;
 356+ $flags = Revision::compressRevisionText( $storedData );
 357+ $dbw = wfGetDB( DB_MASTER );
 358+ $dbw->update( 'code_rev',
 359+ array( 'cr_diff' => $storedData, 'cr_flags' => $flags ),
 360+ array( 'cr_repo_id' => $this->id, 'cr_id' => $rev ),
 361+ __METHOD__
 362+ );
 363+ }
359364 }
360365 }
361366

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r80691[CodeReview] Modified CodeRepository::getDiff() so it now returns a bit more ...happydog17:16, 21 January 2011
r80794Fix for CodeReview on-demand AJAX diff loading; regression caused by refactor...brion02:56, 23 January 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   17:44, 23 January 2011

Spiff! One more note actually while it's on my mind -- in general, over the years we've migrated away from global-namespace constants for this sort of thing to class constants, like Revision::DELETED_TEXT or UploadBase::SUCCESS.

A big advantage to these is that using them will invoke the autoloader if the class hasn't been loaded yet, so you can define the constants close to where they're actively used and don't need to worry about inclusion order. It also helps clarify what code they "belong" to, which is an aid to later maintenance programmers.

(This isn't a FIXME-style requirement, but I'd recommend it when you have time. :)

Re: the "can't tell difference between connection failure and empty diff", I think we can remedy that in the SubversionAdaptor classes:

  • SubversionAdaptorPecl looks like it should throw an exception on failure, so already good?
  • SubversionAdaptorShell should check the return code; a failure should give a non-zero return which we can parley into a nice exception ;)
  • SubversionProxy should throw an exception on a bad return, but that could depend on whether the proxy actually returns an HTTP error code on error
#Comment by HappyDog (talk | contribs)   19:58, 23 January 2011

OK - I'll look into moving them into class constants when I have a mo.

In terms of the other point, I'm not sure if I know enough about the various adaptor classes to implement that. I can log a bug for it though, if you like.

#Comment by HappyDog (talk | contribs)   12:38, 23 March 2011

Reedy moved the constants into the class in r82479.

Have also logged bug 28202 to deal with the "can't tell difference between connection failure and empty diff" issue.

#Comment by 😂 (talk | contribs)   15:36, 25 March 2011

This is ok for now, bug has been logged to clean up the various error conditions.

Status & tagging log