Permalink
Browse files

Add a --commit option to the CLI client

This changes a lot of code, so quick review:

* RepositoryDocumentController now returns the document without selecting a ref
* PBGitWindowController now optionally shows the default view, or selects no view at all
* PBGitRepository keeps a pointer to its WindowController so that it can change views
  • Loading branch information...
1 parent de9f4dd commit 86606ef81564f439b3b2539f2af0019cd4ce6744 @pieter committed Sep 26, 2008
View
@@ -9,6 +9,8 @@
#import "PBCLIProxy.h"
#import "PBRepositoryDocumentController.h"
#import "PBGitRevSpecifier.h"
+#import "PBGitRepository.h"
+#import "PBGitWindowController.h"
@implementation PBCLIProxy
@synthesize connection;
@@ -31,14 +33,22 @@ - (BOOL)openRepository:(NSURL*)repositoryPath arguments: (NSArray*) args 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]];
NSArray* arguments = [NSArray arrayWithArray:args];
- PBGitRevSpecifier* rev = [[PBGitRevSpecifier alloc] initWithParameters:arguments];
- if ([[PBRepositoryDocumentController sharedDocumentController] openRepositoryAtLocation: url RevSpecifier: rev]) {
- [NSApp activateIgnoringOtherApps:YES];
- return YES;
+
+ PBGitRepository *document = [[PBRepositoryDocumentController sharedDocumentController] documentForLocation:url];
+ if (!document)
+ return NO;
+
+ if ([arguments count] > 0 && ([[arguments objectAtIndex:0] isEqualToString:@"--commit"] ||
+ [[arguments objectAtIndex:0] isEqualToString:@"-c"]))
+ ((PBGitWindowController *)document.windowController).selectedViewIndex = 1;
+ else {
+ PBGitRevSpecifier* rev = [[PBGitRevSpecifier alloc] initWithParameters:arguments];
+ [document selectBranch: [document addBranch: rev]];
}
- return NO;
+ [NSApp activateIgnoringOtherApps:YES];
+
+ return YES;
}
@end
View
@@ -14,6 +14,8 @@ extern NSString* PBGitRepositoryErrorDomain;
@interface PBGitRepository : NSDocument {
PBGitRevList* revisionList;
+ NSWindowController *windowController;
+
NSMutableArray* branches;
NSIndexSet* currentBranch;
NSMutableDictionary* refs;
@@ -45,9 +47,10 @@ extern NSString* PBGitRepositoryErrorDomain;
+ (NSURL*)gitDirForURL:(NSURL*)repositoryURL;
+ (NSURL*)baseDirForURL:(NSURL*)repositoryURL;
-- (id) initWithURL: (NSURL*) path andRevSpecifier:(PBGitRevSpecifier*) rev;
+- (id) initWithURL: (NSURL*) path;
- (void) setup;
+@property (readonly) NSWindowController *windowController;
@property (retain) PBGitRevList* revisionList;
@property (assign) NSMutableArray* branches;
@property (assign) NSIndexSet* currentBranch;
View
@@ -19,7 +19,7 @@
@implementation PBGitRepository
-@synthesize revisionList, branches, currentBranch, refs;
+@synthesize revisionList, branches, currentBranch, refs, windowController;
static NSString* gitPath;
+ (void) initialize
@@ -131,12 +131,11 @@ - (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)type
- (void) setup
{
- self.branches = [NSMutableArray array];
[self reloadRefs];
revisionList = [[PBGitRevList alloc] initWithRepository:self];
}
-- (id) initWithURL: (NSURL*) path andRevSpecifier:(PBGitRevSpecifier*) rev
+- (id) initWithURL: (NSURL*) path
{
NSURL* gitDirURL = [PBGitRepository gitDirForURL:path];
if (!gitDirURL)
@@ -146,10 +145,16 @@ - (id) initWithURL: (NSURL*) path andRevSpecifier:(PBGitRevSpecifier*) rev
[self setFileURL: gitDirURL];
[self setup];
- [self selectBranch: [self addBranch: rev]];
+
+ // We don't want the window controller to display anything yet..
+ // We'll leave that to the caller of this method.
+ windowController = [[PBGitWindowController alloc] initWithRepository:self displayDefault:NO];
+ [self addWindowController:windowController];
+ [self showWindows];
return self;
}
+
// The fileURL the document keeps is to the .git dir, but that’s pretty
// useless for display in the window title bar, so we show the directory above
- (NSString*)displayName
@@ -163,11 +168,11 @@ - (NSString*)displayName
// Overridden to create our custom window controller
- (void)makeWindowControllers
{
- PBGitWindowController* controller = [[PBGitWindowController alloc] initWithRepository:self];
- [self addWindowController:controller];
- [controller release];
+ windowController = [[PBGitWindowController alloc] initWithRepository:self displayDefault:YES];
+ [self addWindowController:windowController];
}
+
- (void) addRef: (PBGitRef *) ref fromParameters: (NSArray *) components
{
NSString* type = [components objectAtIndex:1];
@@ -192,6 +197,7 @@ - (void) addRef: (PBGitRef *) ref fromParameters: (NSArray *) components
- (BOOL) reloadRefs
{
BOOL ret = NO;
+ self.branches = [NSMutableArray array];
NSString* output = [PBEasyPipe outputForCommand:gitPath withArgs:[NSArray arrayWithObjects:@"for-each-ref", @"--format=%(refname) %(objecttype) %(objectname) %(*objectname)", @"refs", nil] inDir: self.fileURL.path];
NSArray* lines = [output componentsSeparatedByString:@"\n"];
refs = [NSMutableDictionary dictionary];
@@ -240,18 +246,27 @@ - (PBGitRevSpecifier*) addBranch: (PBGitRevSpecifier*) rev
return rev;
}
+- (void) showHistoryView
+{
+ if (!windowController)
+ return;
+
+ ((PBGitWindowController *)windowController).selectedViewIndex = 0;
+}
+
- (void) selectBranch: (PBGitRevSpecifier*) rev
{
int i;
for (i = 0; i < [branches count]; i++) {
PBGitRevSpecifier* aRev = [branches objectAtIndex:i];
if (rev == aRev) {
self.currentBranch = [NSIndexSet indexSetWithIndex:i];
+ [self showHistoryView];
return;
}
}
}
-
+
- (void) readCurrentBranch
{
[self selectBranch: [self addBranch: [self headRef]]];
View
@@ -13,18 +13,18 @@
IBOutlet NSSearchField* searchField;
IBOutlet NSArrayController* searchController;
IBOutlet NSArrayController *branchesController;
- PBGitRepository* repository;
+ __weak PBGitRepository* repository;
int selectedViewIndex;
IBOutlet NSView* contentView;
NSViewController* viewController;
}
-@property (retain) PBGitRepository *repository;
+@property (assign) __weak PBGitRepository *repository;
@property (readonly) NSViewController *viewController;
@property (assign) int selectedViewIndex;
@property (retain) NSArrayController *searchController;
-- (id)initWithRepository:(PBGitRepository*)theRepository;
+- (id)initWithRepository:(PBGitRepository*)theRepository displayDefault:(BOOL)display;
- (void)changeViewController:(NSInteger)whichViewTag;
- (void) focusOnSearchField;
View
@@ -16,13 +16,20 @@ @implementation PBGitWindowController
@synthesize repository, viewController, searchController, selectedViewIndex;
-- (id)initWithRepository:(PBGitRepository*)theRepository;
+- (id)initWithRepository:(PBGitRepository*)theRepository displayDefault:(BOOL)displayDefault
{
if(self = [self initWithWindowNibName:@"RepositoryWindow"])
{
self.repository = theRepository;
[self showWindow:nil];
}
+
+ if (displayDefault) {
+ self.selectedViewIndex = [[NSUserDefaults standardUserDefaults] integerForKey:@"selectedViewIndex"];
+ } else {
+ self.selectedViewIndex = -1;
+ }
+
return self;
}
@@ -76,7 +83,6 @@ - (void)awakeFromNib
// We bind this ourselves because otherwise we would lose our selection
[branchesController bind:@"selectionIndexes" toObject:repository withKeyPath:@"currentBranch" options:nil];
- self.selectedViewIndex = [[NSUserDefaults standardUserDefaults] integerForKey:@"selectedViewIndex"];
[[self window] setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge];
[[self window] setContentBorderThickness:35.0f forEdge:NSMinYEdge];
@@ -15,5 +15,5 @@
}
-- (id) openRepositoryAtLocation:(NSURL*) url RevSpecifier:(PBGitRevSpecifier*) rev;
+- (id) documentForLocation:(NSURL*) url;
@end
@@ -31,20 +31,17 @@ - (void)noteNewRecentDocumentURL:(NSURL*)url
[super noteNewRecentDocumentURL:[PBGitRepository baseDirForURL:url]];
}
-- (id) openRepositoryAtLocation:(NSURL*) url RevSpecifier:(PBGitRevSpecifier*) rev
+- (id) documentForLocation:(NSURL*) url
{
id document = [self documentForURL:url];
if (!document) {
- document = [[PBGitRepository alloc] initWithURL:url andRevSpecifier:rev];
- if (!document)
- return nil;
+
+ if (!(document = [[PBGitRepository alloc] initWithURL:url]))
+ return NO;
[self addDocument:document];
- [document makeWindowControllers];
- } else {
- [document selectBranch: [document addBranch: rev]];
}
- [document showWindows];
+
return document;
}
@end

0 comments on commit 86606ef

Please sign in to comment.