@@ -181,7 +181,6 @@ - (MGScopeBarGroupSelectionMode)scopeBar:(MGScopeBar *)theScopeBar selectionMode
181
181
182
182
- (void )scopeBar : (MGScopeBar *)theScopeBar selectedStateChanged : (BOOL )selected forItem : (NSString *)identifier inGroup : (int )groupNumber
183
183
{
184
- NSLog (@" startFile=%@ identifier=%@ groupNumber=%d " ,startFile,identifier,groupNumber);
185
184
if ((groupNumber==0 ) && (startFile!=identifier)){
186
185
NSString *path = [NSString stringWithFormat: @" html/views/%@ " , identifier];
187
186
NSString *html = [[NSBundle mainBundle ] pathForResource: @" index" ofType: @" html" inDirectory: path];
@@ -238,11 +237,10 @@ + (NSString *)parseDiffTree:(NSString *)txt withStats:(NSMutableDictionary *)sta
238
237
NSArray *lines = [txt componentsSeparatedByString: @" \n " ];
239
238
NSMutableString *res=[NSMutableString string ];
240
239
[res appendString: @" <table id='filelist'>" ];
241
- int i;
242
- for (i=1 ; i<[lines count ]; i++) {
243
- NSString *line=[lines objectAtIndex: i];
244
- NSArray *fields=[line componentsSeparatedByString: @" " ];
245
- NSArray *fileStatus=[[fields objectAtIndex: 4 ] componentsSeparatedByString: @" \t " ];
240
+ for (NSString *line in lines) {
241
+ if ([line length ]<98 ) continue ;
242
+ line=[line substringFromIndex: 97 ];
243
+ NSArray *fileStatus=[line componentsSeparatedByString: @" \t " ];
246
244
NSString *status=[[fileStatus objectAtIndex: 0 ] substringToIndex: 1 ]; // ignore the score
247
245
NSString *file=[fileStatus objectAtIndex: 1 ];
248
246
NSString *txt=file;
@@ -331,17 +329,19 @@ + (NSString *)parseDiff:(NSString *)txt
331
329
}else if (inDiff){
332
330
[res appendString: [NSString stringWithFormat: @" <p>%@ </p>" ,line]];
333
331
if ([self isBinaryFile: line]){
334
- NSLog (@" line='%@ '" ,line);
335
332
[res appendString: @" </td></tr></thead><tbody>" ];
336
333
NSArray *files=[self getFilesNames: line];
337
- NSLog (@" files='%@ '" ,files);
338
334
if (![[files objectAtIndex: 0 ] isAbsolutePath ]){
339
335
[res appendString: [NSString stringWithFormat: @" <tr><td colspan='3'>%@ </td></tr>" ,[files objectAtIndex: 0 ]]];
340
- [res appendString: [NSString stringWithFormat: @" <tr><td colspan='3'><img src='GitX://{SHA}:/prev/%@ '/></td></tr>" ,[files objectAtIndex: 0 ]]];
336
+ if ([GLFileView isImage: [files objectAtIndex: 0 ]]){
337
+ [res appendString: [NSString stringWithFormat: @" <tr><td colspan='3'><img src='GitX://{SHA}:/prev/%@ '/></td></tr>" ,[files objectAtIndex: 0 ]]];
338
+ }
341
339
}
342
340
if (![[files objectAtIndex: 1 ] isAbsolutePath ]){
343
341
[res appendString: [NSString stringWithFormat: @" <tr><td colspan='3'>%@ </td></tr>" ,[files objectAtIndex: 1 ]]];
344
- [res appendString: [NSString stringWithFormat: @" <tr><td colspan='3'><img src='GitX://{SHA}/%@ '/></td></tr>" ,[files objectAtIndex: 1 ]]];
342
+ if ([GLFileView isImage: [files objectAtIndex: 1 ]]){
343
+ [res appendString: [NSString stringWithFormat: @" <tr><td colspan='3'><img src='GitX://{SHA}/%@ '/></td></tr>" ,[files objectAtIndex: 1 ]]];
344
+ }
345
345
}
346
346
}
347
347
}
@@ -362,7 +362,6 @@ +(NSArray *)getFilesNames:(NSString *)line
362
362
{
363
363
NSString *a;
364
364
NSString *b;
365
- NSLog (@" line='%@ '" ,line);
366
365
NSScanner *scanner=[NSScanner scannerWithString: line];
367
366
if ([scanner scanString: @" Binary files " intoString: NULL ]){
368
367
[scanner scanUpToString: @" and" intoString: &a];
@@ -375,10 +374,34 @@ +(NSArray *)getFilesNames:(NSString *)line
375
374
if (![b isAbsolutePath ]) {
376
375
b=[b substringFromIndex: 2 ];
377
376
}
378
-
377
+
379
378
return [NSArray arrayWithObjects: a,b,nil ];
380
379
}
381
380
381
+ +(NSString *)mimeTypeForFileName : (NSString *)name
382
+ {
383
+ NSString *mimeType = nil ;
384
+ NSInteger i=[name rangeOfString: @" ." options: NSBackwardsSearch].location ;
385
+ if (i!=NSNotFound ){
386
+ NSString *ext=[name substringFromIndex: i+1 ];
387
+ CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag (kUTTagClassFilenameExtension , (CFStringRef)ext, NULL );
388
+ if (UTI){
389
+ CFStringRef registeredType = UTTypeCopyPreferredTagWithClass (UTI, kUTTagClassMIMEType );
390
+ if (registeredType){
391
+ mimeType = NSMakeCollectable (registeredType);
392
+ }
393
+ CFRelease (UTI);
394
+ }
395
+ }
396
+ return mimeType;
397
+ }
398
+
399
+ +(BOOL )isImage : (NSString *)file
400
+ {
401
+ NSString *mimeType=[GLFileView mimeTypeForFileName: file];
402
+ return (mimeType!=nil ) && ([mimeType rangeOfString: @" image/" options: NSCaseInsensitiveSearch].location !=NSNotFound );
403
+ }
404
+
382
405
+(BOOL )isBinaryFile : (NSString *)line
383
406
{
384
407
return (([line length ]>12 ) && [[line substringToIndex: 12 ] isEqualToString: @" Binary files" ]);
0 commit comments