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
This commit is contained in:
Pieter de Bie
2009-06-20 21:26:59 +01:00
parent fa6182e2a4
commit fa6ff44d0b
+16 -17
View File
@@ -78,8 +78,6 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
//this works much better.
- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
{
BOOL success = NO;
if (![PBGitBinary path])
{
if (outError) {
@@ -89,32 +87,33 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
}
return NO;
}
BOOL lIsDirectory = FALSE;
[[NSFileManager defaultManager] fileExistsAtPath:[absoluteURL path] isDirectory:&lIsDirectory];
if (!lIsDirectory) {
BOOL isDirectory = FALSE;
[[NSFileManager defaultManager] fileExistsAtPath:[absoluteURL path] isDirectory:&isDirectory];
if (!isDirectory) {
if (outError) {
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:@"Reading files is not supported."
forKey:NSLocalizedRecoverySuggestionErrorKey];
*outError = [NSError errorWithDomain:PBGitRepositoryErrorDomain code:0 userInfo:userInfo];
}
} else {
NSURL* gitDirURL = [PBGitRepository gitDirForURL:[self fileURL]];
if (gitDirURL) {
[self setFileURL:gitDirURL];
success = YES;
} else if (outError) {
return NO;
}
NSURL* gitDirURL = [PBGitRepository gitDirForURL:[self fileURL]];
if (!gitDirURL) {
if (outError) {
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%@ does not appear to be a git repository.", [self fileName]]
forKey:NSLocalizedRecoverySuggestionErrorKey];
*outError = [NSError errorWithDomain:PBGitRepositoryErrorDomain code:0 userInfo:userInfo];
}
if (success) {
[self setup];
[self readCurrentBranch];
}
return NO;
}
return success;
[self setFileURL:gitDirURL];
[self setup];
[self readCurrentBranch];
return YES;
}
- (void) setup