mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
9be3c50a75
This displays the tree of a specific commit in an NSBrowser.
90 lines
1.7 KiB
Objective-C
90 lines
1.7 KiB
Objective-C
//
|
|
// PBGitTree.m
|
|
// GitTest
|
|
//
|
|
// Created by Pieter de Bie on 15-06-08.
|
|
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
|
//
|
|
|
|
#import "PBGitTree.h"
|
|
#import "PBGitCommit.h"
|
|
#import "NSFileHandleExt.h"
|
|
|
|
@implementation PBGitTree
|
|
|
|
@synthesize sha, path, repository, leaf, parent;
|
|
|
|
+ (PBGitTree*) rootForCommit:(id) commit
|
|
{
|
|
NSLog(@"Making root");
|
|
PBGitCommit* c = commit;
|
|
PBGitTree* tree = [[self alloc] init];
|
|
tree.parent = nil;
|
|
tree.leaf = NO;
|
|
tree.sha = c.sha;
|
|
tree.repository = c.repository;
|
|
tree.path = @"";
|
|
return tree;
|
|
}
|
|
|
|
+ (PBGitTree*) treeForTree: (PBGitTree*) prev andPath: (NSString*) path;
|
|
{
|
|
PBGitTree* tree = [[self alloc] init];
|
|
tree.parent = prev;
|
|
tree.sha = prev.sha;
|
|
tree.repository = prev.repository;
|
|
tree.path = path;
|
|
return tree;
|
|
}
|
|
|
|
- init
|
|
{
|
|
children = nil;
|
|
leaf = YES;
|
|
return self;
|
|
}
|
|
|
|
- (NSArray*) children
|
|
{
|
|
if (children)
|
|
return children;
|
|
|
|
NSString* ref = [NSString stringWithFormat:@"%@:%@", self.sha, self.fullPath];
|
|
NSLog(@"Starting get for %@", ref);
|
|
|
|
NSFileHandle* handle = [repository handleForArguments:[NSArray arrayWithObjects:@"show", ref, nil]];
|
|
[handle readLine];
|
|
[handle readLine];
|
|
|
|
NSMutableArray* c = [NSMutableArray array];
|
|
|
|
NSString* p = [handle readLine];
|
|
while (p.length > 0) {
|
|
NSLog(@"Read line: %@", p);
|
|
BOOL isLeaf = ([p characterAtIndex:p.length - 1] != '/');
|
|
if (!isLeaf)
|
|
p = [p substringToIndex:p.length -1];
|
|
|
|
PBGitTree* child = [PBGitTree treeForTree:self andPath:p];
|
|
child.leaf = isLeaf;
|
|
[c addObject: child];
|
|
|
|
p = [handle readLine];
|
|
}
|
|
children = c;
|
|
return c;
|
|
}
|
|
|
|
- (NSString*) fullPath
|
|
{
|
|
if (!parent)
|
|
return @"";
|
|
|
|
if ([parent.fullPath isEqualToString:@""])
|
|
return self.path;
|
|
|
|
return [parent.fullPath stringByAppendingPathComponent: self.path];
|
|
}
|
|
|
|
@end
|