diff --git a/GitTest.xcodeproj/project.pbxproj b/GitTest.xcodeproj/project.pbxproj index db94630..9281838 100644 --- a/GitTest.xcodeproj/project.pbxproj +++ b/GitTest.xcodeproj/project.pbxproj @@ -18,9 +18,7 @@ F56526240E03D85900F03B52 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F56526230E03D85900F03B52 /* WebKit.framework */; }; F565262B0E03D89B00F03B52 /* PBWebGitController.m in Sources */ = {isa = PBXBuildFile; fileRef = F565262A0E03D89B00F03B52 /* PBWebGitController.m */; }; F565265A0E03E71B00F03B52 /* commit.html in Resources */ = {isa = PBXBuildFile; fileRef = F56526590E03E71B00F03B52 /* commit.html */; }; - F57ABDDF0E0441DE00A088B8 /* commit.js in Sources */ = {isa = PBXBuildFile; fileRef = F57ABDDE0E0441DE00A088B8 /* commit.js */; }; F57ABE0B0E0442DD00A088B8 /* commit.js in Resources */ = {isa = PBXBuildFile; fileRef = F57ABDDE0E0441DE00A088B8 /* commit.js */; }; - F57ABE190E04431D00A088B8 /* prototype.js in Sources */ = {isa = PBXBuildFile; fileRef = F57ABE180E04431D00A088B8 /* prototype.js */; }; F57ABE2B0E04435100A088B8 /* prototype.js in Resources */ = {isa = PBXBuildFile; fileRef = F57ABE180E04431D00A088B8 /* prototype.js */; }; F58A8F280E043698007E3FC0 /* commits.css in Resources */ = {isa = PBXBuildFile; fileRef = F58A8F270E043698007E3FC0 /* commits.css */; }; F5945E170E02B0C200706420 /* PBGitRepository.m in Sources */ = {isa = PBXBuildFile; fileRef = F5945E160E02B0C200706420 /* PBGitRepository.m */; }; @@ -48,7 +46,7 @@ F56526290E03D89B00F03B52 /* PBWebGitController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBWebGitController.h; sourceTree = ""; }; F565262A0E03D89B00F03B52 /* PBWebGitController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBWebGitController.m; sourceTree = ""; }; F56526590E03E71B00F03B52 /* commit.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = commit.html; path = html/commit.html; sourceTree = ""; }; - F57ABDDE0E0441DE00A088B8 /* commit.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = commit.js; path = html/commit.js; sourceTree = ""; }; + F57ABDDE0E0441DE00A088B8 /* commit.js */ = {isa = PBXFileReference; explicitFileType = sourcecode.javascript; fileEncoding = 4; name = commit.js; path = html/commit.js; sourceTree = ""; }; F57ABE180E04431D00A088B8 /* prototype.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = prototype.js; path = html/prototype.js; sourceTree = ""; }; F58A8F270E043698007E3FC0 /* commits.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; name = commits.css; path = html/commits.css; sourceTree = ""; }; F5945E150E02B0C200706420 /* PBGitRepository.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRepository.h; sourceTree = ""; }; @@ -239,8 +237,6 @@ F56524BB0E02D22D00F03B52 /* NSFileHandleExt.m in Sources */, F56524F00E02D45200F03B52 /* PBGitCommit.m in Sources */, F565262B0E03D89B00F03B52 /* PBWebGitController.m in Sources */, - F57ABDDF0E0441DE00A088B8 /* commit.js in Sources */, - F57ABE190E04431D00A088B8 /* prototype.js in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/PBGitRepository.h b/PBGitRepository.h index d2a7532..abd4946 100644 --- a/PBGitRepository.h +++ b/PBGitRepository.h @@ -13,9 +13,13 @@ NSArray* commits; } -+ (PBGitRepository*) repositoryWithPath:(NSString*) path; + (void) setGitPath; + ++ (PBGitRepository*) repositoryWithPath:(NSString*) path; +- (PBGitRepository*) initWithPath:(NSString*) path; + - (NSFileHandle*) handleForCommand:(NSString*) cmd; +- (void) initializeCommits; - (void) addCommit: (id)obj; @property (copy) NSString* path; diff --git a/PBGitRepository.m b/PBGitRepository.m index 0f22ec9..f1e0dbd 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -13,16 +13,25 @@ @implementation PBGitRepository +@synthesize commits; static NSString* gitPath = @"/usr/bin/env"; + (PBGitRepository*) repositoryWithPath:(NSString*) path { [self setGitPath]; - PBGitRepository* repo = [[PBGitRepository alloc] init]; - repo.path = path; + PBGitRepository* repo = [[PBGitRepository alloc] initWithPath: path]; return repo; } +- (PBGitRepository*) initWithPath: (NSString*) p +{ + self.path = p; + NSThread * commitThread = [[NSThread alloc] initWithTarget: self selector: @selector(initializeCommits) object:nil]; + [commitThread start]; + return self; +} + + + (void) setGitPath { char* path = getenv("GIT_PATH"); @@ -60,26 +69,33 @@ static NSString* gitPath = @"/usr/bin/env"; commits = obj; } -- (NSArray*) commits +- (void) initializeCommits { - if (commits != nil) - return commits; + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSFileHandle* handle = [self handleForCommand:@"log --pretty=format:%H\01%s\01%an HEAD"]; NSMutableArray * newArray = [NSMutableArray array]; + NSDate* start = [NSDate date]; + NSFileHandle* handle = [self handleForCommand:@"log --pretty=format:%H\01%s\01%an HEAD"]; NSString* currentLine = [handle readLine]; - + int num = 0; while (currentLine.length > 0) { NSArray* components = [currentLine componentsSeparatedByString:@"\01"]; PBGitCommit* newCommit = [[PBGitCommit alloc] initWithRepository: self andSha: [components objectAtIndex:0]]; newCommit.subject = [components objectAtIndex:1]; newCommit.author = [components objectAtIndex:2]; [newArray addObject: newCommit]; + num++; + if (num % 1000 == 0) + [self performSelectorOnMainThread:@selector(setCommits:) withObject:newArray waitUntilDone:NO]; currentLine = [handle readLine]; } - commits = newArray; - return commits; + [self performSelectorOnMainThread:@selector(setCommits:) withObject:newArray waitUntilDone:YES]; + NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:start]; + NSLog(@"Loaded %i commits in %f seconds", num, duration); + + [pool release]; + [NSThread exit]; } - (NSFileHandle*) handleForCommand:(NSString *)cmd diff --git a/PBWebGitController.h b/PBWebGitController.h index 4982ec8..87e7a71 100644 --- a/PBWebGitController.h +++ b/PBWebGitController.h @@ -8,15 +8,17 @@ #import #import "GitTest_AppDelegate.h" +#import "PBGitCommit.h" #import @interface PBWebGitController : NSObject { IBOutlet GitTest_AppDelegate* controller; IBOutlet WebView* view; IBOutlet NSArrayController* commitsController; + NSString* currentSha; NSString* diff; } -- (void) changeContentTo: (id) content; +- (void) changeContentTo: (PBGitCommit *) content; @property (readonly) NSString* diff; @end diff --git a/PBWebGitController.m b/PBWebGitController.m index ea3514a..e0ffcd5 100644 --- a/PBWebGitController.m +++ b/PBWebGitController.m @@ -41,13 +41,13 @@ } } -- (void) changeContentTo: (id) content +- (void) changeContentTo: (PBGitCommit *) content { - NSLog(@"Starting Change"); + if ([currentSha isEqualToString: content.sha]) + return; + currentSha = content.sha; id script = [view windowScriptObject]; [script setValue: content forKey:@"CommitObject"]; - NSLog(@"Done 1"); [script callWebScriptMethod:@"doeHet" withArguments: nil]; - NSLog(@"Change done"); } @end