From 09011b82e97ceea8045f1acb48c6ca232f47c5cf Mon Sep 17 00:00:00 2001 From: German Laullon Date: Wed, 20 Apr 2011 12:51:24 -0700 Subject: [PATCH] avoid unnecessary reloads --- GLFileView.h | 1 + GLFileView.m | 78 +++++++++++++++++++++++++++------------------------- PBGitTree.m | 5 ++++ 3 files changed, 47 insertions(+), 37 deletions(-) diff --git a/GLFileView.h b/GLFileView.h index a7a5a06..8084ddc 100644 --- a/GLFileView.h +++ b/GLFileView.h @@ -25,6 +25,7 @@ IBOutlet NSView *accessoryView; IBOutlet NSSplitView *fileListSplitView; IBOutlet NSSearchField *searchField; + PBGitTree *lastFile; } - (void)showFile; diff --git a/GLFileView.m b/GLFileView.m index 512bfa3..52c677d 100644 --- a/GLFileView.m +++ b/GLFileView.m @@ -102,42 +102,46 @@ NSArray *files=[historyController.treeController selectedObjects]; if ([files count]>0) { PBGitTree *file=[files objectAtIndex:0]; - - NSString *fileTxt = @""; - if(startFile==@"fileview"){ - fileTxt=[file textContents:&theError]; - if(!theError) - fileTxt=[GLFileView parseHTML:fileTxt]; - }else if(startFile==@"blame"){ - fileTxt=[file blame:&theError]; - if(!theError) - fileTxt=[self parseBlame:fileTxt]; - }else if(startFile==@"log"){ - fileTxt=[file log:logFormat error:&theError]; - }else if(startFile==@"diff"){ - fileTxt=[file diff:diffType error:&theError]; - if(!theError) - fileTxt=[GLFileView parseDiff:fileTxt]; - } - - id script = [view windowScriptObject]; - if(!theError){ - NSString *filePath = [file fullPath]; - fileTxt=[fileTxt stringByReplacingOccurrencesOfString:@"\t" withString:@"    "]; - DLog(@"file.sha='%@'",file.sha); - fileTxt=[fileTxt stringByReplacingOccurrencesOfString:@"{SHA_PREV}" withString:file.sha]; - if(diffType==@"h") { - fileTxt=[fileTxt stringByReplacingOccurrencesOfString:@"{SHA}" withString:@"HEAD"]; - }else { - fileTxt=[fileTxt stringByReplacingOccurrencesOfString:@"{SHA}" withString:@"--"]; + DLog(@"file=%@ == %@ => %d",file,lastFile,[file isEqualTo:lastFile]); + if(![file isEqualTo:lastFile]){ + lastFile=file; + + NSString *fileTxt = @""; + if(startFile==@"fileview"){ + fileTxt=[file textContents:&theError]; + if(!theError) + fileTxt=[GLFileView parseHTML:fileTxt]; + }else if(startFile==@"blame"){ + fileTxt=[file blame:&theError]; + if(!theError) + fileTxt=[self parseBlame:fileTxt]; + }else if(startFile==@"log"){ + fileTxt=[file log:logFormat error:&theError]; + }else if(startFile==@"diff"){ + fileTxt=[file diff:diffType error:&theError]; + if(!theError) + fileTxt=[GLFileView parseDiff:fileTxt]; } - [script callWebScriptMethod:@"showFile" withArguments:[NSArray arrayWithObjects:fileTxt, filePath, nil]]; - }else{ - [script callWebScriptMethod:@"setMessage" withArguments:[NSArray arrayWithObjects:[theError localizedDescription], nil]]; - } + + id script = [view windowScriptObject]; + if(!theError){ + NSString *filePath = [file fullPath]; + fileTxt=[fileTxt stringByReplacingOccurrencesOfString:@"\t" withString:@"    "]; + DLog(@"file.sha='%@'",file.sha); + fileTxt=[fileTxt stringByReplacingOccurrencesOfString:@"{SHA_PREV}" withString:file.sha]; + if(diffType==@"h") { + fileTxt=[fileTxt stringByReplacingOccurrencesOfString:@"{SHA}" withString:@"HEAD"]; + }else { + fileTxt=[fileTxt stringByReplacingOccurrencesOfString:@"{SHA}" withString:@"--"]; + } + [script callWebScriptMethod:@"showFile" withArguments:[NSArray arrayWithObjects:fileTxt, filePath, nil]]; + }else{ + [script callWebScriptMethod:@"setMessage" withArguments:[NSArray arrayWithObjects:[theError localizedDescription], nil]]; + } + [self updateSearch:searchField]; + } } - [self updateSearch:searchField]; #ifdef DEBUG_BUILD DOMHTMLElement *dom=(DOMHTMLElement *)[[[view mainFrame] DOMDocument] documentElement]; @@ -338,10 +342,10 @@ NSMutableString *res=[NSMutableString string]; NSScanner *scan=[NSScanner scannerWithString:txt]; NSString *block; - + [scan scanUpToString:@"Binary files" intoString:NULL]; [scan scanUpToString:@"" intoString:&block]; - + NSArray *files=[self getFilesNames:block]; [res appendString:@""]; [res appendString:[NSString stringWithFormat:@"%@
",[files objectAtIndex:0]]]; @@ -358,7 +362,7 @@ } } [res appendString:@""]; - + return res; } @@ -383,7 +387,7 @@ l_line=abs([[pos_l objectAtIndex:0]integerValue]); r_line=[[pos_r objectAtIndex:0]integerValue]; - + [res appendString:[NSString stringWithFormat:@"%@",line]]; while((line=[lines nextObject])){ NSString *s=[line substringToIndex:1]; diff --git a/PBGitTree.m b/PBGitTree.m index 8c33b73..ad9e1db 100644 --- a/PBGitTree.m +++ b/PBGitTree.m @@ -376,4 +376,9 @@ [[NSFileManager defaultManager] removeItemAtPath:localFileName error:nil]; [super finalize]; } + +- (BOOL)isEqualTo:(PBGitTree *)object +{ + return [sha isEqualTo:[object sha]] && [[self fullPath] isEqualTo:[object fullPath]]; +} @end