Skip to content

Commit fa6ff44

Browse files
author
Pieter de Bie
committed
PBGitRepository: Clean up the readFromURL: method
We used a BOOL value which was returned afterwards, but we might as well just return early and simplify everything
1 parent fa6182e commit fa6ff44

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

PBGitRepository.m

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ + (NSURL*)baseDirForURL:(NSURL*)repositoryURL;
7878
//this works much better.
7979
- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
8080
{
81-
BOOL success = NO;
82-
8381
if (![PBGitBinary path])
8482
{
8583
if (outError) {
@@ -89,32 +87,33 @@ - (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSEr
8987
}
9088
return NO;
9189
}
92-
BOOL lIsDirectory = FALSE;
93-
[[NSFileManager defaultManager] fileExistsAtPath:[absoluteURL path] isDirectory:&lIsDirectory];
94-
if (!lIsDirectory) {
90+
91+
BOOL isDirectory = FALSE;
92+
[[NSFileManager defaultManager] fileExistsAtPath:[absoluteURL path] isDirectory:&isDirectory];
93+
if (!isDirectory) {
9594
if (outError) {
9695
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:@"Reading files is not supported."
9796
forKey:NSLocalizedRecoverySuggestionErrorKey];
9897
*outError = [NSError errorWithDomain:PBGitRepositoryErrorDomain code:0 userInfo:userInfo];
9998
}
100-
} else {
101-
NSURL* gitDirURL = [PBGitRepository gitDirForURL:[self fileURL]];
102-
if (gitDirURL) {
103-
[self setFileURL:gitDirURL];
104-
success = YES;
105-
} else if (outError) {
99+
return NO;
100+
}
101+
102+
103+
NSURL* gitDirURL = [PBGitRepository gitDirForURL:[self fileURL]];
104+
if (!gitDirURL) {
105+
if (outError) {
106106
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%@ does not appear to be a git repository.", [self fileName]]
107107
forKey:NSLocalizedRecoverySuggestionErrorKey];
108108
*outError = [NSError errorWithDomain:PBGitRepositoryErrorDomain code:0 userInfo:userInfo];
109109
}
110-
111-
if (success) {
112-
[self setup];
113-
[self readCurrentBranch];
114-
}
110+
return NO;
115111
}
116112

117-
return success;
113+
[self setFileURL:gitDirURL];
114+
[self setup];
115+
[self readCurrentBranch];
116+
return YES;
118117
}
119118

120119
- (void) setup

0 commit comments

Comments
 (0)