Skip to content

Commit 62b6dba

Browse files
committed
Parse diff hunks from merge diffs.
For now only the differences to the first parent are shown.
1 parent a67e25c commit 62b6dba

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

GLFileView.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,17 @@ + (NSString *)parseDiffChunk:(NSString *)txt
381381

382382
line=[lines nextObject];
383383
DLog(@"-=%@=-",line);
384-
NSString *header=[line substringFromIndex:3];
385-
NSRange hr = NSMakeRange(0, [header rangeOfString:@" @@"].location);
386-
header=[header substringWithRange:hr];
384+
385+
int arity = 0; /* How many files are merged here? Count the '@'! */
386+
while ([line characterAtIndex:arity] == '@')
387+
arity++;
388+
389+
NSRange hr = NSMakeRange(arity+1, [line rangeOfString:@" @@"].location-arity-1);
390+
NSString *header=[line substringWithRange:hr];
387391

388392
NSArray *pos=[header componentsSeparatedByString:@" "];
389393
NSArray *pos_l=[[pos objectAtIndex:0] componentsSeparatedByString:@","];
390-
NSArray *pos_r=[[pos objectAtIndex:1] componentsSeparatedByString:@","];
394+
NSArray *pos_r=[[pos objectAtIndex:arity-1] componentsSeparatedByString:@","];
391395

392396
l_line=abs([[pos_l objectAtIndex:0]integerValue]);
393397
r_line=[[pos_r objectAtIndex:0]integerValue];
@@ -403,7 +407,7 @@ + (NSString *)parseDiffChunk:(NSString *)txt
403407
[res appendString:[NSString stringWithFormat:@"<tr class='r'><td class='l'></td><td class='r'>%d</td>",r_line++]];
404408
}
405409
if(![s isEqualToString:@"\\"]){
406-
[res appendString:[NSString stringWithFormat:@"<td class='code'>%@</td></tr>",[line substringFromIndex:1]]];
410+
[res appendString:[NSString stringWithFormat:@"<td class='code'>%@</td></tr>",[line substringFromIndex:arity-1]]];
407411
}
408412
}
409413
return res;

0 commit comments

Comments
 (0)