Skip to content

Commit 81d7e78

Browse files
committed
Select the commit as soon as it is available when updating the commit list
This is important for large repositories as the commit will be selected when it is added instead of waiting for all the commits to be loaded. Stop attempts to select the current commit again if it's already selected. No longer need the updatedGraph property on the history list.
1 parent 69827e9 commit 81d7e78

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

PBGitHistoryController.m

+28-18
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ - (void)awakeFromNib
4848
[treeController addObserver:self forKeyPath:@"selection" options:0 context:@"treeChange"];
4949

5050
[repository.revisionList addObserver:self forKeyPath:@"isUpdating" options:0 context:@"revisionListUpdating"];
51-
[repository.revisionList addObserver:self forKeyPath:@"updatedGraph" options:0 context:@"revisionListUpdatedGraph"];
5251
[repository addObserver:self forKeyPath:@"currentBranch" options:0 context:@"branchChange"];
5352
[repository addObserver:self forKeyPath:@"refs" options:0 context:@"updateRefs"];
5453

@@ -83,26 +82,34 @@ - (void)awakeFromNib
8382
[super awakeFromNib];
8483
}
8584

86-
- (void) updateKeys
85+
- (void)updateKeys
8786
{
88-
// Remove any references in the QLPanel
89-
//[[QLPreviewPanel sharedPreviewPanel] setURLs:[NSArray array] currentIndex:0 preservingDisplayState:YES];
90-
// We have to do this manually, as NSTreeController leaks memory?
91-
//[treeController setSelectionIndexPaths:[NSArray array]];
87+
PBGitCommit *lastObject = [[commitController selectedObjects] lastObject];
88+
if (lastObject) {
89+
if (![selectedCommit isEqual:lastObject]) {
90+
selectedCommit = lastObject;
9291

93-
selectedCommit = [[commitController selectedObjects] lastObject];
92+
BOOL isOnHeadBranch = [selectedCommit isOnHeadBranch];
93+
[mergeButton setEnabled:!isOnHeadBranch];
94+
[cherryPickButton setEnabled:!isOnHeadBranch];
95+
[rebaseButton setEnabled:!isOnHeadBranch];
96+
}
97+
}
98+
else {
99+
[mergeButton setEnabled:NO];
100+
[cherryPickButton setEnabled:NO];
101+
[rebaseButton setEnabled:NO];
102+
}
94103

95104
if (self.selectedCommitDetailsIndex == kHistoryTreeViewIndex) {
96105
self.gitTree = selectedCommit.tree;
97106
[self restoreFileBrowserSelection];
98107
}
99-
else // kHistoryDetailViewIndex
108+
else {
109+
// kHistoryDetailViewIndex
110+
if (![self.webCommit isEqual:selectedCommit])
100111
self.webCommit = selectedCommit;
101-
102-
BOOL isOnHeadBranch = [selectedCommit isOnHeadBranch];
103-
[mergeButton setEnabled:!isOnHeadBranch];
104-
[cherryPickButton setEnabled:!isOnHeadBranch];
105-
[rebaseButton setEnabled:!isOnHeadBranch];
112+
}
106113
}
107114

108115
- (void) updateBranchFilterMatrix
@@ -141,6 +148,11 @@ - (PBGitCommit *) firstCommit
141148
return nil;
142149
}
143150

151+
- (BOOL)isCommitSelected
152+
{
153+
return [selectedCommit isEqual:[[commitController selectedObjects] lastObject]];
154+
}
155+
144156
- (void) setSelectedCommitDetailsIndex:(int)detailsIndex
145157
{
146158
if (selectedCommitDetailsIndex == detailsIndex)
@@ -230,10 +242,7 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(
230242

231243
if([(NSString *)context isEqualToString:@"updateCommitCount"] || [(NSString *)context isEqualToString:@"revisionListUpdating"]) {
232244
[self updateStatus];
233-
return;
234-
}
235245

236-
if([(NSString *)context isEqualToString:@"revisionListUpdatedGraph"]) {
237246
if ([repository.currentBranch isSimpleRef])
238247
[self selectCommit:[repository shaForRef:[repository.currentBranch ref]]];
239248
else
@@ -399,7 +408,7 @@ - (NSArray *) selectedObjectsForSHA:(PBGitSHA *)commitSHA
399408

400409
- (void)selectCommit:(PBGitSHA *)commitSHA
401410
{
402-
if (!forceSelectionUpdate && [[selectedCommit sha] isEqual:commitSHA])
411+
if (!forceSelectionUpdate && [[[[commitController selectedObjects] lastObject] sha] isEqual:commitSHA])
403412
return;
404413

405414
NSInteger oldIndex = [[commitController selectionIndexes] firstIndex];
@@ -409,6 +418,8 @@ - (void)selectCommit:(PBGitSHA *)commitSHA
409418

410419
if (repository.currentBranchFilter != kGitXSelectedBranchFilter)
411420
[self scrollSelectionToTopOfViewFrom:oldIndex];
421+
422+
forceSelectionUpdate = NO;
412423
}
413424

414425
- (BOOL) hasNonlinearPath
@@ -428,7 +439,6 @@ - (void)closeView
428439
[treeController removeObserver:self forKeyPath:@"selection"];
429440

430441
[repository.revisionList removeObserver:self forKeyPath:@"isUpdating"];
431-
[repository.revisionList removeObserver:self forKeyPath:@"updatedGraph"];
432442
[repository removeObserver:self forKeyPath:@"currentBranch"];
433443
[repository removeObserver:self forKeyPath:@"refs"];
434444
}

PBGitHistoryList.h

-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
PBGitRef *lastRemoteRef;
2929
BOOL resetCommits;
3030
BOOL shouldReloadProjectHistory;
31-
NSDate *updatedGraph;
3231

3332
PBGitHistoryGrapher *grapher;
3433
NSOperationQueue *graphQueue;
@@ -49,6 +48,5 @@
4948
@property (retain) NSMutableArray *commits;
5049
@property (readonly) NSArray *projectCommits;
5150
@property (assign) BOOL isUpdating;
52-
@property (retain) NSDate *updatedGraph;
5351

5452
@end

PBGitHistoryList.m

-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ @implementation PBGitHistoryList
3636
@synthesize projectRevList;
3737
@synthesize commits;
3838
@synthesize isUpdating;
39-
@synthesize updatedGraph;
4039
@dynamic projectCommits;
4140

4241

@@ -137,7 +136,6 @@ - (void) finishedGraphing
137136
{
138137
if (!currentRevList.isParsing && ([[graphQueue operations] count] == 0)) {
139138
self.isUpdating = NO;
140-
[self performSelector:@selector(setUpdatedGraph:) withObject:[NSDate date] afterDelay:0];
141139
}
142140
}
143141

@@ -272,7 +270,6 @@ - (BOOL) selectedBranchNeedsNewGraph:(PBGitRevSpecifier *)rev
272270
lastRemoteRef = [[rev ref] remoteRef];
273271
lastSHA = nil;
274272
self.isUpdating = NO;
275-
self.updatedGraph = [NSDate date];
276273
return NO;
277274
}
278275

0 commit comments

Comments
 (0)