Branch commit ahead/behind values

This commit is contained in:
German Laullon
2011-01-04 23:59:32 -08:00
parent 63289230e1
commit 0bd684791d
8 changed files with 43 additions and 5 deletions
+3
View File
@@ -128,6 +128,9 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
// for the scripting bridge
- (void)findInModeScriptCommand:(NSScriptCommand *)command;
-(NSNumber *)countCommintsOf:(NSString *)branchs;
+(bool)isLocalBranch:(NSString *)name;
@property (assign) BOOL hasChanged;
@property (readonly) PBGitWindowController *windowController;
+21
View File
@@ -269,6 +269,10 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
PBGitRef *newRef = [PBGitRef refFromString:[components objectAtIndex:0]];
PBGitRevSpecifier *revSpec = [[PBGitRevSpecifier alloc] initWithRef:newRef];
if([PBGitRepository isLocalBranch:[components objectAtIndex:0]]){
[revSpec setAhead:[self countCommintsOf:[NSString stringWithFormat:@"origin..%@",[components objectAtIndex:0]]]];
[revSpec setBehind:[self countCommintsOf:[NSString stringWithFormat:@"%@..origin",[components objectAtIndex:0]]]];
}
[self addBranch:revSpec];
[self addRef:newRef fromParameters:components];
[oldBranches removeObject:revSpec];
@@ -284,6 +288,23 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
[[[self windowController] window] setTitle:[self displayName]];
}
+(bool)isLocalBranch:(NSString *)name
{
NSScanner *scanner=[NSScanner scannerWithString:name];
return [scanner scanString:@"refs/heads/" intoString:NULL];
}
-(NSNumber *)countCommintsOf:(NSString *)branchs
{
NSArray *args = [NSArray arrayWithObjects:@"rev-list", branchs, nil];
NSString *o = [self outputForArguments:args];
if ([o length]==0) {
return NULL;
}
NSArray *commits = [o componentsSeparatedByString:@"\n"];
return [NSNumber numberWithInt:[commits count]];
}
- (void) lazyReload
{
if (!hasChanged)
+4
View File
@@ -14,6 +14,8 @@
NSArray *parameters;
NSURL *workingDirectory;
BOOL isSimpleRef;
NSNumber *behind;
NSNumber *ahead;
}
- (id) initWithParameters:(NSArray *)params description:(NSString *)descrip;
@@ -37,5 +39,7 @@
@property(readonly) NSArray *parameters;
@property(retain) NSURL *workingDirectory;
@property(readonly) BOOL isSimpleRef;
@property(assign) NSNumber *behind;
@property(assign) NSNumber *ahead;
@end
+1
View File
@@ -13,6 +13,7 @@
@synthesize parameters, description, workingDirectory;
@synthesize isSimpleRef;
@synthesize behind,ahead;
// internal designated init
+3 -2
View File
@@ -223,12 +223,13 @@
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(PBSourceViewCell *)cell forTableColumn:(NSTableColumn *)tableColumn item:(PBSourceViewItem *)item
{
NSLog(@"%@ -- %d",item.revSpecifier,(item.revSpecifier!=NULL));
if(item.revSpecifier!=NULL){
cell.isCheckedOut = [item.revSpecifier isEqual:[repository headRef]];
cell.behind=[NSNumber numberWithInt:10];
cell.behind=[item.revSpecifier behind];
cell.ahead=[item.revSpecifier ahead];
}else{
cell.behind=nil;
cell.ahead=nil;
}
[cell setImage:[item icon]];
}
+1
View File
@@ -13,6 +13,7 @@
}
+ (NSImage *) badge:(NSString *)badge forCell:(NSTextFieldCell *)cell;
+ (NSImage *) checkedOutBadgeForCell:(NSTextFieldCell *)cell;
+ (NSImage *) numericBadge:(NSInteger)number forCell:(NSTextFieldCell *)cell;
+3
View File
@@ -13,9 +13,12 @@
@interface PBSourceViewCell : PBIconAndTextCell {
BOOL isCheckedOut;
NSNumber *behind;
NSNumber *ahead;
}
@property (assign) BOOL isCheckedOut;
@property (assign) NSNumber *behind;
@property (assign) NSNumber *ahead;
@end
+7 -3
View File
@@ -16,7 +16,7 @@
@implementation PBSourceViewCell
@synthesize isCheckedOut;
@synthesize behind;
@synthesize behind,ahead;
# pragma mark context menu delegate methods
@@ -35,8 +35,12 @@
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)outlineView
{
if(behind){
NSImage *checkedOutImage = [PBSourceViewBadge badge:[NSString stringWithFormat:@"%@-%@",(isCheckedOut?@"":@""),behind] forCell:self];
if(behind || ahead || isCheckedOut){
NSMutableString *badge=[NSMutableString string];
if(isCheckedOut) [badge appendString:@""];
if(ahead) [badge appendFormat:@"+%@",ahead];
if(behind) [badge appendFormat:@"-%@",behind];
NSImage *checkedOutImage = [PBSourceViewBadge badge:badge forCell:self];
NSSize imageSize = [checkedOutImage size];
NSRect imageFrame;
NSDivideRect(cellFrame, &imageFrame, &cellFrame, imageSize.width + 3, NSMaxXEdge);