From 0151598af03e1abc744e1ff1b64925bfd0a03b82 Mon Sep 17 00:00:00 2001 From: German Laullon Date: Fri, 7 Jan 2011 00:37:29 -0800 Subject: [PATCH] (inital) display if remotes need a fetch --- PBGitSVRemoteItem.h | 4 +++- PBGitSVRemoteItem.m | 1 + PBGitSidebarController.h | 2 ++ PBGitSidebarController.m | 26 +++++++++++++++++++++----- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/PBGitSVRemoteItem.h b/PBGitSVRemoteItem.h index a64084c..8f27532 100644 --- a/PBGitSVRemoteItem.h +++ b/PBGitSVRemoteItem.h @@ -11,9 +11,11 @@ @interface PBGitSVRemoteItem : PBSourceViewItem { - + BOOL alert; } +@property (assign) BOOL alert; + + (id)remoteItemWithTitle:(NSString *)title; @end diff --git a/PBGitSVRemoteItem.m b/PBGitSVRemoteItem.m index 4ce251d..cbc4c32 100644 --- a/PBGitSVRemoteItem.m +++ b/PBGitSVRemoteItem.m @@ -12,6 +12,7 @@ @implementation PBGitSVRemoteItem +@synthesize alert; + (id)remoteItemWithTitle:(NSString *)title { diff --git a/PBGitSidebarController.h b/PBGitSidebarController.h index 268ba5c..134c251 100644 --- a/PBGitSidebarController.h +++ b/PBGitSidebarController.h @@ -40,6 +40,8 @@ - (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode; +-(bool)remoteNeedFetch:(NSString *)remote; + @property(readonly) NSMutableArray *items; @property(readonly) NSView *sourceListControlsView; @property(readonly) PBGitHistoryController *historyViewController; diff --git a/PBGitSidebarController.m b/PBGitSidebarController.m index 9f33709..528bafd 100644 --- a/PBGitSidebarController.m +++ b/PBGitSidebarController.m @@ -51,6 +51,7 @@ historyViewController = [[PBGitHistoryController alloc] initWithRepository:repository superController:superController]; commitViewController = [[PBGitCommitController alloc] initWithRepository:repository superController:superController]; + [repository addObserver:self forKeyPath:@"refs" options:0 context:@"updateRefs"]; [repository addObserver:self forKeyPath:@"currentBranch" options:0 context:@"currentBranchChange"]; [repository addObserver:self forKeyPath:@"branches" options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew) context:@"branchesModified"]; @@ -79,9 +80,7 @@ [sourceView reloadData]; [self selectCurrentBranch]; return; - } - - if ([@"branchesModified" isEqualToString:context]) { + }else if ([@"branchesModified" isEqualToString:context]) { NSInteger changeKind = [(NSNumber *)[change objectForKey:NSKeyValueChangeKindKey] intValue]; if (changeKind == NSKeyValueChangeInsertion) { @@ -97,10 +96,22 @@ for (PBGitRevSpecifier *rev in removedRevSpecs) [self removeRevSpec:rev]; } - return; + }else if ([@"updateRefs" isEqualToString:context]) { + for(PBGitSVRemoteItem* remote in [remotes children]){ + NSLog(@"remote.title=%@",[remote title]); + [remote setAlert:[self remoteNeedFetch:[remote title]]]; + } + }else{ + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } +} - [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; +-(bool)remoteNeedFetch:(NSString *)remote +{ + int ret; + NSArray *args = [NSArray arrayWithObjects:@"fetch", @"--dry-run", remote, nil]; + NSString *o = [repository outputForArguments:args retValue:&ret]; + return ((ret==0) && ([o length]!=0)); } - (PBSourceViewItem *) selectedItem @@ -231,6 +242,11 @@ cell.behind=nil; cell.ahead=nil; } + + if([item isKindOfClass:[PBGitSVRemoteItem class]]){ + NSLog(@"title: %@",[item title]); + cell.isCheckedOut=[item alert]; + } [cell setImage:[item icon]]; }