Index: branches/wmf/1.19wmf1/extensions/CodeReview/tests/DiffHighlighterTest.php |
— | — | @@ -46,6 +46,37 @@ |
47 | 47 | array( 1, 63, 0, 0 ), |
48 | 48 | '@@ -1,63 +0,0 @@' |
49 | 49 | ), |
| 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 | + ), |
50 | 81 | ); |
51 | 82 | } |
52 | 83 | |
Index: branches/wmf/1.19wmf1/extensions/CodeReview/backend/DiffHighlighter.php |
— | — | @@ -214,6 +214,14 @@ |
215 | 215 | * - l is the starting line number |
216 | 216 | * - s is the number of lines the change hunk applies to |
217 | 217 | * |
| 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 | + * |
218 | 226 | * NOTE: visibility is 'public' since the function covered by tests. |
219 | 227 | * |
220 | 228 | * @param $chunk string a one line chunk as described above |
— | — | @@ -224,16 +232,33 @@ |
225 | 233 | |
226 | 234 | # regex snippet to capture a number |
227 | 235 | $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 | + } |
228 | 242 | |
229 | | - $matches = preg_match( "/^@@ -$n,$n \+$n,$n @@$/", $chunkHeader, $m ); |
230 | | - array_shift( $m ); |
| 243 | + $s_default_value = 1; |
231 | 244 | |
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 ); |
237 | 248 | } |
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 | + ); |
239 | 264 | } |
240 | 265 | } |
Property changes on: branches/wmf/1.19wmf1/extensions/CodeReview |
___________________________________________________________________ |
Modified: svn:mergeinfo |
241 | 266 | Merged /trunk/extensions/CodeReview:r112096 |