Read branches in a repository

This adds a -readBranches function which allows you to read in all
branches in our repository. It is used in the branch display popup box.
This commit is contained in:
Pieter de Bie
2008-08-18 22:03:41 +02:00
parent 6d500bc310
commit f786fe2b0b
3 changed files with 933 additions and 885 deletions
File diff suppressed because it is too large Load Diff
+5
View File
@@ -13,6 +13,7 @@ extern NSString* PBGitRepositoryErrorDomain;
@interface PBGitRepository : NSDocument {
PBGitRevList* revisionList;
NSArray* branches;
}
+ (PBGitRepository*) repositoryWithPath:(NSString*) path;
@@ -21,6 +22,10 @@ extern NSString* PBGitRepositoryErrorDomain;
- (NSFileHandle*) handleForCommand:(NSString*) cmd;
- (NSFileHandle*) handleForArguments:(NSArray*) args;
- (void) readBranches;
+ (NSURL*)gitDirForURL:(NSURL*)repositoryURL;
@property (readonly) PBGitRevList* revisionList;
@property (assign) NSArray* branches;
@end
+18 -1
View File
@@ -17,7 +17,7 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
@implementation PBGitRepository
@synthesize revisionList;
@synthesize revisionList, branches;
static NSString* gitPath;
+ (void) initialize
@@ -143,9 +143,26 @@ static NSString* gitPath;
NSLog(@"Git path is: %@", self.fileURL);
revisionList = [[PBGitRevList alloc] initWithRepository:self andRevListParameters:[NSArray array]];
[self readBranches];
return self;
}
- (void) readBranches
{
NSString* output = [PBEasyPipe outputForCommand:gitPath withArgs:[NSArray arrayWithObjects:@"for-each-ref", @"refs/heads", nil] inDir: self.fileURL.path];
NSArray* lines = [output componentsSeparatedByString:@"\n"];
NSMutableArray* newBranches = [NSMutableArray array];
for (NSString* line in lines) {
NSString* substr = [line substringWithRange: NSMakeRange(40,19)];
if (![substr isEqualToString:@" commit\trefs/heads/"]) {
NSLog(@"Cannot parse branch %@. (%@)", line, substr);
continue;
}
NSString* branch = [line substringFromIndex:59];
[newBranches addObject: branch];
}
self.branches = newBranches;
}
- (NSFileHandle*) handleForArguments:(NSArray *)args
{