Skip to content

Commit c221c64

Browse files
committed
Merge branch 'branch-status'
2 parents 9057911 + 5c9d716 commit c221c64

11 files changed

+86
-48
lines changed

PBGitRepository.m

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

272-
NSString *bName;
273-
if([PBGitRepository isLocalBranch:[components objectAtIndex:0] branchNameInto:&bName]){
274-
[revSpec setAhead:[self countCommintsOf:[NSString stringWithFormat:@"origin/%@..%@",bName,bName]]];
275-
[revSpec setBehind:[self countCommintsOf:[NSString stringWithFormat:@"%@..origin/%@",bName,bName]]];
276-
}
277272
[self addBranch:revSpec];
278273
[self addRef:newRef fromParameters:components];
279274
[oldBranches removeObject:revSpec];
@@ -299,19 +294,6 @@ +(bool)isLocalBranch:(NSString *)branch branchNameInto:(NSString **)name
299294
return is;
300295
}
301296

302-
-(NSNumber *)countCommintsOf:(NSString *)branchs
303-
{
304-
NSLog(@"branchs:'%@'",branchs);
305-
NSArray *args = [NSArray arrayWithObjects:@"rev-list", branchs, nil];
306-
int ret;
307-
NSString *o = [self outputForArguments:args retValue:&ret];
308-
if ((ret!=0) || ([o length]==0)) {
309-
return NULL;
310-
}
311-
NSArray *commits = [o componentsSeparatedByString:@"\n"];
312-
return [NSNumber numberWithInt:[commits count]];
313-
}
314-
315297
- (void) lazyReload
316298
{
317299
if (!hasChanged)

PBGitSVBranchItem.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@
1111

1212

1313
@interface PBGitSVBranchItem : PBSourceViewItem {
14-
14+
BOOL isCheckedOut;
15+
NSNumber *behind;
16+
NSNumber *ahead;
1517
}
1618

1719
+ (id)branchItemWithRevSpec:(PBGitRevSpecifier *)revSpecifier;
1820

21+
@property (assign) BOOL isCheckedOut;
22+
@property (assign) NSNumber *behind;
23+
@property (assign) NSNumber *ahead;
24+
1925
@end

PBGitSVBranchItem.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
@implementation PBGitSVBranchItem
1313

14+
@synthesize isCheckedOut;
15+
@synthesize behind,ahead;
1416

1517
+ (id)branchItemWithRevSpec:(PBGitRevSpecifier *)revSpecifier
1618
{
@@ -30,4 +32,17 @@ - (NSImage *) icon
3032
return branchImage;
3133
}
3234

35+
36+
- (NSString *) badge{
37+
NSMutableString *badge=nil;
38+
if(isCheckedOut || ahead || behind){
39+
badge=[NSMutableString string];
40+
if(isCheckedOut) [badge appendString:@""];
41+
if(ahead) [badge appendFormat:@"+%@",ahead];
42+
if(behind) [badge appendFormat:@"-%@",behind];
43+
}
44+
return badge;
45+
}
46+
47+
3348
@end

PBGitSVRemoteItem.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212

1313
@interface PBGitSVRemoteItem : PBSourceViewItem {
14-
14+
BOOL alert;
1515
}
1616

17+
@property (assign) BOOL alert;
18+
1719
+ (id)remoteItemWithTitle:(NSString *)title;
1820

1921
@end

PBGitSVRemoteItem.m

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

1313
@implementation PBGitSVRemoteItem
1414

15+
@synthesize alert;
1516

1617
+ (id)remoteItemWithTitle:(NSString *)title
1718
{
@@ -38,4 +39,8 @@ - (PBGitRef *) ref
3839
return [PBGitRef refFromString:[kGitXRemoteRefPrefix stringByAppendingString:self.title]];
3940
}
4041

42+
- (NSString *)badge
43+
{
44+
return (alert ? @"!" : nil);
45+
}
4146
@end

PBGitSidebarController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040

4141
- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode;
4242

43+
-(NSNumber *)countCommintsOf:(NSString *)range;
44+
-(bool)remoteNeedFetch:(NSString *)remote;
45+
4346
@property(readonly) NSMutableArray *items;
4447
@property(readonly) NSView *sourceListControlsView;
4548
@property(readonly) PBGitHistoryController *historyViewController;

PBGitSidebarController.m

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ - (void)awakeFromNib
5151
historyViewController = [[PBGitHistoryController alloc] initWithRepository:repository superController:superController];
5252
commitViewController = [[PBGitCommitController alloc] initWithRepository:repository superController:superController];
5353

54+
[repository addObserver:self forKeyPath:@"refs" options:0 context:@"updateRefs"];
5455
[repository addObserver:self forKeyPath:@"currentBranch" options:0 context:@"currentBranchChange"];
5556
[repository addObserver:self forKeyPath:@"branches" options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew) context:@"branchesModified"];
5657

