r112098 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112097‎ | r112098 | r112099 >
Date:10:06, 22 February 2012
Author:hashar
Status:ok
Tags:
Comment:
MFT to 1.19wmf1 r112096

(bug 34554) diff chunk fail to parse file add/rm
Modified paths:
  • /branches/wmf/1.19wmf1/extensions/CodeReview (modified) (history)
  • /branches/wmf/1.19wmf1/extensions/CodeReview/backend/DiffHighlighter.php (modified) (history)
  • /branches/wmf/1.19wmf1/extensions/CodeReview/tests/DiffHighlighterTest.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.19wmf1/extensions/CodeReview/tests/DiffHighlighterTest.php
@@ -46,6 +46,37 @@
4747 array( 1, 63, 0, 0 ),
4848 '@@ -1,63 +0,0 @@'
4949 ),
 50+ array(
 51+ # File deletion? Second param is a default value for s
 52+ array( 1, 1, 0, 0 ),
 53+ '@@ -1 +0,0 @@'
 54+ ),
 55+ array(
 56+ # File addition? Last param is a default value for s
 57+ array( 0, 0, 1, 1 ),
 58+ '@@ -0,0 +1 @@'
 59+ ),
 60+ array(
 61+ array( 1, 1, 1, 1 ),
 62+ '@@ -1 +1 @@'
 63+ ),
 64+
 65+ # Some chunks which probably are non sense but yet must be
 66+ # considered valid by our chunk parsing code.
 67+ array(
 68+ array( 25, 1, 26, 1 ),
 69+ '@@ -25 +26 @@'
 70+ ),
 71+ array(
 72+ array( 31, 32, 33, 1 ),
 73+ '@@ -31,32 +33 @@'
 74+ ),
 75+ array(
 76+ array( 41, 1, 42, 43 ),
 77+ '@@ -41 +42,43 @@'
 78+ # note how this has the answer to the ultimate question of
 79+ # life, the universe and everything. Useful to hitchhikers.
 80+ ),
5081 );
5182 }
5283
Index: branches/wmf/1.19wmf1/extensions/CodeReview/backend/DiffHighlighter.php
@@ -214,6 +214,14 @@
215215 * - l is the starting line number
216216 * - s is the number of lines the change hunk applies to
217217 *
 218+ * 's', for the number of lines, is optional and default to 1.
 219+ * When omitted, the previous comma will be skipped as well. So all
 220+ * following lines are valid too:
 221+ *
 222+ * @@ -l,s +l @@
 223+ * @@ -l +l,s @@
 224+ * @@ -l +l @@
 225+ *
218226 * NOTE: visibility is 'public' since the function covered by tests.
219227 *
220228 * @param $chunk string a one line chunk as described above
@@ -224,16 +232,33 @@
225233
226234 # regex snippet to capture a number
227235 $n = "(\d+)";
 236+ $s = "(?:,(\d+))";
 237+ $matches = preg_match( "/^@@ -$n$s \+$n$s @@$/", $chunkHeader, $m );
 238+ if( $matches === 1 ) {
 239+ array_shift( $m );
 240+ return $m;
 241+ }
228242
229 - $matches = preg_match( "/^@@ -$n,$n \+$n,$n @@$/", $chunkHeader, $m );
230 - array_shift( $m );
 243+ $s_default_value = 1;
231244
232 - if( $matches !== 1 ) {
233 - # We really really should have matched something!
234 - throw new MWException(
235 - __METHOD__ . " given an invalid chunk header: '$chunkHeader'\n"
236 - );
 245+ $matches = preg_match( "/^@@ -$n$s \+$n @@$/", $chunkHeader, $m );
 246+ if( $matches === 1 ) {
 247+ return array( $m[1], $m[2], $m[3], $s_default_value );
237248 }
238 - return $m;
 249+
 250+ $matches = preg_match( "/^@@ -$n \+$n$s @@$/", $chunkHeader, $m );
 251+ if( $matches === 1 ) {
 252+ return array( $m[1], $s_default_value, $m[2], $m[3] );
 253+ }
 254+
 255+ $matches = preg_match( "/^@@ -$n \+$n @@$/", $chunkHeader, $m );
 256+ if( $matches === 1 ) {
 257+ return array( $m[1], $s_default_value, $m[2], $s_default_value );
 258+ }
 259+
 260+ # We really really should have matched something!
 261+ throw new MWException(
 262+ __METHOD__ . " given an invalid chunk header: '$chunkHeader'\n"
 263+ );
239264 }
240265 }
Property changes on: branches/wmf/1.19wmf1/extensions/CodeReview
___________________________________________________________________
Modified: svn:mergeinfo
241266 Merged /trunk/extensions/CodeReview:r112096

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r112096(bug 34554) diff chunk fail to parse file add/rm...hashar10:01, 22 February 2012

Status & tagging log