From 8896dc993c73c704d54b44ecbe2d025d0fc8ec16 Mon Sep 17 00:00:00 2001 From: German Laullon Date: Fri, 4 Mar 2011 13:38:55 -0800 Subject: [PATCH 1/3] basic FileMerge support --- GLFileView.m | 1 + PBGitXProtocol.m | 51 ++++++++++++++++++++++------------ PBWebController.m | 5 ++++ PBWebHistoryController.h | 1 + PBWebHistoryController.m | 7 +++++ html/views/history/history.css | 5 ++++ html/views/history/history.js | 6 ++++ 7 files changed, 58 insertions(+), 18 deletions(-) diff --git a/GLFileView.m b/GLFileView.m index 4999df4..27e8ac1 100644 --- a/GLFileView.m +++ b/GLFileView.m @@ -324,6 +324,7 @@ inDiff=TRUE; NSString *fileName=[self getFileName:line]; [res appendString:[NSString stringWithFormat:@""]; - inDiff=FALSE; - NSString *header=[line substringFromIndex:3]; - NSRange hr = NSMakeRange(0, [header rangeOfString:@" @@"].location); - header=[header substringWithRange:hr]; - - NSArray *pos=[header componentsSeparatedByString:@" "]; - NSArray *pos_l=[[pos objectAtIndex:0] componentsSeparatedByString:@","]; - NSArray *pos_r=[[pos objectAtIndex:1] componentsSeparatedByString:@","]; - - l_end=l_line=abs([[pos_l objectAtIndex:0]integerValue]); - if ([pos_l count]>1) { - l_end=l_line+[[pos_l objectAtIndex:1]integerValue]; - } - - r_end=r_line=[[pos_r objectAtIndex:0]integerValue]; - if ([pos_r count]>1) { - r_end=r_line+[[pos_r objectAtIndex:1]integerValue]; - } - - [res appendString:[NSString stringWithFormat:@"",line]]; - inBlock=TRUE; - }else if(inBlock){ - NSString *s=[line substringToIndex:1]; - if([s isEqualToString:@" "]){ - [res appendString:[NSString stringWithFormat:@"",l_line++,r_line++]]; - }else if([s isEqualToString:@"-"]){ - [res appendString:[NSString stringWithFormat:@"",l_line++]]; - }else if([s isEqualToString:@"+"]){ - [res appendString:[NSString stringWithFormat:@"",r_line++]]; - } - [res appendString:[NSString stringWithFormat:@"",[line substringFromIndex:1]]]; - if(!(l_line
",fileName]]; + [res appendString:[NSString stringWithFormat:@"",fileName]]; [res appendString:[NSString stringWithFormat:@"

%@

",line]]; }else if(inDiff){ [res appendString:[NSString stringWithFormat:@"

%@

",line]]; diff --git a/PBGitXProtocol.m b/PBGitXProtocol.m index 7d1e1bc..5fe8194 100644 --- a/PBGitXProtocol.m +++ b/PBGitXProtocol.m @@ -31,25 +31,40 @@ return; } - NSString *path=[[url path] substringFromIndex:1]; - NSString *v=@""; - if ([[path substringToIndex:5] isEqualToString:@"prev/"]) { - path=[path substringFromIndex:5]; - v=@"^"; + if ([[url host] isEqualToString:@"app"]) { + NSString *app=[[url path] substringFromIndex:1]; + NSString *appPath=[[NSWorkspace sharedWorkspace] fullPathForApplication:app]; + NSLog(@"app=%@ appPath=%@",app,appPath); + if(appPath){ + NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:appPath]; + NSLog(@"icon=%@",icon); + [[self client] URLProtocol:self didLoadData:[icon TIFFRepresentation]]; + [[self client] URLProtocolDidFinishLoading:self]; + }else{ + [[self client] URLProtocol:self didFailWithError:[NSError errorWithDomain:@"gitx" code:404 userInfo:nil]]; + } + }else { + + NSString *path=[[url path] substringFromIndex:1]; + NSString *v=@""; + if ([[path substringToIndex:5] isEqualToString:@"prev/"]) { + path=[path substringFromIndex:5]; + v=@"^"; + } + NSString *specifier = [NSString stringWithFormat:@"%@%@:%@", [url host], v,path]; + handle = [repo handleInWorkDirForArguments:[NSArray arrayWithObjects:@"cat-file", @"blob", specifier, nil]]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishFileLoad:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle]; + [handle readToEndOfFileInBackgroundAndNotify]; + + NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL] + MIMEType:nil + expectedContentLength:-1 + textEncodingName:nil]; + + [[self client] URLProtocol:self + didReceiveResponse:response + cacheStoragePolicy:NSURLCacheStorageNotAllowed]; } - NSString *specifier = [NSString stringWithFormat:@"%@%@:%@", [url host], v,path]; - handle = [repo handleInWorkDirForArguments:[NSArray arrayWithObjects:@"cat-file", @"blob", specifier, nil]]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishFileLoad:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle]; - [handle readToEndOfFileInBackgroundAndNotify]; - - NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL] - MIMEType:nil - expectedContentLength:-1 - textEncodingName:nil]; - - [[self client] URLProtocol:self - didReceiveResponse:response - cacheStoragePolicy:NSURLCacheStorageNotAllowed]; } - (void) didFinishFileLoad:(NSNotification *)notification diff --git a/PBWebController.m b/PBWebController.m index ab890fb..7c18db8 100644 --- a/PBWebController.m +++ b/PBWebController.m @@ -76,6 +76,11 @@ NSLog(@"Error from webkit: %@", dictionary); } +- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame +{ + NSLog(@"Message from webkit: %@", message); +} + - (NSURLRequest *)webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request diff --git a/PBWebHistoryController.h b/PBWebHistoryController.h index 0d887be..7f4fc4a 100644 --- a/PBWebHistoryController.h +++ b/PBWebHistoryController.h @@ -29,6 +29,7 @@ - (NSString *)parseHeader:(NSString *)txt withRefs:(NSString *)badges; - (NSMutableDictionary *)parseStats:(NSString *)txt; - (NSString *) someMethodThatReturnsSomeHashForSomeString:(NSString*)concat; +- (void) openFileMerge:(NSString*)file sha:(NSString *)sha; @property (readonly) NSString* diff; @end diff --git a/PBWebHistoryController.m b/PBWebHistoryController.m index d38a180..75d69ce 100644 --- a/PBWebHistoryController.m +++ b/PBWebHistoryController.m @@ -224,6 +224,13 @@ [historyController selectCommit:[PBGitSHA shaWithString:sha]]; } +- (void) openFileMerge:(NSString*)file sha:(NSString *)sha +{ + NSArray *args=[NSArray arrayWithObjects:@"difftool",@"--no-prompt",@"--tool=opendiff",[NSString stringWithFormat:@"%@^",sha],sha,file,nil]; + [historyController.repository handleForArguments:args]; +} + + - (void) sendKey: (NSString*) key { id script = [view windowScriptObject]; diff --git a/html/views/history/history.css b/html/views/history/history.css index 6ac1cda..8c073d4 100644 --- a/html/views/history/history.css +++ b/html/views/history/history.css @@ -317,4 +317,9 @@ a.showdiff { -webkit-box-shadow: 5px 5px 5px #ccc; width: 98%; margin: auto auto 20px 1%; +} + +.filemerge { + float: right; + text-align: center; } \ No newline at end of file diff --git a/html/views/history/history.js b/html/views/history/history.js index e37baee..6a3b3e1 100644 --- a/html/views/history/history.js +++ b/html/views/history/history.js @@ -2,6 +2,12 @@ var selectCommit = function(a) { Controller.selectCommit_(a); } +var openFileMerge = function(file,sha) { + alert(file); + alert(sha); + Controller.openFileMerge_sha_(file,sha); +} + var showImage = function(element, filename) { element.outerHTML = ''; From a098c4038a176c99341a76070ef0e3ce3bc7b933 Mon Sep 17 00:00:00 2001 From: German Laullon Date: Fri, 4 Mar 2011 13:56:01 -0800 Subject: [PATCH 2/3] workaround _NSCFURLProtocolBridge BUG!!! --- PBGitXProtocol.m | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/PBGitXProtocol.m b/PBGitXProtocol.m index 5fe8194..052a667 100644 --- a/PBGitXProtocol.m +++ b/PBGitXProtocol.m @@ -11,6 +11,19 @@ @implementation PBGitXProtocol +- (id)initWithRequest:(NSURLRequest *)request cachedResponse:(NSCachedURLResponse *)cachedResponse client:(id )client +{ + // work around for NSURLProtocol bug + // note that this leaks! + CFRetain(client); + + if (self = [super initWithRequest:request cachedResponse:cachedResponse client:client]) + { + } + + return self; +} + + (BOOL) canInitWithRequest:(NSURLRequest *)request { return [[[request URL] scheme] isEqualToString:@"GitX"]; From 5f85c8269cb236ffcec5190abf9ad8b046fed7db Mon Sep 17 00:00:00 2001 From: German Laullon Date: Fri, 4 Mar 2011 23:54:34 -0800 Subject: [PATCH 3/3] diff parser refactoring --- GLFileView.h | 1 + GLFileView.m | 118 ++++++++++++++++++++++++++++----------------------- 2 files changed, 65 insertions(+), 54 deletions(-) diff --git a/GLFileView.h b/GLFileView.h index 7dd9125..a734dd0 100644 --- a/GLFileView.h +++ b/GLFileView.h @@ -40,6 +40,7 @@ +(BOOL)isBinaryFile:(NSString *)line; +(NSString*)mimeTypeForFileName:(NSString*)file; +(BOOL)isImage:(NSString*)file; ++(BOOL)isDiffHeader:(NSString*)line; @property(retain) NSMutableArray *groups; @property(retain) NSString *logFormat; diff --git a/GLFileView.m b/GLFileView.m index 27e8ac1..1ff1ded 100644 --- a/GLFileView.m +++ b/GLFileView.m @@ -274,62 +274,27 @@ NSArray *lines = [txt componentsSeparatedByString:@"\n"]; NSString *line; NSMutableString *res=[NSMutableString string]; - BOOL inDiff=FALSE; - BOOL inBlock=FALSE; - + int l_line,l_end; int r_line,r_end; - int i; - for (i=0; i<[lines count]; i++) { + + int i=0; + do { line=[lines objectAtIndex:i]; - - if([GLFileView isStartBlock:line]){ - [res appendString:@"
%@
%d%d
%d
%d%@
"]; - inDiff=TRUE; + if([GLFileView isStartDiff:line]){ NSString *fileName=[self getFileName:line]; - [res appendString:[NSString stringWithFormat:@"
",fileName]]; - [res appendString:[NSString stringWithFormat:@"",fileName]]; - [res appendString:[NSString stringWithFormat:@"

%@

",line]]; - }else if(inDiff){ - [res appendString:[NSString stringWithFormat:@"

%@

",line]]; + [res appendString:[NSString stringWithFormat:@""]; + if([self isBinaryFile:line]){ - [res appendString:@""]; NSArray *files=[self getFilesNames:line]; if(![[files objectAtIndex:0] isAbsolutePath]){ [res appendString:[NSString stringWithFormat:@"",[files objectAtIndex:0]]]; @@ -343,11 +308,50 @@ [res appendString:[NSString stringWithFormat:@"",[files objectAtIndex:1]]]; } } + }else{ + do{ + NSString *header=[line substringFromIndex:3]; + NSRange hr = NSMakeRange(0, [header rangeOfString:@" @@"].location); + header=[header substringWithRange:hr]; + + NSArray *pos=[header componentsSeparatedByString:@" "]; + NSArray *pos_l=[[pos objectAtIndex:0] componentsSeparatedByString:@","]; + NSArray *pos_r=[[pos objectAtIndex:1] componentsSeparatedByString:@","]; + + l_end=l_line=abs([[pos_l objectAtIndex:0]integerValue]); + if ([pos_l count]>1) { + l_end=l_line+[[pos_l objectAtIndex:1]integerValue]; + } + + r_end=r_line=[[pos_r objectAtIndex:0]integerValue]; + if ([pos_r count]>1) { + r_end=r_line+[[pos_r objectAtIndex:1]integerValue]; + } + + [res appendString:[NSString stringWithFormat:@"",line]]; + do{ + line=[lines objectAtIndex:++i]; + NSString *s=[line substringToIndex:1]; + if([s isEqualToString:@" "]){ + [res appendString:[NSString stringWithFormat:@"",l_line++,r_line++]]; + }else if([s isEqualToString:@"-"]){ + [res appendString:[NSString stringWithFormat:@"",l_line++]]; + }else if([s isEqualToString:@"+"]){ + [res appendString:[NSString stringWithFormat:@"",r_line++]]; + } + [res appendString:[NSString stringWithFormat:@"",[line substringFromIndex:1]]]; + }while((l_line
",fileName]]; + do{ + [res appendString:[NSString stringWithFormat:@"

%@

",line]]; + line=[lines objectAtIndex:++i]; + }while([GLFileView isDiffHeader:line]); + [res appendString:@"
"]; + if(![self isBinaryFile:line]){ + [res appendString:[NSString stringWithFormat:@"",fileName]]; + } + [res appendString:@"
%@
%@
%d%d
%d
%d%@
"]; + }else { + i++; } - } - if(inDiff) - [res appendString:@"
"]; + }while(i<[lines count]); + return res; } @@ -396,6 +400,12 @@ return mimeType; } ++(BOOL)isDiffHeader:(NSString*)line +{ + unichar c=[line characterAtIndex:0]; + return (c=='i') || (c=='m') || (c=='n') || (c=='d') || (c=='-') || (c=='+'); +} + +(BOOL)isImage:(NSString*)file { NSString *mimeType=[GLFileView mimeTypeForFileName:file];