@@ -79,9 +80,7 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(
7980
[sourceView reloadData];
8081
[self selectCurrentBranch];
8182
return;
82-
}
83-
84-
if ([@"branchesModified" isEqualToString:context]) {
83+
}else if ([@"branchesModified" isEqualToString:context]) {
8584
NSInteger changeKind = [(NSNumber *)[change objectForKey:NSKeyValueChangeKindKey] intValue];
8685

8786
if (changeKind == NSKeyValueChangeInsertion) {
@@ -97,12 +96,49 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(
9796
for (PBGitRevSpecifier *rev in removedRevSpecs)
9897
[self removeRevSpec:rev];
9998
}
100-
return;
99+
}else if ([@"updateRefs" isEqualToString:context]) {
100+
for(PBGitSVRemoteItem* remote in [remotes children]){
101+
NSLog(@"remote.title=%@",[remote title]);
102+
[remote setAlert:[self remoteNeedFetch:[remote title]]];
103+
}
104+
105+
for(PBGitSVBranchItem* branch in [branches children]){
106+
NSString *bName=[branch title];
107+
[branch setAhead:[self countCommintsOf:[NSString stringWithFormat:@"origin/%@..%@",bName,bName]]];
108+
[branch setBehind:[self countCommintsOf:[NSString stringWithFormat:@"%@..origin/%@",bName,bName]]];
109+
[branch setIsCheckedOut:[branch.revSpecifier isEqual:[repository headRef]]];
110+
}
111+
112+
}else{
113+
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
101114
}
115+
}
102116

103-
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
117+
#pragma mark Badges Methods
118+
119+
-(NSNumber *)countCommintsOf:(NSString *)range
120+
{
121+
NSArray *args = [NSArray arrayWithObjects:@"rev-list", range, nil];
122+
int ret;
123+
NSString *o = [repository outputForArguments:args retValue:&ret];
124+
if ((ret!=0) || ([o length]==0)) {
125+
return NULL;
126+
}
127+
NSArray *commits = [o componentsSeparatedByString:@"\n"];
128+
return [NSNumber numberWithInt:[commits count]];
129+
}
130+
131+
132+
-(bool)remoteNeedFetch:(NSString *)remote
133+
{
134+
int ret;
135+
NSArray *args = [NSArray arrayWithObjects:@"fetch", @"--dry-run", remote, nil];
136+
NSString *o = [repository outputForArguments:args retValue:&ret];
137+
return ((ret==0) && ([o length]!=0));
104138
}
105139

140+
#pragma mark -----
141+
106142
- (PBSourceViewItem *) selectedItem
107143
{
108144
NSInteger index = [sourceView selectedRow];
@@ -223,14 +259,7 @@ - (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
223259

224260
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(PBSourceViewCell *)cell forTableColumn:(NSTableColumn *)tableColumn item:(PBSourceViewItem *)item
225261
{
226-
cell.isCheckedOut = [item.revSpecifier isEqual:[repository headRef]];
227-
if(item.revSpecifier!=NULL){
228-
cell.behind=[item.revSpecifier behind];
229-
cell.ahead=[item.revSpecifier ahead];
230-
}else{
231-
cell.behind=nil;
232-
cell.ahead=nil;
233-
}
262+
[cell setBadge:[item badge]];
234263
[cell setImage:[item icon]];
235264
}
236265

PBSourceViewCell.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,10 @@
99
#import <Cocoa/Cocoa.h>
1010
#import "PBIconAndTextCell.h"
1111

12-
1312
@interface PBSourceViewCell : PBIconAndTextCell {
14-
BOOL isCheckedOut;
15-
NSNumber *behind;
16-
NSNumber *ahead;
13+
NSString *badge;
1714
}
1815

19-
@property (assign) BOOL isCheckedOut;
20-
@property (assign) NSNumber *behind;
21-
@property (assign) NSNumber *ahead;
22-
16+
@property (assign) NSString *badge;
2317

2418
@end

PBSourceViewCell.m

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515

1616
@implementation PBSourceViewCell
1717

18-
@synthesize isCheckedOut;
19-
@synthesize behind,ahead;
18+
@synthesize badge;
2019

2120
# pragma mark context menu delegate methods
2221

@@ -35,11 +34,7 @@ - (NSMenu *) menuForEvent:(NSEvent *)event inRect:(NSRect)rect ofView:(NSOutline
3534

3635
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)outlineView
3736
{
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];
37+
if(badge){
4338
NSImage *checkedOutImage = [PBSourceViewBadge badge:badge forCell:self];
4439
NSSize imageSize = [checkedOutImage size];
4540
NSRect imageFrame;

PBSourceViewItem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
+ (id)itemWithRevSpec:(PBGitRevSpecifier *)revSpecifier;
2727
+ (id)itemWithTitle:(NSString *)title;
2828

29+
- (NSString *)badge;
30+
2931
- (void)addChild:(PBSourceViewItem *)child;
3032
- (void)removeChild:(PBSourceViewItem *)child;
3133

0 commit comments

Comments
 (0)