Permalink
Browse files

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
  • Loading branch information...
1 parent fa6182e commit fa6ff44d0b219db90051ad56123bdd0761212653 Pieter de Bie committed Jun 20, 2009
Showing with 16 additions and 17 deletions.
  1. +16 −17 PBGitRepository.m
View
@@ -78,8 +78,6 @@ + (NSURL*)baseDirForURL:(NSURL*)repositoryURL;
//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 @@ - (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSEr
}
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

0 comments on commit fa6ff44

Please sign in to comment.