-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added git_repository_open_ext wrapper #593
Conversation
/// +initWithURL:flags:ceilingDirs:error:. | ||
/// | ||
/// See respository.h for documentation of each individual flag. | ||
typedef NS_OPTIONS(UInt32, GTRepositoryOpenFlags) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NSInteger
instead of UInt32
. I think UInt32
comes from Carbon ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, UInt32
will not always be an unsigned int
. I guess I will just use an NSInteger
and down-cast it to an unsigned int
.
/// error - The error if one occurs. | ||
/// | ||
/// Returns the initialized repository, or nil if an error occurred. | ||
+ (nullable instancetype)initWithURL:(NSURL *)localFileURL flags:(UInt32)flags ceilingDirs:(nullable const char *)ceilingDirs error:(NSError **)error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initWith...
class-method is confusing. It should be named-repositoryWith...
instead.- Use the typedef name instead of
UInt32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const char *
isn't very Cocoa-y. What about passing anNSArray <NSURL *> *
and doing the conversion internally ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Others class-methods for
GTRepository
are usinginitWithURL:...
. It make sense for me to stay consistent. (Plus, I don't know howrepositoryWithURL...
will translate into Swift. I will experiment and see) NSArray <NSURL *> *
it is 😃
@@ -177,6 +181,22 @@ - (instancetype)initWithURL:(NSURL *)localFileURL error:(NSError **)error { | |||
return [self initWithGitRepository:r]; | |||
} | |||
|
|||
- (instancetype)initWithURL:(NSURL *)localFileURL flags:(UInt32)flags ceilingDirs:(const char *)ceilingDirs error:(NSError **)error { | |||
if (!localFileURL.isFileURL || localFileURL.path == nil) { | |||
if (error != NULL) *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnsupportedSchemeError userInfo:@{ NSLocalizedDescriptionKey: NSLocalizedString(@"Invalid file path URL to initialize repository.", @"") }]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NSFileWriteUnsupportedScheme
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy paste error. Will fix.
/// error - The error if one occurs. | ||
/// | ||
/// Returns the initialized repository, or nil if an error occurred. | ||
- (nullable instancetype)initWithURL:(NSURL *)localFileURL flags:(UInt32)flags ceilingDirs:(nullable const char *)ceilingDirs error:(NSError **)error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, having both a class and an instance method is unwarranted IMHO. I'd drop this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree on this one. I will remove the instance method. I only created this one for consistency with the rest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, is there any reason you would rather drop the instance initializer rather than the class initializer? Keeping the convenience instance initializer allows my Swift code to look cleaner: GTRepository(url: url, flags: 0, ceilingDirs: nil)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually, my Cocoa-fu says that convenience initializers get declared as class methods, designated initializers go under -init...
. Arguably, this one could be kept as a designated initializer (since it ends up calling one of the handful libgit2
functions that creates objects), but our designated initializer is actually initWithGitRepository:
.
I'm not sure how that would like after being Swift-preprocessed though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your input. Greatly appreciated.
/// +initWithURL:flags:ceilingDirs:error:. | ||
/// | ||
/// See respository.h for documentation of each individual flag. | ||
typedef NS_OPTIONS(UInt32, GTRepositoryOpenFlags) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, UInt32
will not always be an unsigned int
. I guess I will just use an NSInteger
and down-cast it to an unsigned int
.
/// error - The error if one occurs. | ||
/// | ||
/// Returns the initialized repository, or nil if an error occurred. | ||
- (nullable instancetype)initWithURL:(NSURL *)localFileURL flags:(UInt32)flags ceilingDirs:(nullable const char *)ceilingDirs error:(NSError **)error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree on this one. I will remove the instance method. I only created this one for consistency with the rest
@@ -177,6 +181,22 @@ - (instancetype)initWithURL:(NSURL *)localFileURL error:(NSError **)error { | |||
return [self initWithGitRepository:r]; | |||
} | |||
|
|||
- (instancetype)initWithURL:(NSURL *)localFileURL flags:(UInt32)flags ceilingDirs:(const char *)ceilingDirs error:(NSError **)error { | |||
if (!localFileURL.isFileURL || localFileURL.path == nil) { | |||
if (error != NULL) *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnsupportedSchemeError userInfo:@{ NSLocalizedDescriptionKey: NSLocalizedString(@"Invalid file path URL to initialize repository.", @"") }]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy paste error. Will fix.
/// error - The error if one occurs. | ||
/// | ||
/// Returns the initialized repository, or nil if an error occurred. | ||
+ (nullable instancetype)initWithURL:(NSURL *)localFileURL flags:(UInt32)flags ceilingDirs:(nullable const char *)ceilingDirs error:(NSError **)error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Others class-methods for
GTRepository
are usinginitWithURL:...
. It make sense for me to stay consistent. (Plus, I don't know howrepositoryWithURL...
will translate into Swift. I will experiment and see) NSArray <NSURL *> *
it is 😃
Any ideas how to fix Travis? |
The iOS tests are flaky, so (unless you happen to find a solution 😉 ), you're better off just making sure the macOS run is green. |
d15fb27
to
367ad42
Compare
Travis is still failing after rebase |
iOS is green, Mac is failing because of SSH check which is because of something else. So this should be good from a CI standpoint. |
Thanks for the PR 👾 |
Added a GTRepository convenience initializer to use git_repository_open_ext to permit "searching" from the given url.