Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash and miscellaneous cleanup #223

Merged
merged 6 commits into from Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions Classes/Controllers/PBGitCommitController.m
Expand Up @@ -98,7 +98,7 @@ - (void)awakeFromNib
ascending:true]]];

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

[stagedFilesController setAutomaticallyRearrangesObjects:NO];
[unstagedFilesController setAutomaticallyRearrangesObjects:NO];
Expand Down Expand Up @@ -145,12 +145,12 @@ - (NSResponder *)firstResponder;

- (PBGitIndex *)index
{
return repository.index;
return self.repository.index;
}

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

[repository.index commitWithMessage:commitMessage andVerify:doVerify];
[self.repository.index commitWithMessage:commitMessage andVerify:doVerify];
}

- (void)discardChangesForFiles:(NSArray *)files force:(BOOL)force
Expand Down Expand Up @@ -217,7 +217,7 @@ - (void)discardChangesForFiles:(NSArray *)files force:(BOOL)force
- (IBAction)signOff:(id)sender
{
NSError *error = nil;
GTConfiguration *config = [repository.gtRepo configurationWithError:&error];
GTConfiguration *config = [self.repository.gtRepo configurationWithError:&error];
NSString *userName = [config stringForKey:@"user.name"];
NSString *userEmail = [config stringForKey:@"user.email"];
if (!(userName && userEmail)) {
Expand All @@ -243,10 +243,10 @@ - (IBAction)refresh:(id)sender
{
self.isBusy = YES;
self.status = NSLocalizedString(@"Refreshing index…", @"Message in status bar while the index is refreshing");
[repository.index refresh];
[self.repository.index refresh];

// Reload refs (in case HEAD changed)
[repository reloadRefs];
[self.repository reloadRefs];
}

- (IBAction)commit:(id)sender
Expand Down
17 changes: 12 additions & 5 deletions Classes/Controllers/PBGitHistoryController.m
Expand Up @@ -88,6 +88,8 @@ - (void)loadView

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

PBGitRepository *repository = self.repository;

[commitController addObserver:self
keyPath:@"selection"
options:0
Expand Down Expand Up @@ -265,6 +267,8 @@ + (NSSet *)keyPathsForValuesAffectingSingleNonHeadCommitSelected

- (void)updateBranchFilterMatrix
{
PBGitRepository *repository = self.repository;

if ([repository.currentBranch isSimpleRef]) {
[allBranchesFilterItem setEnabled:YES];
[localRemoteBranchesFilterItem setEnabled:YES];
Expand Down Expand Up @@ -321,7 +325,7 @@ - (NSInteger)selectedCommitDetailsIndex

- (void)updateStatus
{
self.isBusy = repository.revisionList.isUpdating;
self.isBusy = self.repository.revisionList.isUpdating;
self.status = [NSString stringWithFormat:@"%lu commits loaded", [[commitController arrangedObjects] count]];
}

Expand Down Expand Up @@ -417,6 +421,8 @@ - (IBAction)setTreeView:(id)sender

- (IBAction)setBranchFilter:(id)sender
{
PBGitRepository *repository = self.repository;

repository.currentBranchFilter = [(NSView *)sender tag];
[PBGitDefaults setBranchFilter:repository.currentBranchFilter];
[self updateBranchFilterMatrix];
Expand All @@ -426,7 +432,7 @@ - (IBAction)setBranchFilter:(id)sender
- (void)keyDown:(NSEvent *)event
{
if ([[event charactersIgnoringModifiers] isEqualToString:@"f"] && [event modifierFlags] & NSAlternateKeyMask && [event modifierFlags] & NSCommandKeyMask)
[superController.window makeFirstResponder:searchField];
[self.windowController.window makeFirstResponder:searchField];
else
[super keyDown:event];
}
Expand Down Expand Up @@ -518,7 +524,7 @@ - (void)updateQuicklookForce:(BOOL)force

- (IBAction)refresh:(id)sender
{
[repository forceUpdateRevisions];
[self.repository forceUpdateRevisions];
}

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

NSError *error = nil;
BOOL success = [repository checkoutFiles:files fromRefish:self.selectedCommits.firstObject error:&error];
BOOL success = [self.repository checkoutFiles:files fromRefish:self.selectedCommits.firstObject error:&error];
if (!success) {
[self.windowController showErrorSheet:error];
}
Expand Down Expand Up @@ -664,7 +670,7 @@ - (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexe
if ([ref isTag] || [ref isRemoteBranch])
return NO;

if ([[[repository headRef] ref] isEqualToRef:ref])
if ([[[self.repository headRef] ref] isEqualToRef:ref])
return NO;

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

PBGitRepository *repository = self.repository;
PBGitRef *headRef = [[repository headRef] ref];
NSString *headRefName = [headRef shortName];
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");
Expand Down
28 changes: 14 additions & 14 deletions Classes/Controllers/PBGitSidebarController.m
Expand Up @@ -67,6 +67,8 @@ - (void)awakeFromNib
window.contentView = self.view;
[self populateList];

PBGitRepository *repository = self.repository;

[repository addObserver:self
keyPath:@"currentBranch"
options:0
Expand Down Expand Up @@ -125,11 +127,6 @@ - (void)awakeFromNib
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(expandCollapseItem:) name:NSOutlineViewItemWillCollapseNotification object:sourceView];
}

- (void)closeView
{
[super closeView];
}

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSOutlineViewItemWillExpandNotification object:sourceView];
Expand All @@ -152,6 +149,7 @@ - (void)selectStage

- (void)selectCurrentBranch
{
PBGitRepository *repository = self.repository;
PBGitRevSpecifier *rev = repository.currentBranch;
if (!rev) {
[repository reloadRefs];
Expand Down Expand Up @@ -239,18 +237,19 @@ - (void)outlineViewSelectionDidChange:(NSNotification *)notification
{
NSInteger index = [sourceView selectedRow];
PBSourceViewItem *item = [sourceView itemAtRow:index];
PBGitWindowController *windowController = self.windowController;

if ([item revSpecifier]) {
if (![repository.currentBranch isEqual:[item revSpecifier]]) {
repository.currentBranch = [item revSpecifier];
if (![self.repository.currentBranch isEqual:[item revSpecifier]]) {
self.repository.currentBranch = [item revSpecifier];
}

[superController changeContentController:superController.historyViewController];
[windowController changeContentController:windowController.historyViewController];
[PBGitDefaults setShowStageView:NO];
}

if (item == stage) {
[superController changeContentController:superController.commitViewController];
[windowController changeContentController:windowController.commitViewController];
[PBGitDefaults setShowStageView:YES];
}

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

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

cell.textField.stringValue = [[item title] copy];
cell.imageView.image = item.icon;
cell.isCheckedOut = [item.revSpecifier isEqual:[repository headRef]];
cell.isCheckedOut = [item.revSpecifier isEqual:[self.repository headRef]];

return cell;
}
Expand Down Expand Up @@ -329,6 +328,7 @@ - (BOOL)outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:(i

- (void)populateList
{
PBGitRepository *repository = self.repository;
PBSourceViewItem *project = [PBSourceViewItem groupItemWithTitle:[repository projectName]];
project.uncollapsible = YES;

Expand Down Expand Up @@ -420,7 +420,7 @@ - (void)addMenuItemsForRef:(PBGitRef *)ref toMenu:(NSMenu *)menu
if (!ref)
return;

for (NSMenuItem *menuItem in [superController.historyViewController menuItemsForRef:ref])
for (NSMenuItem *menuItem in [self.windowController.historyViewController menuItemsForRef:ref])
[menu addItem:menuItem];
}

Expand Down Expand Up @@ -493,7 +493,7 @@ - (void)updateRemoteControls
BOOL hasRemote = NO;

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

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

PBGitRef *remoteRef = [repository remoteRefForBranch:ref error:NULL];
PBGitRef *remoteRef = [self.repository remoteRefForBranch:ref error:NULL];
if (!remoteRef)
return;

Expand Down
8 changes: 2 additions & 6 deletions Classes/Controllers/PBViewController.h
Expand Up @@ -11,13 +11,9 @@
#import "PBGitRepository.h"
#import "PBGitWindowController.h"

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

@property (nonatomic, strong, readonly) PBGitRepository *repository;
@property (nonatomic, weak, readonly) PBGitRepository *repository;
@property (weak, readonly) PBGitWindowController *windowController;
@property (copy) NSString *status;
@property (assign) BOOL isBusy;
Expand Down
2 changes: 0 additions & 2 deletions Classes/Controllers/PBViewController.m
Expand Up @@ -36,8 +36,6 @@ - (void)closeView
[self unbind:@"repository"];
if (_hasViewLoaded)
[[self view] removeFromSuperview]; // remove the current view
repository = nil;
superController = nil;
}

- (void)awakeFromNib
Expand Down
2 changes: 0 additions & 2 deletions Classes/git/PBGitGrapher.h
Expand Up @@ -6,12 +6,10 @@
// Copyright 2008 __MyCompanyName__. All rights reserved.
//

@class PBGitRepository;
@class PBGitCommit;

@interface PBGitGrapher : NSObject

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

@end
2 changes: 1 addition & 1 deletion Classes/git/PBGitGrapher.mm
Expand Up @@ -34,7 +34,7 @@ @interface PBGitGrapher ()

@implementation PBGitGrapher

- (id) initWithRepository: (PBGitRepository*) repo
- (id) init
{
self = [super init];
if (!self) {
Expand Down
8 changes: 5 additions & 3 deletions Classes/git/PBGitHistoryGrapher.m
Expand Up @@ -21,7 +21,7 @@ - (instancetype)initWithBaseCommits:(NSSet *)commits viewAllBranches:(BOOL)viewA
delegate = theDelegate;
currentQueue = queue;
searchOIDs = [NSMutableSet setWithSet:commits];
grapher = [[PBGitGrapher alloc] initWithRepository:nil];
grapher = [[PBGitGrapher alloc] init];
viewAllBranches = viewAll;

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

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

[self sendCommits:commits];
[strongDelegate performSelectorOnMainThread:@selector(finishedGraphing) withObject:nil waitUntilDone:NO];

dispatch_async(dispatch_get_main_queue(), ^{
[self->delegate finishedGraphing];
});
}


Expand Down
12 changes: 9 additions & 3 deletions Classes/git/PBGitRevList.m
Expand Up @@ -75,7 +75,7 @@ - (void)loadRevisionsWithCompletionBlock:(void (^)(void))completionBlock
GTEnumerator *enu = [[GTEnumerator alloc] initWithRepository:repo error:&error];

[weakSelf setupEnumerator:enu forRevspec:weakSelf.currentRev];
[weakSelf addCommitsFromEnumerator:enu inPBRepo:pbRepo operation:weakParseOperation];
[weakSelf addCommitsFromEnumerator:enu operation:weakParseOperation];
}];
[parseOperation setCompletionBlock:completionBlock];

Expand Down Expand Up @@ -193,9 +193,9 @@ - (void)setupEnumerator:(GTEnumerator *)enumerator
}
}

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

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

PBGitRepository *pbRepo = self.repository;

if (pbRepo == nil) {
return;
}

PBGitCommit *newCommit = nil;
PBGitCommit *cachedCommit = [self.commitCache objectForKey:oid];
if (cachedCommit) {
Expand Down