Skip to content
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

Merged
merged 3 commits into from
Oct 31, 2016

Conversation

glegrain
Copy link
Contributor

@glegrain glegrain commented Oct 8, 2016

Added a GTRepository convenience initializer to use git_repository_open_ext to permit "searching" from the given url.

/// +initWithURL:flags:ceilingDirs:error:.
///
/// See respository.h for documentation of each individual flag.
typedef NS_OPTIONS(UInt32, GTRepositoryOpenFlags) {
Copy link
Contributor

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 ?

Copy link
Contributor Author

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;
Copy link
Contributor

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

Copy link
Contributor

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 an NSArray <NSURL *> * and doing the conversion internally ?

Copy link
Contributor Author

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 using initWithURL:.... It make sense for me to stay consistent. (Plus, I don't know how repositoryWithURL... 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.", @"") }];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NSFileWriteUnsupportedScheme ?

Copy link
Contributor Author

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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)

Copy link
Contributor

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.

Copy link
Contributor Author

@glegrain glegrain left a 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) {
Copy link
Contributor Author

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;
Copy link
Contributor Author

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.", @"") }];
Copy link
Contributor Author

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;
Copy link
Contributor Author

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 using initWithURL:.... It make sense for me to stay consistent. (Plus, I don't know how repositoryWithURL... will translate into Swift. I will experiment and see)
  • NSArray <NSURL *> * it is 😃

@glegrain
Copy link
Contributor Author

Any ideas how to fix Travis?

@tiennou
Copy link
Contributor

tiennou commented Oct 11, 2016

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.

@pietbrauer
Copy link
Member

@glegrain Could you rebase onto master and see if the tests run through? #591 might have fixed the iOS tests, which now also run on Xcode 8

@glegrain glegrain force-pushed the git_repository_open_ext branch from d15fb27 to 367ad42 Compare October 31, 2016 13:22
@glegrain
Copy link
Contributor Author

Travis is still failing after rebase

@pietbrauer
Copy link
Member

pietbrauer commented Oct 31, 2016

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.

@pietbrauer pietbrauer merged commit 614bce9 into libgit2:master Oct 31, 2016
@pietbrauer
Copy link
Member

Thanks for the PR 👾

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants