From f0a3502c72ecf31af8ec902c8a5d24470ebf5f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Berg?= Date: Fri, 26 Mar 2010 11:36:06 +0100 Subject: [PATCH] Make the gitx arguments "--all" and "--local" (new) switch to the corresponding branch filtered output instead of adding the argument name to the "OTHERS" group. --- PBCLIProxy.h | 4 ++-- PBCLIProxy.m | 35 +++++++++++++++++++++++++++++------ gitx.m | 9 +++++---- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/PBCLIProxy.h b/PBCLIProxy.h index 6c11886..135f1d1 100644 --- a/PBCLIProxy.h +++ b/PBCLIProxy.h @@ -16,10 +16,10 @@ @property (retain) NSConnection* connection; @end -#define ConnectionName @"GitX DO Connection" +#define PBDOConnectionName @"GitXDOConnection" #define PBCLIProxyErrorDomain @"PBCLIProxyErrorDomain" @protocol GitXCliToolProtocol -- (BOOL)openRepository:(NSURL*)repositoryPath arguments: (NSArray*) args error:(NSError**)error; +- (BOOL)openRepository:(NSString *)repositoryPath arguments: (NSArray*) args error:(NSError**)error; - (void)openDiffWindowWithDiff:(NSString *)diff; @end \ No newline at end of file diff --git a/PBCLIProxy.m b/PBCLIProxy.m index 5c07812..4e1ec8f 100644 --- a/PBCLIProxy.m +++ b/PBCLIProxy.m @@ -23,18 +23,27 @@ connection = [NSConnection new]; [connection setRootObject:self]; - if ([connection registerName:ConnectionName] == NO) + if ([connection registerName:PBDOConnectionName] == NO) NSBeep(); } return self; } -- (BOOL)openRepository:(NSURL*)repositoryPath arguments: (NSArray*) args error:(NSError**)error; +- (BOOL)openRepository:(NSString *)repositoryPath arguments: (NSArray*) args error:(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. - NSURL* url = [NSURL fileURLWithPath:[repositoryPath path]]; + + // !!! Andre Berg 20100326: This is because NSURL objects are passed by reference + // See NSObject's implementation of -replacementObjectForPortCoder: where it says + // "Subclasses that want to be passed by copy instead of by reference must override + // this method and return self." + // In other words we either make a subclass of NSURL that returns self for that implementation + // or we simply pass the path as NSString which is always bycopy. + // See also http://jens.mooseyard.com/2009/07/the-subtle-dangers-of-distributed-objects/#comment-3068 + // + NSURL* url = [NSURL fileURLWithPath:repositoryPath isDirectory:YES]; NSArray* arguments = [NSArray arrayWithArray:args]; PBGitRepository *document = [[PBRepositoryDocumentController sharedDocumentController] documentForLocation:url]; @@ -62,9 +71,23 @@ [[arguments objectAtIndex:0] isEqualToString:@"-c"])) [document.windowController showCommitView:self]; else { - PBGitRevSpecifier* rev = [[PBGitRevSpecifier alloc] initWithParameters:arguments]; - rev.workingDirectory = url; - document.currentBranch = [document addBranch: rev]; + 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]; diff --git a/gitx.m b/gitx.m index 6449556..1dae6ae 100644 --- a/gitx.m +++ b/gitx.m @@ -12,7 +12,7 @@ NSDistantObject* connect() { - id proxy = [NSConnection rootProxyForConnectionWithRegisteredName:ConnectionName host:nil]; + id proxy = [NSConnection rootProxyForConnectionWithRegisteredName:PBDOConnectionName host:nil]; [proxy setProtocolForProxy:@protocol(GitXCliToolProtocol)]; return proxy; } @@ -59,6 +59,7 @@ void usage(char const *programName) printf("\tSee 'man git-log' and 'man git-rev-list' for options you can pass to gitx\n"); printf("\n"); printf("\t--all show all branches\n"); + printf("\t--local show local branches\n"); printf("\t show specific branch\n"); printf("\t -- show commits touching paths\n"); exit(1); @@ -148,13 +149,13 @@ int main(int argc, const char** argv) handleDiffWithArguments([arguments subarrayWithRange:NSMakeRange(1, [arguments count] - 1)], pwd, proxy); // No diff, just open the current dir - NSURL* url = [NSURL fileURLWithPath:pwd]; NSError* error = nil; - if (![proxy openRepository:url arguments: arguments error:&error]) { - fprintf(stderr, "Error opening repository at %s\n", [[url path] UTF8String]); + if (![proxy openRepository:pwd arguments: arguments error:&error]) { + fprintf(stderr, "Error opening repository at %s\n", [pwd UTF8String]); if (error) fprintf(stderr, "\t%s\n", [[error localizedFailureReason] UTF8String]); + return 1; } return 0;