diff --git a/GLFileView.m b/GLFileView.m index f1d5fbc..579bee9 100644 --- a/GLFileView.m +++ b/GLFileView.m @@ -73,10 +73,6 @@ @"h", ITEM_IDENTIFIER, @"HEAD", ITEM_NAME, nil], - [NSDictionary dictionaryWithObjectsAndKeys: - @"p", ITEM_IDENTIFIER, - @"Previous", ITEM_NAME, - nil], nil]; [self.groups addObject:[NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:NO], GROUP_SEPARATOR, @@ -93,29 +89,34 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - //NSLog(@"keyPath=%@ change=%@ context=%@ object=%@ \n %@",keyPath,change,context,object,[historyController.treeController selectedObjects]); [self showFile]; } - (void) showFile { + NSError *theError = nil; NSArray *files=[historyController.treeController selectedObjects]; if ([files count]>0) { PBGitTree *file=[files objectAtIndex:0]; - + NSString *fileTxt = @""; - if(startFile==@"fileview") - fileTxt=[self parseHTML:[file textContents]]; - else if(startFile==@"blame") - fileTxt=[self parseBlame:[file blame]]; - else if(startFile==@"log") - fileTxt=[file log:logFormat]; - else if(startFile==@"diff") - fileTxt=[file diff:diffType]; + if(startFile==@"fileview"){ + fileTxt=[self parseHTML:[file textContents:&theError]]; + }else if(startFile==@"blame"){ + fileTxt=[self parseBlame:[file blame:&theError]]; + }else if(startFile==@"log"){ + fileTxt=[file log:logFormat error:&theError]; + }else if(startFile==@"diff"){ + fileTxt=[file diff:diffType error:&theError]; + } id script = [view windowScriptObject]; - NSString *filePath = [file fullPath]; - [script callWebScriptMethod:@"showFile" withArguments:[NSArray arrayWithObjects:fileTxt, filePath, nil]]; + if(theError==nil){ + NSString *filePath = [file fullPath]; + [script callWebScriptMethod:@"showFile" withArguments:[NSArray arrayWithObjects:fileTxt, filePath, nil]]; + }else{ + [script callWebScriptMethod:@"setMessage" withArguments:[NSArray arrayWithObjects:[theError localizedDescription], nil]]; + } } #if 0 @@ -174,7 +175,8 @@ - (void)scopeBar:(MGScopeBar *)theScopeBar selectedStateChanged:(BOOL)selected forItem:(NSString *)identifier inGroup:(int)groupNumber { - if(groupNumber==0){ + NSLog(@"startFile=%@ identifier=%@ groupNumber=%d",startFile,identifier,groupNumber); + if((groupNumber==0) && (startFile!=identifier)){ NSString *path = [NSString stringWithFormat:@"html/views/%@", identifier]; NSString *html = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:path]; NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:html]]; diff --git a/PBGitHistoryController.m b/PBGitHistoryController.m index 03e5c9e..c4037c2 100644 --- a/PBGitHistoryController.m +++ b/PBGitHistoryController.m @@ -228,46 +228,31 @@ { if ([(NSString *)context isEqualToString: @"commitChange"]) { [self updateKeys]; - [self restoreFileBrowserSelection]; - return; - } - - if ([(NSString *)context isEqualToString: @"treeChange"]) { + //[self restoreFileBrowserSelection]; + }else if ([(NSString *)context isEqualToString: @"treeChange"]) { [self updateQuicklookForce: NO]; [self saveFileBrowserSelection]; - return; - } - - if([(NSString *)context isEqualToString:@"branchChange"]) { + }else if([(NSString *)context isEqualToString:@"branchChange"]) { // Reset the sorting if ([[commitController sortDescriptors] count]) [commitController setSortDescriptors:[NSArray array]]; [self updateBranchFilterMatrix]; - return; - } - - if([(NSString *)context isEqualToString:@"updateRefs"]) { + }else if([(NSString *)context isEqualToString:@"updateRefs"]) { [commitController rearrangeObjects]; - return; - } - - if ([(NSString *)context isEqualToString:@"branchFilterChange"]) { + }else if ([(NSString *)context isEqualToString:@"branchFilterChange"]) { [PBGitDefaults setBranchFilter:repository.currentBranchFilter]; [self updateBranchFilterMatrix]; - return; - } - - if([(NSString *)context isEqualToString:@"updateCommitCount"] || [(NSString *)context isEqualToString:@"revisionListUpdating"]) { + }else if([(NSString *)context isEqualToString:@"updateCommitCount"] || [(NSString *)context isEqualToString:@"revisionListUpdating"]) { [self updateStatus]; if ([repository.currentBranch isSimpleRef]) [self selectCommit:[repository shaForRef:[repository.currentBranch ref]]]; else [self selectCommit:[[self firstCommit] sha]]; - return; + }else{ + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } - [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } - (IBAction) openSelectedFile:(id)sender diff --git a/PBGitTree.h b/PBGitTree.h index 7b948d3..27cef62 100644 --- a/PBGitTree.h +++ b/PBGitTree.h @@ -26,10 +26,11 @@ + (PBGitTree*) rootForCommit: (id) commit; + (PBGitTree*) treeForTree: (PBGitTree*) tree andPath: (NSString*) path; - (void) saveToFolder: (NSString *) directory; -- (NSString *)textContents; -- (NSString *)blame; -- (NSString *) log:(NSString *)format; -- (NSString *) diff:(NSString *)format; + +- (NSString *) textContents:(NSError **)anError; +- (NSString *) blame:(NSError **)anError; +- (NSString *) log:(NSString *)format error:(NSError **)anError; +- (NSString *) diff:(NSString *)format error:(NSError **)anError; - (NSString*) tmpFileNameForContents; - (long long)fileSize; diff --git a/PBGitTree.m b/PBGitTree.m index 7a011b3..2f7af52 100644 --- a/PBGitTree.m +++ b/PBGitTree.m @@ -115,73 +115,100 @@ return [repository outputForArguments:[NSArray arrayWithObjects:@"show", [self refSpec], nil]]; } -- (NSString *) blame +- (NSString *) blame:(NSError **)anError { + NSString *error=nil; + NSString *res=nil; if (!leaf) - return [NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]]; + error=[NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]]; if ([self hasBinaryAttributes]) - return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]]; + error=[NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]]; if ([self fileSize] > 52428800) // ~50MB - return [NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]]; + error=[NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]]; - NSString *contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"blame", @"-p", sha, @"--", [self fullPath], nil]]; - - if ([self hasBinaryHeader:contents]) - return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]]; - - - return contents; -} - -- (NSString *) log:(NSString *)format -{ - if (!leaf) - return [NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]]; - - if ([self hasBinaryAttributes]) - return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]]; - - if ([self fileSize] > 52428800) // ~50MB - return [NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]]; - - NSString *contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"log", [NSString stringWithFormat:@"--pretty=format:%@",format], @"--", [self fullPath], nil]]; - - if ([self hasBinaryHeader:contents]) - return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]]; - - - return contents; -} - -- (NSString *) diff:(NSString *)format -{ - if (!leaf) - return [NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]]; - - if ([self hasBinaryAttributes]) - return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]]; - - if ([self fileSize] > 52428800) // ~50MB - return [NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]]; - - NSString *contents=@""; - if(format==@"p") { - contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", sha, [NSString stringWithFormat:@"%@^",sha],[self fullPath], nil]]; - }else if(format==@"h") { - contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", sha, @"HEAD",[self fullPath], nil]]; - }else if(format==@"l") { - contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", sha, @"--",[self fullPath], nil]]; + if(error==nil){ + res=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"blame", @"-p", sha, @"--", [self fullPath], nil]]; + }else{ + *anError = [NSError errorWithDomain:@"blame" code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:error,NSLocalizedDescriptionKey,nil]]; } - - - if ([self hasBinaryHeader:contents]) - return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]]; + return res; +} + +- (NSString *) log:(NSString *)format error:(NSError **)anError +{ + NSString *error=nil; + NSString *res=nil; + if (!leaf) + error=[NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]]; + if(error==nil){ + res=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"log", [NSString stringWithFormat:@"--pretty=format:%@",format], @"--", [self fullPath], nil]]; + }else{ + *anError = [NSError errorWithDomain:@"log" code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:error,NSLocalizedDescriptionKey,nil]]; + } - return contents; + return res; +} + +- (NSString *) diff:(NSString *)format error:(NSError **)anError +{ + NSString *error=nil; + NSString *res=nil; + if (!leaf) + error=[NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]]; + + if ([self hasBinaryAttributes]) + error=[NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]]; + + if ([self fileSize] > 52428800) // ~50MB + error=[NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]]; + + if(error==nil){ + NSString *des=@""; + if(format==@"p") { + des=[NSString stringWithFormat:@"%@^",sha]; + }else if(format==@"h") { + des=@"HEAD"; + }else{ + des=@"--"; + } + res=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", sha, des,[self fullPath], nil]]; + if ([res length]==0) { + NSLog(@"--%d",[res length]); + *anError = [NSError errorWithDomain:@"diff" code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"No Diff",NSLocalizedDescriptionKey,nil]]; + }else{ + NSLog(@"--%@",[res substringToIndex:80]); + } + }else{ + *anError = [NSError errorWithDomain:@"diff" code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:error,NSLocalizedDescriptionKey,nil]]; + } + + return res; +} + +- (NSString *)textContents:(NSError **)anError +{ + NSString *error=nil; + NSString *res=nil; + if (!leaf) + error=[NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]]; + + if ([self hasBinaryAttributes]) + error=[NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]]; + + if ([self fileSize] > 52428800) // ~50MB + error=[NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]]; + + if(error==nil){ + res = [self contents]; + }else{ + *anError = [NSError errorWithDomain:@"show" code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:error,NSLocalizedDescriptionKey,nil]]; + } + + return res; } - (long long)fileSize @@ -200,25 +227,6 @@ return _fileSize; } -- (NSString *)textContents -{ - if (!leaf) - return [NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]]; - - if ([self hasBinaryAttributes]) - return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]]; - - if ([self fileSize] > 52428800) // ~50MB - return [NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]]; - - NSString* contents = [self contents]; - - if ([self hasBinaryHeader:contents]) - return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]]; - - return contents; -} - - (void) saveToFolder: (NSString *) dir { NSString* newName = [dir stringByAppendingPathComponent:path]; diff --git a/html/views/diff/diffWindow.js b/html/views/diff/diffWindow.js index 8d60fc9..cee1133 100644 --- a/html/views/diff/diffWindow.js +++ b/html/views/diff/diffWindow.js @@ -6,7 +6,13 @@ var setMessage = function(message) { $("diff").style.display = "none"; } +var hideMessage = function() { + $("message").style.display = "none"; + $("diff").style.display = ""; +} + var showDiff = function(diff) { + hideMessage(); highlightDiff(diff, $("diff")); }