Index: trunk/extensions/CodeReview/tests/DiffHighlighterTest.php |
— | — | @@ -48,6 +48,37 @@ |
49 | 49 | array( 1, 63, 0, 0 ), |
50 | 50 | '@@ -1,63 +0,0 @@' |
51 | 51 | ), |
| 52 | + array( |
| 53 | + # File deletion? Second param is a default value for s |
| 54 | + array( 1, 1, 0, 0 ), |
| 55 | + '@@ -1 +0,0 @@' |
| 56 | + ), |
| 57 | + array( |
| 58 | + # File addition? Last param is a default value for s |
| 59 | + array( 0, 0, 1, 1 ), |
| 60 | + '@@ -0,0 +1 @@' |
| 61 | + ), |
| 62 | + array( |
| 63 | + array( 1, 1, 1, 1 ), |
| 64 | + '@@ -1 +1 @@' |
| 65 | + ), |
| 66 | + |
| 67 | + # Some chunks which probably are non sense but yet must be |
| 68 | + # considered valid by our chunk parsing code. |
| 69 | + array( |
| 70 | + array( 25, 1, 26, 1 ), |
| 71 | + '@@ -25 +26 @@' |
| 72 | + ), |
| 73 | + array( |
| 74 | + array( 31, 32, 33, 1 ), |
| 75 | + '@@ -31,32 +33 @@' |
| 76 | + ), |
| 77 | + array( |
| 78 | + array( 41, 1, 42, 43 ), |
| 79 | + '@@ -41 +42,43 @@' |
| 80 | + # note how this has the answer to the ultimate question of |
| 81 | + # life, the universe and everything. Useful to hitchhikers. |
| 82 | + ), |
52 | 83 | ); |
53 | 84 | } |
54 | 85 | |
Index: trunk/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 | } |