Skip to content

Commit d3592f3

Browse files
committed
Remove things that aren't needed now that PBGitRepository is more NSDoc-like
Also, switch repository creation to GTRepository.
1 parent 5acdd70 commit d3592f3

11 files changed

+47
-98
lines changed

Classes/Controllers/ApplicationController.m

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#import "ApplicationController.h"
1010
#import "PBGitRevisionCell.h"
1111
#import "PBGitWindowController.h"
12-
#import "PBRepositoryDocumentController.h"
1312
#import "PBServicesController.h"
1413
#import "PBGitXProtocol.h"
1514
#import "PBPrefsWindowController.h"
@@ -70,7 +69,7 @@ - (void)registerServices
7069

7170
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
7271
{
73-
if(!started || [[[PBRepositoryDocumentController sharedDocumentController] documents] count])
72+
if(!started || [[[NSDocumentController sharedDocumentController] documents] count])
7473
return NO;
7574
return YES;
7675
}

Classes/Controllers/OpenRecentController.m

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#import "OpenRecentController.h"
1010
#import "PBGitDefaults.h"
11-
#import "PBRepositoryDocumentController.h"
1211

1312
@implementation OpenRecentController
1413

@@ -77,9 +76,9 @@ - (IBAction) tableDoubleClick:(id)sender
7776
{
7877
[self changeSelection:self];
7978
if(selectedResult != nil) {
80-
[[PBRepositoryDocumentController sharedDocumentController] openDocumentWithContentsOfURL:selectedResult
81-
display:YES
82-
error:nil];
79+
[[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:selectedResult
80+
display:YES
81+
error:nil];
8382
}
8483
[self hide];
8584
}
@@ -88,9 +87,9 @@ - (BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySe
8887
BOOL result = NO;
8988
if (commandSelector == @selector(insertNewline:)) {
9089
if(selectedResult != nil) {
91-
[[PBRepositoryDocumentController sharedDocumentController] openDocumentWithContentsOfURL:selectedResult
92-
display:YES
93-
error:nil];
90+
[[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:selectedResult
91+
display:YES
92+
error:nil];
9493
}
9594
[self hide];
9695
// [searchWindow makeKeyAndOrderFront: nil];

Classes/Controllers/PBGitSidebarController.m

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#import "PBAddRemoteSheet.h"
1717
#import "PBGitDefaults.h"
1818
#import "PBHistorySearchController.h"
19-
#import "PBRepositoryDocumentController.h"
2019

2120
@interface PBGitSidebarController ()
2221

@@ -225,9 +224,9 @@ - (void)doubleClicked:(id)object {
225224
PBGitSVSubmoduleItem *subModule = [sourceView itemAtRow:rowNumber];
226225

227226
NSURL *url = [NSURL fileURLWithPath:subModule.submodule.path];
228-
[[PBRepositoryDocumentController sharedDocumentController] openDocumentWithContentsOfURL:url
229-
display:YES
230-
error:nil];
227+
[[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:url
228+
display:YES
229+
error:nil];
231230

232231
;
233232
}

Classes/Controllers/PBRepositoryDocumentController.h

-7
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@
77
//
88

99
#import <Cocoa/Cocoa.h>
10-
#import "PBGitRevSpecifier.h"
11-
1210

1311
@interface PBRepositoryDocumentController : NSDocumentController
14-
{
15-
16-
}
1712

18-
- (id) documentForLocation:(NSURL*) url;
19-
- (void)initNewRepositoryAtURL:(NSURL *)url;
2013
@end

Classes/Controllers/PBRepositoryDocumentController.m

+11-46
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#import "PBGitBinary.h"
1414
#import "GitRepoFinder.h"
1515

16+
#import <ObjectiveGit/GTRepository.h>
17+
1618
@implementation PBRepositoryDocumentController
1719
// This method is overridden to configure the open panel to only allow
1820
// selection of directories
@@ -24,60 +26,23 @@ - (NSInteger)runModalOpenPanel:(NSOpenPanel *)openPanel forTypes:(NSArray *)exte
2426
return [openPanel runModal];
2527
}
2628

27-
// Convert paths to the .git dir before searching for an already open document
28-
- (id)documentForURL:(NSURL *)URL
29-
{
30-
NSURL* fileURL = [GitRepoFinder fileURLForURL:URL];
31-
id result = [super documentForURL:fileURL];
32-
return result;
33-
}
34-
35-
- (void)noteNewRecentDocumentURL:(NSURL*)URL
36-
{
37-
NSURL* fileURL = [GitRepoFinder fileURLForURL:URL];
38-
[super noteNewRecentDocumentURL:fileURL];
39-
}
40-
41-
- (id) documentForLocation:(NSURL*) url
42-
{
43-
id document = [self documentForURL:url];
44-
if (!document) {
45-
46-
if (!(document = [[PBGitRepository alloc] initWithURL:url]))
47-
return nil;
48-
49-
[self addDocument:document];
50-
}
51-
else
52-
[document showWindows];
53-
54-
return document;
55-
}
56-
57-
- (void)initNewRepositoryAtURL:(NSURL *)url
58-
{
59-
int terminationStatus;
60-
NSString *result = [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:[NSArray arrayWithObjects:@"init", @"-q", nil] inDir:[url path] retValue:&terminationStatus];
61-
62-
if (terminationStatus == 0)
63-
[self openDocumentWithContentsOfURL:url display:YES error:NULL];
64-
else
65-
NSRunAlertPanel(@"Failed to create new Git repository", @"Git returned the following error when trying to create the repository: %@", nil, nil, nil, result);
66-
}
67-
68-
- (IBAction)newDocument:(id)sender
69-
{
29+
- (id)makeUntitledDocumentOfType:(NSString *)typeName error:(NSError *__autoreleasing *)outError {
7030
NSOpenPanel *op = [NSOpenPanel openPanel];
7131

7232
[op setCanChooseFiles:NO];
7333
[op setCanChooseDirectories:YES];
7434
[op setAllowsMultipleSelection:NO];
7535
[op setMessage:@"Initialize a repository here:"];
7636
[op setTitle:@"New Repository"];
77-
if ([op runModal] == NSFileHandlingPanelOKButton)
78-
[self initNewRepositoryAtURL:[op URL]];
79-
}
37+
if ([op runModal] != NSFileHandlingPanelOKButton)
38+
return nil;
8039

40+
BOOL success = [GTRepository initializeEmptyRepositoryAtURL:[op URL] error:outError];
41+
if (!success)
42+
return nil; // Repo creation failed
43+
44+
return [[PBGitRepository alloc] initWithContentsOfURL:[op URL] ofType:PBGitRepositoryDocumentType error:outError];
45+
}
8146

8247
- (BOOL)validateMenuItem:(NSMenuItem *)item
8348
{

Classes/Controllers/PBServicesController.m

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//
88

99
#import "PBServicesController.h"
10-
#import "PBRepositoryDocumentController.h"
1110
#import "PBGitRepository.h"
1211

1312
@implementation PBServicesController

Classes/PBCLIProxy.m

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//
88

99
#import "PBCLIProxy.h"
10-
#import "PBRepositoryDocumentController.h"
1110
#import "PBGitRevSpecifier.h"
1211
#import "PBGitRepository.h"
1312
#import "PBGitWindowController.h"
@@ -38,7 +37,7 @@ - (BOOL)openRepository:(NSURL*)repositoryPath arguments: (NSArray*) args error:(
3837
NSURL* url = [NSURL fileURLWithPath:[repositoryPath path]];
3938
NSArray* arguments = [NSArray arrayWithArray:args];
4039

41-
PBGitRepository *document = [[PBRepositoryDocumentController sharedDocumentController] documentForLocation:url];
40+
PBGitRepository *document = [[NSDocumentController sharedDocumentController] documentForURL:url];
4241
if (!document) {
4342
if (error) {
4443
NSString *suggestion = [PBGitBinary path] ? @"this isn't a git repository" : @"GitX can't find your git binary";

Classes/Util/NSApplication+GitXScripting.m

+20-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
#import "NSApplication+GitXScripting.h"
1010
#import "GitXScriptingConstants.h"
1111
#import "PBDiffWindowController.h"
12-
#import "PBRepositoryDocumentController.h"
12+
#import "PBGitRepository.h"
1313
#import "PBCloneRepositoryPanel.h"
1414

15+
#import <ObjectiveGit/GTRepository.h>
16+
1517

1618
@implementation NSApplication (GitXScripting)
1719

@@ -27,9 +29,24 @@ - (void)showDiffScriptCommand:(NSScriptCommand *)command
2729

2830
- (void)initRepositoryScriptCommand:(NSScriptCommand *)command
2931
{
32+
NSError *error = nil;
3033
NSURL *repositoryURL = [command directParameter];
31-
if (repositoryURL)
32-
[[PBRepositoryDocumentController sharedDocumentController] initNewRepositoryAtURL:repositoryURL];
34+
if (!repositoryURL)
35+
return;
36+
37+
BOOL success = [GTRepository initializeEmptyRepositoryAtURL:repositoryURL error:&error];
38+
if (!success) {
39+
NSLog(@"Failed to create repository at %@: %@", repositoryURL, error);
40+
return;
41+
}
42+
43+
[[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:repositoryURL
44+
display:YES
45+
completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error) {
46+
if (error) {
47+
NSLog(@"Failed to open repository at %@: %@", repositoryURL, error);
48+
}
49+
}];
3350
}
3451

3552
- (void)cloneRepositoryScriptCommand:(NSScriptCommand *)command

Classes/Views/PBCloneRepositoryPanel.m

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#import "PBCloneRepositoryPanel.h"
1010
#import "PBRemoteProgressSheet.h"
11-
#import "PBRepositoryDocumentController.h"
1211
#import "PBGitDefaults.h"
1312

1413

@@ -166,7 +165,7 @@ - (void) messageSheetDidEnd:(NSOpenPanel *)sheet returnCode:(NSInteger)code cont
166165
NSURL *documentURL = [NSURL fileURLWithPath:path];
167166

168167
NSError *error = nil;
169-
id document = [[PBRepositoryDocumentController sharedDocumentController] openDocumentWithContentsOfURL:documentURL display:YES error:&error];
168+
id document = [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:documentURL display:YES error:&error];
170169
if (!document && error)
171170
[self showErrorSheet:error];
172171
else {

Classes/git/PBGitRepository.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
@class GTConfiguration;
1616

1717
extern NSString* PBGitRepositoryErrorDomain;
18+
extern NSString *PBGitRepositoryDocumentType;
19+
1820
typedef enum branchFilterTypes {
1921
kGitXAllBranchesFilter = 0,
2022
kGitXLocalRemoteBranchesFilter,
@@ -133,7 +135,6 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
133135
- (NSString*) parseSymbolicReference:(NSString*) ref;
134136
- (NSString*) parseReference:(NSString*) ref;
135137

136-
- (id) initWithURL: (NSURL*) path;
137138
- (void) forceUpdateRevisions;
138139
- (NSURL*) getIndexURL;
139140

Classes/git/PBGitRepository.m

+2-23
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#import <ObjectiveGit/GTIndex.h>
2929
#import <ObjectiveGit/GTConfiguration.h>
3030

31+
NSString *PBGitRepositoryDocumentType = @"Git Repository";
32+
3133
@interface PBGitRepository ()
3234

3335
@property (nonatomic, strong) NSNumber *hasSVNRepoConfig;
@@ -136,29 +138,6 @@ - (void)close
136138
[super close];
137139
}
138140

139-
- (id) initWithURL: (NSURL*) path
140-
{
141-
if (![PBGitBinary path])
142-
return nil;
143-
144-
self = [self initWithContentsOfURL:path ofType:@"" error:NULL];
145-
if (!self)
146-
{
147-
NSLog(@"Failed to initWithURL:%@", path);
148-
return nil;
149-
}
150-
151-
// We don't want the window controller to display anything yet..
152-
// We'll leave that to the caller of this method.
153-
#ifndef CLI
154-
[self addWindowController:[[PBGitWindowController alloc] initWithRepository:self displayDefault:NO]];
155-
#endif
156-
157-
[self showWindows];
158-
159-
return self;
160-
}
161-
162141
- (void) forceUpdateRevisions
163142
{
164143
[revisionList forceUpdate];

0 commit comments

Comments
 (0)