Files
gitx/PBCLIProxy.m
T
André Berg 8ddcc6c660 Add DO directional/value qualifier keywords to PBCLIProxy
Specifying these helps to improve DO performance and it should also help
with the NSURL passed byref thingy (see PBCLIProxy.m), although we don't
really need that anymore because we changed the parameters to be NSString's
which by default are passed bycopy.

Specifying "oneway void" creates a fire-and-forget situation where the 
distant object will not wait for the value returned.
2010-04-05 22:58:35 +02:00

104 lines
3.6 KiB
Objective-C

//
// PBCLIProxy.m
// GitX
//
// Created by Ciarán Walsh on 15/08/2008.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "PBCLIProxy.h"
#import "PBRepositoryDocumentController.h"
#import "PBGitRevSpecifier.h"
#import "PBGitRepository.h"
#import "PBGitWindowController.h"
#import "PBGitBinary.h"
#import "PBDiffWindowController.h"
@implementation PBCLIProxy
@synthesize connection;
- (id)init
{
if (self = [super init]) {
connection = [NSConnection new];
[connection setRootObject:self];
if ([connection registerName:PBDOConnectionName] == NO)
NSBeep();
}
return self;
}
- (BOOL) openRepository:(in bycopy NSString *)repositoryPath arguments:(in bycopy NSArray *)args error:(byref NSError **)error
{
// FIXME I found that creating this redundant NSURL reference was necessary to
// work around an apparent bug with GC and Distributed Objects
// I am not familiar with GC though, so perhaps I was doing something wrong.
// !!! Andre Berg 20100326: This is because NSURL objects are passed as proxies
// See also http://jens.mooseyard.com/2009/07/the-subtle-dangers-of-distributed-objects/#comment-3069
//
NSURL* url = [NSURL fileURLWithPath:repositoryPath isDirectory:YES];
NSArray* arguments = [NSArray arrayWithArray:args];
PBGitRepository *document = [[PBRepositoryDocumentController sharedDocumentController] documentForLocation:url];
if (!document) {
if (error) {
NSString *suggestion = nil;
NSInteger errCode = -1;
if ([PBGitBinary path]) {
suggestion = @"this isn't a git repository";
errCode = PBNotAGitRepositoryErrorCode;
} else {
suggestion = @"GitX can't find your git binary";
errCode = PBGitBinaryNotFoundErrorCode;
}
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Could not create document. Perhaps %@", suggestion]
forKey:NSLocalizedFailureReasonErrorKey];
*error = [NSError errorWithDomain:PBCLIProxyErrorDomain code:errCode userInfo:userInfo];
}
return NO;
}
NSLog(@"document = %@ at path = %@", document, repositoryPath);
document.launchedFromCLI = YES;
if ([arguments count] > 0 && ([[arguments objectAtIndex:0] isEqualToString:@"--commit"] ||
[[arguments objectAtIndex:0] isEqualToString:@"-c"]))
[document.windowController showCommitView:self];
else {
PBGitRevSpecifier* rev = nil;
if ([arguments count] > 0 && [[arguments objectAtIndex:0] isEqualToString:@"--all"]) {
document.currentBranchFilter = kGitXAllBranchesFilter;
[document readCurrentBranch];
rev = document.currentBranch;
} else if ([arguments count] > 0 && [[arguments objectAtIndex:0] isEqualToString:@"--local"]) {
document.currentBranchFilter = kGitXLocalRemoteBranchesFilter;
[document readCurrentBranch];
rev = document.currentBranch;
}
if (!rev) {
rev = [[PBGitRevSpecifier alloc] initWithParameters:arguments];
rev.workingDirectory = url;
document.currentBranch = [document addBranch: rev];
}
[document.windowController showHistoryView:self];
}
[NSApp activateIgnoringOtherApps:YES];
return YES;
}
- (oneway void) openDiffWindowWithDiff:(in bycopy NSString *)diff
{
PBDiffWindowController *diffController = [[PBDiffWindowController alloc] initWithDiff:[diff copy]];
[diffController showWindow:nil];
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
}
@end