From 62b6dba98302618872e2d587af8023697e094bc8 Mon Sep 17 00:00:00 2001 From: Uwe Hees Date: Sat, 7 May 2011 09:07:04 +0200 Subject: [PATCH] Parse diff hunks from merge diffs. For now only the differences to the first parent are shown. --- GLFileView.m | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/GLFileView.m b/GLFileView.m index 46ab18b..1cbee27 100644 --- a/GLFileView.m +++ b/GLFileView.m @@ -381,13 +381,17 @@ line=[lines nextObject]; DLog(@"-=%@=-",line); - NSString *header=[line substringFromIndex:3]; - NSRange hr = NSMakeRange(0, [header rangeOfString:@" @@"].location); - header=[header substringWithRange:hr]; + + int arity = 0; /* How many files are merged here? Count the '@'! */ + while ([line characterAtIndex:arity] == '@') + arity++; + + NSRange hr = NSMakeRange(arity+1, [line rangeOfString:@" @@"].location-arity-1); + NSString *header=[line substringWithRange:hr]; NSArray *pos=[header componentsSeparatedByString:@" "]; NSArray *pos_l=[[pos objectAtIndex:0] componentsSeparatedByString:@","]; - NSArray *pos_r=[[pos objectAtIndex:1] componentsSeparatedByString:@","]; + NSArray *pos_r=[[pos objectAtIndex:arity-1] componentsSeparatedByString:@","]; l_line=abs([[pos_l objectAtIndex:0]integerValue]); r_line=[[pos_r objectAtIndex:0]integerValue]; @@ -403,7 +407,7 @@ [res appendString:[NSString stringWithFormat:@"%d",r_line++]]; } if(![s isEqualToString:@"\\"]){ - [res appendString:[NSString stringWithFormat:@"%@",[line substringFromIndex:1]]]; + [res appendString:[NSString stringWithFormat:@"%@",[line substringFromIndex:arity-1]]]; } } return res;