Skip to content

Commit b27378f

Browse files
committed
Merge branch 'refs/heads/branch-status'
2 parents 812c2ad + 0bd6847 commit b27378f

8 files changed

+55
-9
lines changed

PBGitRepository.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
128128
// for the scripting bridge
129129
- (void)findInModeScriptCommand:(NSScriptCommand *)command;
130130

131+
-(NSNumber *)countCommintsOf:(NSString *)branchs;
132+
+(bool)isLocalBranch:(NSString *)name;
133+
131134

132135
@property (assign) BOOL hasChanged;
133136
@property (readonly) PBGitWindowController *windowController;

PBGitRepository.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ - (void) reloadRefs
269269
PBGitRef *newRef = [PBGitRef refFromString:[components objectAtIndex:0]];
270270
PBGitRevSpecifier *revSpec = [[PBGitRevSpecifier alloc] initWithRef:newRef];
271271

272+
if([PBGitRepository isLocalBranch:[components objectAtIndex:0]]){
273+
[revSpec setAhead:[self countCommintsOf:[NSString stringWithFormat:@"origin..%@",[components objectAtIndex:0]]]];
274+
[revSpec setBehind:[self countCommintsOf:[NSString stringWithFormat:@"%@..origin",[components objectAtIndex:0]]]];
275+
}
272276
[self addBranch:revSpec];
273277
[self addRef:newRef fromParameters:components];
274278
[oldBranches removeObject:revSpec];
@@ -284,6 +288,23 @@ - (void) reloadRefs
284288
[[[self windowController] window] setTitle:[self displayName]];
285289
}
286290

291+
+(bool)isLocalBranch:(NSString *)name
292+
{
293+
NSScanner *scanner=[NSScanner scannerWithString:name];
294+
return [scanner scanString:@"refs/heads/" intoString:NULL];
295+
}
296+
297+
-(NSNumber *)countCommintsOf:(NSString *)branchs
298+
{
299+
NSArray *args = [NSArray arrayWithObjects:@"rev-list", branchs, nil];
300+
NSString *o = [self outputForArguments:args];
301+
if ([o length]==0) {
302+
return NULL;
303+
}
304+
NSArray *commits = [o componentsSeparatedByString:@"\n"];
305+
return [NSNumber numberWithInt:[commits count]];
306+
}
307+
287308
- (void) lazyReload
288309
{
289310
if (!hasChanged)

PBGitRevSpecifier.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
NSArray *parameters;
1515
NSURL *workingDirectory;
1616
BOOL isSimpleRef;
17+
NSNumber *behind;
18+
NSNumber *ahead;
1719
}
1820

1921
- (id) initWithParameters:(NSArray *)params description:(NSString *)descrip;
@@ -37,5 +39,7 @@
3739
@property(readonly) NSArray *parameters;
3840
@property(retain) NSURL *workingDirectory;
3941
@property(readonly) BOOL isSimpleRef;
42+
@property(assign) NSNumber *behind;
43+
@property(assign) NSNumber *ahead;
4044

4145
@end

PBGitRevSpecifier.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ @implementation PBGitRevSpecifier
1313

1414
@synthesize parameters, description, workingDirectory;
1515
@synthesize isSimpleRef;
16+
@synthesize behind,ahead;
1617

1718

1819
// internal designated init

PBGitSidebarController.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,14 @@ - (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
223223

224224
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(PBSourceViewCell *)cell forTableColumn:(NSTableColumn *)tableColumn item:(PBSourceViewItem *)item
225225
{
226-
cell.isCheckedOut = [item.revSpecifier isEqual:[repository headRef]];
227-
226+
if(item.revSpecifier!=NULL){
227+
cell.isCheckedOut = [item.revSpecifier isEqual:[repository headRef]];
228+
cell.behind=[item.revSpecifier behind];
229+
cell.ahead=[item.revSpecifier ahead];
230+
}else{
231+
cell.behind=nil;
232+
cell.ahead=nil;
233+
}
228234
[cell setImage:[item icon]];
229235
}
230236

PBSourceViewBadge.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
}
1515

16+
+ (NSImage *) badge:(NSString *)badge forCell:(NSTextFieldCell *)cell;
1617
+ (NSImage *) checkedOutBadgeForCell:(NSTextFieldCell *)cell;
1718
+ (NSImage *) numericBadge:(NSInteger)number forCell:(NSTextFieldCell *)cell;
1819

PBSourceViewCell.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@
1212

1313
@interface PBSourceViewCell : PBIconAndTextCell {
1414
BOOL isCheckedOut;
15+
NSNumber *behind;
16+
NSNumber *ahead;
1517
}
1618

1719
@property (assign) BOOL isCheckedOut;
20+
@property (assign) NSNumber *behind;
21+
@property (assign) NSNumber *ahead;
22+
1823

1924
@end

PBSourceViewCell.m

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@
1616
@implementation PBSourceViewCell
1717

1818
@synthesize isCheckedOut;
19+
@synthesize behind,ahead;
1920

2021
# pragma mark context menu delegate methods
2122

2223
- (NSMenu *) menuForEvent:(NSEvent *)event inRect:(NSRect)rect ofView:(NSOutlineView *)view
2324
{
2425
NSPoint point = [view convertPoint:[event locationInWindow] fromView:nil];
2526
NSInteger row = [view rowAtPoint:point];
26-
27+
2728
PBGitSidebarController *controller = [view delegate];
28-
29+
2930
return [controller menuForRow:row];
3031
}
3132

@@ -34,21 +35,25 @@ - (NSMenu *) menuForEvent:(NSEvent *)event inRect:(NSRect)rect ofView:(NSOutline
3435

3536
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)outlineView
3637
{
37-
if (isCheckedOut) {
38-
NSImage *checkedOutImage = [PBSourceViewBadge checkedOutBadgeForCell:self];
38+
if(behind || ahead || isCheckedOut){
39+
NSMutableString *badge=[NSMutableString string];
40+
if(isCheckedOut) [badge appendString:@""];
41+
if(ahead) [badge appendFormat:@"+%@",ahead];
42+
if(behind) [badge appendFormat:@"-%@",behind];
43+
NSImage *checkedOutImage = [PBSourceViewBadge badge:badge forCell:self];
3944
NSSize imageSize = [checkedOutImage size];
4045
NSRect imageFrame;
4146
NSDivideRect(cellFrame, &imageFrame, &cellFrame, imageSize.width + 3, NSMaxXEdge);
4247
imageFrame.size = imageSize;
43-
48+
4449
if ([outlineView isFlipped])
4550
imageFrame.origin.y += floor((cellFrame.size.height + imageFrame.size.height) / 2);
4651
else
4752
imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2);
48-
53+
4954
[checkedOutImage compositeToPoint:imageFrame.origin operation:NSCompositeSourceOver];
5055
}
51-
56+
5257
[super drawWithFrame:cellFrame inView:outlineView];
5358
}
5459

0 commit comments

Comments
 (0)