Skip to content

Commit 09011b8

Browse files
committed
avoid unnecessary reloads
1 parent e109d03 commit 09011b8

File tree

3 files changed

+47
-37
lines changed

3 files changed

+47
-37
lines changed

GLFileView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
IBOutlet NSView *accessoryView;
2626
IBOutlet NSSplitView *fileListSplitView;
2727
IBOutlet NSSearchField *searchField;
28+
PBGitTree *lastFile;
2829
}
2930

3031
- (void)showFile;

GLFileView.m

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -102,42 +102,46 @@ - (void) showFile
102102
NSArray *files=[historyController.treeController selectedObjects];
103103
if ([files count]>0) {
104104
PBGitTree *file=[files objectAtIndex:0];
105-
106-
NSString *fileTxt = @"";
107-
if(startFile==@"fileview"){
108-
fileTxt=[file textContents:&theError];
109-
if(!theError)
110-
fileTxt=[GLFileView parseHTML:fileTxt];
111-
}else if(startFile==@"blame"){
112-
fileTxt=[file blame:&theError];
113-
if(!theError)
114-
fileTxt=[self parseBlame:fileTxt];
115-
}else if(startFile==@"log"){
116-
fileTxt=[file log:logFormat error:&theError];
117-
}else if(startFile==@"diff"){
118-
fileTxt=[file diff:diffType error:&theError];
119-
if(!theError)
120-
fileTxt=[GLFileView parseDiff:fileTxt];
121-
}
122-
123-
id script = [view windowScriptObject];
124-
if(!theError){
125-
NSString *filePath = [file fullPath];
126-
fileTxt=[fileTxt stringByReplacingOccurrencesOfString:@"\t" withString:@"    "];
127-
DLog(@"file.sha='%@'",file.sha);
128-
fileTxt=[fileTxt stringByReplacingOccurrencesOfString:@"{SHA_PREV}" withString:file.sha];
129-
if(diffType==@"h") {
130-
fileTxt=[fileTxt stringByReplacingOccurrencesOfString:@"{SHA}" withString:@"HEAD"];
131-
}else {
132-
fileTxt=[fileTxt stringByReplacingOccurrencesOfString:@"{SHA}" withString:@"--"];
105+
DLog(@"file=%@ == %@ => %d",file,lastFile,[file isEqualTo:lastFile]);
106+
if(![file isEqualTo:lastFile]){
107+
lastFile=file;
108+
109+
NSString *fileTxt = @"";
110+
if(startFile==@"fileview"){
111+
fileTxt=[file textContents:&theError];
112+
if(!theError)
113+
fileTxt=[GLFileView parseHTML:fileTxt];
114+
}else if(startFile==@"blame"){
115+
fileTxt=[file blame:&theError];
116+
if(!theError)
117+
fileTxt=[self parseBlame:fileTxt];
118+
}else if(startFile==@"log"){
119+
fileTxt=[file log:logFormat error:&theError];
120+
}else if(startFile==@"diff"){
121+
fileTxt=[file diff:diffType error:&theError];
122+
if(!theError)
123+
fileTxt=[GLFileView parseDiff:fileTxt];
133124
}
134-
[script callWebScriptMethod:@"showFile" withArguments:[NSArray arrayWithObjects:fileTxt, filePath, nil]];
135-
}else{
136-
[script callWebScriptMethod:@"setMessage" withArguments:[NSArray arrayWithObjects:[theError localizedDescription], nil]];
137-
}
125+
126+
id script = [view windowScriptObject];
127+
if(!theError){
128+
NSString *filePath = [file fullPath];
129+
fileTxt=[fileTxt stringByReplacingOccurrencesOfString:@"\t" withString:@"    "];
130+
DLog(@"file.sha='%@'",file.sha);
131+
fileTxt=[fileTxt stringByReplacingOccurrencesOfString:@"{SHA_PREV}" withString:file.sha];
132+
if(diffType==@"h") {
133+
fileTxt=[fileTxt stringByReplacingOccurrencesOfString:@"{SHA}" withString:@"HEAD"];
134+
}else {
135+
fileTxt=[fileTxt stringByReplacingOccurrencesOfString:@"{SHA}" withString:@"--"];
136+
}
137+
[script callWebScriptMethod:@"showFile" withArguments:[NSArray arrayWithObjects:fileTxt, filePath, nil]];
138+
}else{
139+
[script callWebScriptMethod:@"setMessage" withArguments:[NSArray arrayWithObjects:[theError localizedDescription], nil]];
140+
}
141+
[self updateSearch:searchField];
142+
}
138143
}
139144

140-
[self updateSearch:searchField];
141145

142146
#ifdef DEBUG_BUILD
143147
DOMHTMLElement *dom=(DOMHTMLElement *)[[[view mainFrame] DOMDocument] documentElement];
@@ -338,10 +342,10 @@ + (NSString *)parseBinaryDiff:(NSString *)txt
338342
NSMutableString *res=[NSMutableString string];
339343
NSScanner *scan=[NSScanner scannerWithString:txt];
340344
NSString *block;
341-
345+
342346
[scan scanUpToString:@"Binary files" intoString:NULL];
343347
[scan scanUpToString:@"" intoString:&block];
344-
348+
345349
NSArray *files=[self getFilesNames:block];
346350
[res appendString:@"<tr class='images'><td>"];
347351
[res appendString:[NSString stringWithFormat:@"%@<br/>",[files objectAtIndex:0]]];
@@ -358,7 +362,7 @@ + (NSString *)parseBinaryDiff:(NSString *)txt
358362
}
359363
}
360364
[res appendString:@"</td></tr>"];
361-
365+
362366
return res;
363367
}
364368

@@ -383,7 +387,7 @@ + (NSString *)parseDiffChunk:(NSString *)txt
383387

384388
l_line=abs([[pos_l objectAtIndex:0]integerValue]);
385389
r_line=[[pos_r objectAtIndex:0]integerValue];
386-
390+
387391
[res appendString:[NSString stringWithFormat:@"<tr class='header'><td colspan='3'>%@</td></tr>",line]];
388392
while((line=[lines nextObject])){
389393
NSString *s=[line substringToIndex:1];

PBGitTree.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,9 @@ - (void) finalize
376376
[[NSFileManager defaultManager] removeItemAtPath:localFileName error:nil];
377377
[super finalize];
378378
}
379+
380+
- (BOOL)isEqualTo:(PBGitTree *)object
381+
{
382+
return [sha isEqualTo:[object sha]] && [[self fullPath] isEqualTo:[object fullPath]];
383+
}
379384
@end

0 commit comments

Comments
 (0)