Skip to content

Commit 812c2ad

Browse files
committed
images on diff
1 parent f0b1b74 commit 812c2ad

File tree

4 files changed

+58
-7
lines changed

4 files changed

+58
-7
lines changed

GLFileView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
+ (NSString *)parseHTML:(NSString *)txt;
3232
+ (NSString *)parseDiff:(NSString *)txt;
3333
+ (NSString *)parseDiffTree:(NSString *)txt withStats:(NSMutableDictionary *)stats;
34+
+ (NSString *)getFileName:(NSString *)line;
35+
3436
+(BOOL)isStartDiff:(NSString *)line;
3537
+(BOOL)isStartBlock:(NSString *)line;
3638

GLFileView.m

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ + (NSString *) parseHTML:(NSString *)txt
225225

226226
+ (NSString *)parseDiffTree:(NSString *)txt withStats:(NSMutableDictionary *)stats
227227
{
228-
NSInteger granTotal=0;
228+
NSInteger granTotal=1;
229229
for(NSArray *stat in [stats allValues]){
230230
NSInteger add=[[stat objectAtIndex:0] integerValue];
231231
NSInteger rem=[[stat objectAtIndex:1] integerValue];
@@ -330,19 +330,60 @@ + (NSString *)parseDiff:(NSString *)txt
330330
[res appendString:[NSString stringWithFormat:@"<p>%@</p>",line]];
331331
}else if(inDiff){
332332
[res appendString:[NSString stringWithFormat:@"<p>%@</p>",line]];
333+
if([self isBinaryFile:line]){
334+
NSLog(@"line='%@'",line);
335+
[res appendString:@"</td></tr></thead><tbody>"];
336+
NSArray *files=[self getFilesNames:line];
337+
NSLog(@"files='%@'",files);
338+
if(![[files objectAtIndex:0] isAbsolutePath]){
339+
[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]]];
341+
}
342+
if(![[files objectAtIndex:1] isAbsolutePath]){
343+
[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]]];
345+
}
346+
}
333347
}
334348
}
335349
if(inDiff)
336350
[res appendString:@"</tbody></table>"];
337351
return res;
338352
}
339353

340-
+(NSString *)getFileName:(NSString *)line{
354+
+(NSString *)getFileName:(NSString *)line
355+
{
341356
NSRange b = [line rangeOfString:@"b/"];
342357
NSString *file=[line substringFromIndex:b.location+2];
343358
return file;
344359
}
345360

361+
+(NSArray *)getFilesNames:(NSString *)line
362+
{
363+
NSString *a;
364+
NSString *b;
365+
NSLog(@"line='%@'",line);
366+
NSScanner *scanner=[NSScanner scannerWithString:line];
367+
if([scanner scanString:@"Binary files " intoString:NULL]){
368+
[scanner scanUpToString:@" and" intoString:&a];
369+
[scanner scanString:@"and" intoString:NULL];
370+
[scanner scanUpToString:@" differ" intoString:&b];
371+
}
372+
if (![a isAbsolutePath]) {
373+
a=[a substringFromIndex:2];
374+
}
375+
if (![b isAbsolutePath]) {
376+
b=[b substringFromIndex:2];
377+
}
378+
379+
return [NSArray arrayWithObjects:a,b,nil];
380+
}
381+
382+
+(BOOL)isBinaryFile:(NSString *)line
383+
{
384+
return (([line length]>12) && [[line substringToIndex:12] isEqualToString:@"Binary files"]);
385+
}
386+
346387
+(BOOL)isStartDiff:(NSString *)line
347388
{
348389
return (([line length]>10) && [[line substringToIndex:10] isEqualToString:@"diff --git"]);

PBGitXProtocol.m

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,28 @@ -(void)startLoading
2525
{
2626
NSURL *url = [[self request] URL];
2727
PBGitRepository *repo = [[self request] repository];
28-
28+
2929
if(!repo) {
3030
[[self client] URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:nil]];
3131
return;
3232
}
33-
34-
NSString *specifier = [NSString stringWithFormat:@"%@:%@", [url host], [[url path] substringFromIndex:1]];
33+
34+
NSString *path=[[url path] substringFromIndex:1];
35+
NSString *v=@"";
36+
if ([[path substringToIndex:5] isEqualToString:@"prev/"]) {
37+
path=[path substringFromIndex:5];
38+
v=@"^";
39+
}
40+
NSString *specifier = [NSString stringWithFormat:@"%@%@:%@", [url host], v,path];
3541
handle = [repo handleInWorkDirForArguments:[NSArray arrayWithObjects:@"cat-file", @"blob", specifier, nil]];
3642
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishFileLoad:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle];
3743
[handle readToEndOfFileInBackgroundAndNotify];
38-
44+
3945
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL]
4046
MIMEType:nil
4147
expectedContentLength:-1
4248
textEncodingName:nil];
43-
49+
4450
[[self client] URLProtocol:self
4551
didReceiveResponse:response
4652
cacheStoragePolicy:NSURLCacheStorageNotAllowed];

PBWebHistoryController.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ - (void)commitDetailsLoaded:(NSNotification *)notification
116116

117117
NSString *html=[NSString stringWithFormat:@"%@%@<div id='diffs'>%@</div>",header,fileList,diffs];
118118

119+
html=[html stringByReplacingOccurrencesOfString:@"{SHA}" withString:[currentSha string]];
120+
119121
[[view windowScriptObject] callWebScriptMethod:@"showCommit" withArguments:[NSArray arrayWithObject:html]];
120122

121123
#if 1

0 commit comments

Comments
 (0)