Skip to content

Commit 832d426

Browse files
authored
Merge pull request laullon#223 from ksuther/misc-cleanup
Fix crash and miscellaneous cleanup
2 parents eece2fc + 22829f4 commit 832d426

9 files changed

+50
-43
lines changed

Classes/Controllers/PBGitCommitController.m

+7-7
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ - (void)awakeFromNib
9898
ascending:true]]];
9999

100100
// listen for updates
101-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_repositoryUpdatedNotification:) name:PBGitRepositoryEventNotification object:repository];
101+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_repositoryUpdatedNotification:) name:PBGitRepositoryEventNotification object:self.repository];
102102

103103
[stagedFilesController setAutomaticallyRearrangesObjects:NO];
104104
[unstagedFilesController setAutomaticallyRearrangesObjects:NO];
@@ -145,12 +145,12 @@ - (NSResponder *)firstResponder;
145145

146146
- (PBGitIndex *)index
147147
{
148-
return repository.index;
148+
return self.repository.index;
149149
}
150150

151151
- (void)commitWithVerification:(BOOL)doVerify
152152
{
153-
if ([[NSFileManager defaultManager] fileExistsAtPath:[repository.gitURL.path stringByAppendingPathComponent:@"MERGE_HEAD"]]) {
153+
if ([[NSFileManager defaultManager] fileExistsAtPath:[self.repository.gitURL.path stringByAppendingPathComponent:@"MERGE_HEAD"]]) {
154154
NSString *message = NSLocalizedString(@"Cannot commit merges",
155155
@"Title for sheet that GitX cannot create merge commits");
156156
NSString *info = NSLocalizedString(@"GitX cannot commit merges yet. Please commit your changes from the command line.",
@@ -188,7 +188,7 @@ - (void)commitWithVerification:(BOOL)doVerify
188188
self.isBusy = YES;
189189
commitMessageView.editable = NO;
190190

191-
[repository.index commitWithMessage:commitMessage andVerify:doVerify];
191+
[self.repository.index commitWithMessage:commitMessage andVerify:doVerify];
192192
}
193193

194194
- (void)discardChangesForFiles:(NSArray *)files force:(BOOL)force
@@ -217,7 +217,7 @@ - (void)discardChangesForFiles:(NSArray *)files force:(BOOL)force
217217
- (IBAction)signOff:(id)sender
218218
{
219219
NSError *error = nil;
220-
GTConfiguration *config = [repository.gtRepo configurationWithError:&error];
220+
GTConfiguration *config = [self.repository.gtRepo configurationWithError:&error];
221221
NSString *userName = [config stringForKey:@"user.name"];
222222
NSString *userEmail = [config stringForKey:@"user.email"];
223223
if (!(userName && userEmail)) {
@@ -243,10 +243,10 @@ - (IBAction)refresh:(id)sender
243243
{
244244
self.isBusy = YES;
245245
self.status = NSLocalizedString(@"Refreshing index…", @"Message in status bar while the index is refreshing");
246-
[repository.index refresh];
246+
[self.repository.index refresh];
247247

248248
// Reload refs (in case HEAD changed)
249-
[repository reloadRefs];
249+
[self.repository reloadRefs];
250250
}
251251

252252
- (IBAction)commit:(id)sender

Classes/Controllers/PBGitHistoryController.m

+12-5
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ - (void)loadView
8888

8989
self.selectedCommitDetailsIndex = [[NSUserDefaults standardUserDefaults] integerForKey:kHistorySelectedDetailIndexKey];
9090

91+
PBGitRepository *repository = self.repository;
92+
9193
[commitController addObserver:self
9294
keyPath:@"selection"
9395
options:0
@@ -265,6 +267,8 @@ + (NSSet *)keyPathsForValuesAffectingSingleNonHeadCommitSelected
265267

266268
- (void)updateBranchFilterMatrix
267269
{
270+
PBGitRepository *repository = self.repository;
271+
268272
if ([repository.currentBranch isSimpleRef]) {
269273
[allBranchesFilterItem setEnabled:YES];
270274
[localRemoteBranchesFilterItem setEnabled:YES];
@@ -321,7 +325,7 @@ - (NSInteger)selectedCommitDetailsIndex
321325

322326
- (void)updateStatus
323327
{
324-
self.isBusy = repository.revisionList.isUpdating;
328+
self.isBusy = self.repository.revisionList.isUpdating;
325329
self.status = [NSString stringWithFormat:@"%lu commits loaded", [[commitController arrangedObjects] count]];
326330
}
327331

@@ -417,6 +421,8 @@ - (IBAction)setTreeView:(id)sender
417421

418422
- (IBAction)setBranchFilter:(id)sender
419423
{
424+
PBGitRepository *repository = self.repository;
425+
420426
repository.currentBranchFilter = [(NSView *)sender tag];
421427
[PBGitDefaults setBranchFilter:repository.currentBranchFilter];
422428
[self updateBranchFilterMatrix];
@@ -426,7 +432,7 @@ - (IBAction)setBranchFilter:(id)sender
426432
- (void)keyDown:(NSEvent *)event
427433
{
428434
if ([[event charactersIgnoringModifiers] isEqualToString:@"f"] && [event modifierFlags] & NSAlternateKeyMask && [event modifierFlags] & NSCommandKeyMask)
429-
[superController.window makeFirstResponder:searchField];
435+
[self.windowController.window makeFirstResponder:searchField];
430436
else
431437
[super keyDown:event];
432438
}
@@ -518,7 +524,7 @@ - (void)updateQuicklookForce:(BOOL)force
518524

519525
- (IBAction)refresh:(id)sender
520526
{
521-
[repository forceUpdateRevisions];
527+
[self.repository forceUpdateRevisions];
522528
}
523529

524530
- (void)updateView
@@ -628,7 +634,7 @@ - (void)checkoutFiles:(id)sender
628634
[files addObject:[filePath stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
629635

630636
NSError *error = nil;
631-
BOOL success = [repository checkoutFiles:files fromRefish:self.selectedCommits.firstObject error:&error];
637+
BOOL success = [self.repository checkoutFiles:files fromRefish:self.selectedCommits.firstObject error:&error];
632638
if (!success) {
633639
[self.windowController showErrorSheet:error];
634640
}
@@ -664,7 +670,7 @@ - (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexe
664670
if ([ref isTag] || [ref isRemoteBranch])
665671
return NO;
666672

667-
if ([[[repository headRef] ref] isEqualToRef:ref])
673+
if ([[[self.repository headRef] ref] isEqualToRef:ref])
668674
return NO;
669675

670676
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:[NSArray arrayWithObjects:[NSNumber numberWithInteger:row], [NSNumber numberWithInt:index], NULL]];
@@ -779,6 +785,7 @@ - (NSArray *)menuItemsForPaths:(NSArray *)paths
779785
action:@selector(showCommitsFromTree:)
780786
keyEquivalent:@""];
781787

788+
PBGitRepository *repository = self.repository;
782789
PBGitRef *headRef = [[repository headRef] ref];
783790
NSString *headRefName = [headRef shortName];
784791
NSString *diffTitleFormat = multiple ? NSLocalizedString(@"Diff files with %@", @"Diff with ref menu item for multiple files") : NSLocalizedString(@"Diff file with %@", @"Diff with ref menu item for single file");

Classes/Controllers/PBGitSidebarController.m

+14-14
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ - (void)awakeFromNib
6767
window.contentView = self.view;
6868
[self populateList];
6969

70+
PBGitRepository *repository = self.repository;
71+
7072
[repository addObserver:self
7173
keyPath:@"currentBranch"
7274
options:0
@@ -125,11 +127,6 @@ - (void)awakeFromNib
125127
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(expandCollapseItem:) name:NSOutlineViewItemWillCollapseNotification object:sourceView];
126128
}
127129

128-
- (void)closeView
129-
{
130-
[super closeView];
131-
}
132-
133130
- (void)dealloc
134131
{
135132
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSOutlineViewItemWillExpandNotification object:sourceView];
@@ -152,6 +149,7 @@ - (void)selectStage
152149

153150
- (void)selectCurrentBranch
154151
{
152+
PBGitRepository *repository = self.repository;
155153
PBGitRevSpecifier *rev = repository.currentBranch;
156154
if (!rev) {
157155
[repository reloadRefs];
@@ -239,18 +237,19 @@ - (void)outlineViewSelectionDidChange:(NSNotification *)notification
239237
{
240238
NSInteger index = [sourceView selectedRow];
241239
PBSourceViewItem *item = [sourceView itemAtRow:index];
240+
PBGitWindowController *windowController = self.windowController;
242241

243242
if ([item revSpecifier]) {
244-
if (![repository.currentBranch isEqual:[item revSpecifier]]) {
245-
repository.currentBranch = [item revSpecifier];
243+
if (![self.repository.currentBranch isEqual:[item revSpecifier]]) {
244+
self.repository.currentBranch = [item revSpecifier];
246245
}
247246

248-
[superController changeContentController:superController.historyViewController];
247+
[windowController changeContentController:windowController.historyViewController];
249248
[PBGitDefaults setShowStageView:NO];
250249
}
251250

252251
if (item == stage) {
253-
[superController changeContentController:superController.commitViewController];
252+
[windowController changeContentController:windowController.commitViewController];
254253
[PBGitDefaults setShowStageView:YES];
255254
}
256255

@@ -271,7 +270,7 @@ - (void)doubleClicked:(id)object
271270
PBSourceViewGitBranchItem *branch = item;
272271

273272
NSError *error = nil;
274-
BOOL success = [repository checkoutRefish:[branch ref] error:&error];
273+
BOOL success = [self.repository checkoutRefish:[branch ref] error:&error];
275274
if (!success) {
276275
[self.windowController showErrorSheet:error];
277276
}
@@ -297,7 +296,7 @@ - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTable
297296

298297
cell.textField.stringValue = [[item title] copy];
299298
cell.imageView.image = item.icon;
300-
cell.isCheckedOut = [item.revSpecifier isEqual:[repository headRef]];
299+
cell.isCheckedOut = [item.revSpecifier isEqual:[self.repository headRef]];
301300

302301
return cell;
303302
}
@@ -329,6 +328,7 @@ - (BOOL)outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:(i
329328

330329
- (void)populateList
331330
{
331+
PBGitRepository *repository = self.repository;
332332
PBSourceViewItem *project = [PBSourceViewItem groupItemWithTitle:[repository projectName]];
333333
project.uncollapsible = YES;
334334

@@ -420,7 +420,7 @@ - (void)addMenuItemsForRef:(PBGitRef *)ref toMenu:(NSMenu *)menu
420420
if (!ref)
421421
return;
422422

423-
for (NSMenuItem *menuItem in [superController.historyViewController menuItemsForRef:ref])
423+
for (NSMenuItem *menuItem in [self.windowController.historyViewController menuItemsForRef:ref])
424424
[menu addItem:menuItem];
425425
}
426426

@@ -493,7 +493,7 @@ - (void)updateRemoteControls
493493
BOOL hasRemote = NO;
494494

495495
PBGitRef *ref = [[self selectedItem] ref];
496-
if ([ref isRemote] || ([ref isBranch] && [[repository remoteRefForBranch:ref error:NULL] remoteName]))
496+
if ([ref isRemote] || ([ref isBranch] && [[self.repository remoteRefForBranch:ref error:NULL] remoteName]))
497497
hasRemote = YES;
498498

499499
[remoteControls setEnabled:hasRemote forSegment:kFetchSegment];
@@ -520,7 +520,7 @@ - (IBAction)fetchPullPushAction:(id)sender
520520
if (![ref isRemote] && ![ref isBranch])
521521
return;
522522

523-
PBGitRef *remoteRef = [repository remoteRefForBranch:ref error:NULL];
523+
PBGitRef *remoteRef = [self.repository remoteRefForBranch:ref error:NULL];
524524
if (!remoteRef)
525525
return;
526526

Classes/Controllers/PBViewController.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111
#import "PBGitRepository.h"
1212
#import "PBGitWindowController.h"
1313

14-
@interface PBViewController : NSViewController {
15-
// FIXME: these ivars must go, but most controller out there access it directly, so, not today
16-
PBGitRepository *repository;
17-
__weak PBGitWindowController *superController;
18-
}
14+
@interface PBViewController : NSViewController
1915

20-
@property (nonatomic, strong, readonly) PBGitRepository *repository;
16+
@property (nonatomic, weak, readonly) PBGitRepository *repository;
2117
@property (weak, readonly) PBGitWindowController *windowController;
2218
@property (copy) NSString *status;
2319
@property (assign) BOOL isBusy;

Classes/Controllers/PBViewController.m

-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ - (void)closeView
3636
[self unbind:@"repository"];
3737
if (_hasViewLoaded)
3838
[[self view] removeFromSuperview]; // remove the current view
39-
repository = nil;
40-
superController = nil;
4139
}
4240

4341
- (void)awakeFromNib

Classes/git/PBGitGrapher.h

-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
// Copyright 2008 __MyCompanyName__. All rights reserved.
77
//
88

9-
@class PBGitRepository;
109
@class PBGitCommit;
1110

1211
@interface PBGitGrapher : NSObject
1312

14-
- (id)initWithRepository:(PBGitRepository *)repo;
1513
- (void)decorateCommit:(PBGitCommit *)commit;
1614

1715
@end

Classes/git/PBGitGrapher.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ @interface PBGitGrapher ()
3434

3535
@implementation PBGitGrapher
3636

37-
- (id) initWithRepository: (PBGitRepository*) repo
37+
- (id) init
3838
{
3939
self = [super init];
4040
if (!self) {

Classes/git/PBGitHistoryGrapher.m

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ - (instancetype)initWithBaseCommits:(NSSet *)commits viewAllBranches:(BOOL)viewA
2121
delegate = theDelegate;
2222
currentQueue = queue;
2323
searchOIDs = [NSMutableSet setWithSet:commits];
24-
grapher = [[PBGitGrapher alloc] initWithRepository:nil];
24+
grapher = [[PBGitGrapher alloc] init];
2525
viewAllBranches = viewAll;
2626

2727
return self;
@@ -41,7 +41,6 @@ - (void)graphCommits:(NSArray *)revList
4141
if (!revList || [revList count] == 0)
4242
return;
4343

44-
id strongDelegate = delegate;
4544
//NSDate *start = [NSDate date];
4645
NSThread *currentThread = [NSThread currentThread];
4746
NSDate *lastUpdate = [NSDate date];
@@ -72,7 +71,10 @@ - (void)graphCommits:(NSArray *)revList
7271
//NSLog(@"Graphed %i commits in %f seconds (%f/sec)", counter, duration, counter/duration);
7372

7473
[self sendCommits:commits];
75-
[strongDelegate performSelectorOnMainThread:@selector(finishedGraphing) withObject:nil waitUntilDone:NO];
74+
75+
dispatch_async(dispatch_get_main_queue(), ^{
76+
[self->delegate finishedGraphing];
77+
});
7678
}
7779

7880

Classes/git/PBGitRevList.m

+9-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ - (void)loadRevisionsWithCompletionBlock:(void (^)(void))completionBlock
7575
GTEnumerator *enu = [[GTEnumerator alloc] initWithRepository:repo error:&error];
7676

7777
[weakSelf setupEnumerator:enu forRevspec:weakSelf.currentRev];
78-
[weakSelf addCommitsFromEnumerator:enu inPBRepo:pbRepo operation:weakParseOperation];
78+
[weakSelf addCommitsFromEnumerator:enu operation:weakParseOperation];
7979
}];
8080
[parseOperation setCompletionBlock:completionBlock];
8181

@@ -193,9 +193,9 @@ - (void)setupEnumerator:(GTEnumerator *)enumerator
193193
}
194194
}
195195

196-
- (void)addCommitsFromEnumerator:(GTEnumerator *)enumerator inPBRepo:(PBGitRepository *)pbRepo operation:(NSOperation *)operation
196+
- (void)addCommitsFromEnumerator:(GTEnumerator *)enumerator operation:(NSOperation *)operation
197197
{
198-
PBGitGrapher *g = [[PBGitGrapher alloc] initWithRepository:pbRepo];
198+
PBGitGrapher *g = [[PBGitGrapher alloc] init];
199199
__block NSDate *lastUpdate = [NSDate date];
200200

201201
dispatch_queue_t loadQueue = dispatch_queue_create("net.phere.gitx.loadQueue", 0);
@@ -214,6 +214,12 @@ - (void)addCommitsFromEnumerator:(GTEnumerator *)enumerator inPBRepo:(PBGitRepos
214214
return;
215215
}
216216

217+
PBGitRepository *pbRepo = self.repository;
218+
219+
if (pbRepo == nil) {
220+
return;
221+
}
222+
217223
PBGitCommit *newCommit = nil;
218224
PBGitCommit *cachedCommit = [self.commitCache objectForKey:oid];
219225
if (cachedCommit) {

0 commit comments

Comments
 (0)