diff --git a/PBGitRepository.h b/PBGitRepository.h index 9d743d9..ccbc1cd 100644 --- a/PBGitRepository.h +++ b/PBGitRepository.h @@ -19,6 +19,8 @@ extern NSString* PBGitRepositoryErrorDomain; NSMutableArray* branches; NSIndexSet* currentBranch; NSMutableDictionary* refs; + + PBGitRevSpecifier *_headRef; // Caching } - (NSFileHandle*) handleForCommand:(NSString*) cmd; diff --git a/PBGitRepository.m b/PBGitRepository.m index 5ccb5e4..4611008 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -188,6 +188,7 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain"; // returns YES when a ref was changed - (BOOL) reloadRefs { + _headRef = nil; BOOL ret = NO; refs = [NSMutableDictionary dictionary]; @@ -233,13 +234,18 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain"; hasChanged = NO; } -- (PBGitRevSpecifier*) headRef +- (PBGitRevSpecifier *)headRef { + if (_headRef) + return _headRef; + NSString* branch = [self parseSymbolicReference: @"HEAD"]; if (branch && [branch hasPrefix:@"refs/heads/"]) - return [[PBGitRevSpecifier alloc] initWithRef:[PBGitRef refFromString:branch]]; + _headRef = [[PBGitRevSpecifier alloc] initWithRef:[PBGitRef refFromString:branch]]; + else + _headRef = [[PBGitRevSpecifier alloc] initWithRef:[PBGitRef refFromString:@"HEAD"]]; - return [[PBGitRevSpecifier alloc] initWithRef:[PBGitRef refFromString:@"HEAD"]]; + return _headRef; } // Returns either this object, or an existing, equal object