diff --git a/PBGitSidebarController.m b/PBGitSidebarController.m index e8ca450..5bb4854 100644 --- a/PBGitSidebarController.m +++ b/PBGitSidebarController.m @@ -78,14 +78,17 @@ for (PBGitRevSpecifier *rev in repository.branches) { - if (![rev isSimpleRef]) + if (![rev isSimpleRef]) { [custom addChild:[PBSourceViewItem itemWithRevSpec:rev]]; - else if ([[rev simpleRef] hasPrefix:@"refs/heads/"]) - [branches addChild:[PBSourceViewItem itemWithRevSpec:rev]]; + continue; + } + NSArray *pathComponents = [[rev simpleRef] componentsSeparatedByString:@"/"]; + if ([[pathComponents objectAtIndex:1] isEqualToString:@"heads"]) + [branches addRev:rev toPath:[pathComponents subarrayWithRange:NSMakeRange(2, [pathComponents count] - 2)]]; else if ([[rev simpleRef] hasPrefix:@"refs/tags/"]) - [tags addChild:[PBSourceViewItem itemWithRevSpec:rev]]; + [tags addRev:rev toPath:[pathComponents subarrayWithRange:NSMakeRange(2, [pathComponents count] - 2)]]; else if ([[rev simpleRef] hasPrefix:@"refs/remotes/"]) - [remotes addChild:[PBSourceViewItem itemWithRevSpec:rev]]; + [remotes addRev:rev toPath:[pathComponents subarrayWithRange:NSMakeRange(2, [pathComponents count] - 2)]]; } diff --git a/PBSourceViewItem.h b/PBSourceViewItem.h index 5825bc8..c6d5f4e 100644 --- a/PBSourceViewItem.h +++ b/PBSourceViewItem.h @@ -21,9 +21,15 @@ + (PBSourceViewItem *)groupItemWithTitle:(NSString *)title; + (PBSourceViewItem *)itemWithRevSpec:(PBGitRevSpecifier *)revSpecifier; ++ (PBSourceViewItem *)itemWithTitle:(NSString *)title; - (void)addChild:(PBSourceViewItem *)child; +// This adds the ref to the path, which should match the item's title, +// so "refs/heads/pu/pb/sidebar" would have the path [@"pu", @"pb", @"sidebare"] +// to the 'local' branch thing +- (void)addRev:(PBGitRevSpecifier *)revSpecifier toPath:(NSArray *)path; + @property(retain) NSString *title; @property(readonly) NSMutableArray *children; @property(assign) BOOL isGroupItem; diff --git a/PBSourceViewItem.m b/PBSourceViewItem.m index dfbd7de..cd11084 100644 --- a/PBSourceViewItem.m +++ b/PBSourceViewItem.m @@ -37,17 +37,46 @@ return item; } ++ (PBSourceViewItem *)itemWithTitle:(NSString *)title; +{ + PBSourceViewItem *item = [[PBSourceViewItem alloc] init]; + item.title = title; + return item; +} + - (void)addChild:(PBSourceViewItem *)child { [self.children addObject:child]; } +- (void)addRev:(PBGitRevSpecifier *)theRevSpecifier toPath:(NSArray *)path +{ + if ([path count] == 1) { + PBSourceViewItem *item = [PBSourceViewItem itemWithRevSpec:theRevSpecifier]; + [self addChild:item]; + return; + } + + NSString *firstTitle = [path objectAtIndex:0]; + PBSourceViewItem *node = nil; + for (PBSourceViewItem *child in [self children]) + if ([child.title isEqualToString:firstTitle]) + node = child; + + if (!node) { + node = [PBSourceViewItem itemWithTitle:firstTitle]; + [self addChild:node]; + } + + [node addRev:theRevSpecifier toPath:[path subarrayWithRange:NSMakeRange(1, [path count] - 1)]]; +} + - (NSString *)title { if (title) return title; - return [revSpecifier description]; + return [[revSpecifier description] lastPathComponent]; } @end