From dea6a77d02725a214eca41492293782a507ff67d Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Fri, 12 Sep 2008 17:55:45 +0200 Subject: [PATCH] Add branch control to the PBGitRepository This allows you to add and select specific branches --- PBGitRepository.h | 7 +++++-- PBGitRepository.m | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/PBGitRepository.h b/PBGitRepository.h index 63c4972..021378d 100644 --- a/PBGitRepository.h +++ b/PBGitRepository.h @@ -8,12 +8,13 @@ #import #import "PBGitRevList.h" +#import "PBGitRevSpecifier.h" extern NSString* PBGitRepositoryErrorDomain; @interface PBGitRepository : NSDocument { PBGitRevList* revisionList; - NSArray* branches; + NSMutableArray* branches; NSIndexSet* currentBranch; NSDictionary* refs; } @@ -25,6 +26,8 @@ extern NSString* PBGitRepositoryErrorDomain; - (void) readRefs; - (void) readCurrentBranch; +- (void) addBranch: (PBGitRevSpecifier*) rev; +- (void) selectBranch: (PBGitRevSpecifier*) rev; - (NSString*) parseSymbolicReference:(NSString*) ref; - (NSString*) parseReference:(NSString*) ref; @@ -35,7 +38,7 @@ extern NSString* PBGitRepositoryErrorDomain; - (id) initWithURL: (NSURL*) path andArguments:(NSArray*) array; @property (retain) PBGitRevList* revisionList; -@property (assign) NSArray* branches; +@property (assign) NSMutableArray* branches; @property (assign) NSIndexSet* currentBranch; @property (assign) NSDictionary* refs; @end diff --git a/PBGitRepository.m b/PBGitRepository.m index e23f0a4..6a15b55 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -183,6 +183,23 @@ static NSString* gitPath; self.refs = newRefs; } +- (void) addBranch: (PBGitRevSpecifier*) rev +{ + [branches addObject: rev]; +} + +- (void) selectBranch: (PBGitRevSpecifier*) rev +{ + int i; + for (i = 0; i < [branches count]; i++) { + PBGitRevSpecifier* aRev = [branches objectAtIndex:i]; + if (rev == aRev) { + self.currentBranch = [NSIndexSet indexSetWithIndex:i]; + return; + } + } +} + - (void) readCurrentBranch { NSString* branch = [self parseSymbolicReference: @"HEAD"];