-
Notifications
You must be signed in to change notification settings - Fork 281
Fetch support. #224
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
Fetch support. #224
Changes from 1 commit
132f488
9683b82
8ddbf4d
e219d96
25ac41d
69a6870
32e16dd
32d431c
b1e068c
9ae2de9
99fd4f8
9147337
fe0fcd4
f1e0fed
1f4a741
b66841d
b78b7a7
132d34b
085bfcd
53e72ac
9b24687
016e600
326c2a1
3e3741d
dbeb1c7
951f2d3
2a52a5a
df7797b
6a5962e
2da274b
264e432
315c7fc
82ef2b4
e9eb978
6ec740c
d8f467c
48cb468
30466af
95b4397
1be6929
36b83c0
7dce701
df9e8f7
0ca55db
89435cd
958de2c
c0cddf8
7e8d9c1
e5c6f1e
8be93a4
95be58a
921b3cf
4c8b62e
cb4a418
358c700
69073fd
da4acdd
3597084
3820fbd
d04f203
3b46ae3
e94e011
a14aaea
46f73ae
fcaee88
d31823d
e38111a
01fbe83
a2c219c
055425d
6422662
8385bca
9051caf
7944375
c18ad46
300422f
ed50421
2561348
36dc5f4
f82ac62
321d1a3
f7a63f5
aa41ad5
6ac1d81
ee4a798
564e3b3
dff9ece
393d9b6
9e656fc
b00bd04
f550b23
dbe3571
a8939d3
b2aa3c1
fe64125
749bae7
bb31e14
f7e65e5
34ba3fc
2b1b414
4ff2704
545424d
6ae8d4c
0416a80
fe53e2b
5154b01
9721263
ee395c1
8eccf6d
073dc08
6389d67
d9ddd3b
1070b18
cf17a4b
1510cea
401bf3d
7f223a9
defc906
6f48fe8
e4d9317
9861940
aa67fc5
f36fc31
f35af60
503fe77
64c09d6
b27d70c
c4da29f
8fb43d7
c033c41
66825b7
a425175
6a2eb3e
ffbcc17
9f408ac
f51b848
2f8160c
d3f4cca
5f0b899
3b739da
e5f1bb4
f934b16
37107c8
06295d3
47706f5
5533868
7b7f600
b9b0594
2593ebb
f3e1380
fc766f4
e79a88a
fc6efba
741a444
5ed28b8
0489bd8
5f363f7
4c00640
b2887f7
6385b01
60de3e3
f01278a
7160ff1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ typedef enum { | |
@property (nonatomic, readonly, strong) GTRepository *repository; | ||
@property (nonatomic, readonly, copy) NSString *name; | ||
@property (nonatomic, readonly, copy) NSString *URLString; | ||
@property (nonatomic, readonly, getter = isConnected) BOOL connected; | ||
@property (nonatomic, readonly, getter=isConnected) BOOL connected; | ||
|
||
|
||
+ (instancetype)remoteWithName:(NSString *)name inRepository:(GTRepository *)repo; | ||
|
@@ -40,8 +40,7 @@ typedef enum { | |
// The underlying `git_remote` object. | ||
- (git_remote *)git_remote __attribute__((objc_returns_inner_pointer)); | ||
|
||
- (BOOL)fetchWithError:(NSError **)error credentials:(int (^)(git_cred **cred, GTCredentialType allowedTypes, NSURL *url))credBlock progress:(void (^)(NSString *message, int length))progressBlock completion:(int (^)(GTRemoteCompletionType type))completionBlock updateTips:(int (^)(GTReference *ref, GTOID *a, GTOID *b))updateTipsBlock; | ||
|
||
- (void)stop; | ||
- (BOOL)fetchWithError:(NSError **)error credentials:(int (^)(git_cred **cred, GTCredentialType allowedTypes, NSString *url, NSString *username))credBlock progress:(void (^)(NSString *message, int length))progressBlock completion:(int (^)(GTRemoteCompletionType type))completionBlock updateTips:(int (^)(GTReference *ref, GTOID *a, GTOID *b))updateTipsBlock; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think the credential block needs a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's more or less what I was saying ;-). I'll add |
||
|
||
- (void)cancelOperation; | ||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,13 @@ | |
#import "NSError+Git.h" | ||
|
||
@interface GTRemote () { | ||
GTRepository *repository; | ||
GTRepository *_repository; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be necessary. The property should be automatically synthesized, even if it's read-only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I found I needed to redeclare the property without |
||
} | ||
@property (nonatomic, readonly, assign) git_remote *git_remote; | ||
@end | ||
|
||
@implementation GTRemote | ||
@synthesize repository; | ||
|
||
- (void)dealloc { | ||
if (_git_remote != NULL) git_remote_free(_git_remote); | ||
|
@@ -41,18 +42,22 @@ + (instancetype)remoteWithName:(NSString *)name inRepository:(GTRepository *)rep | |
} | ||
|
||
- (instancetype)initWithName:(NSString *)name inRepository:(GTRepository *)repo { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should assert that these arguments aren't |
||
NSParameterAssert(name != nil); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just thought about something. Aren't asserts a little heavy-handed here ? Because as an app developer I would prefer to just call that method (and the others above) with whatever the user passed in (from a sheet or something), and being kindly returned There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A This matches the convention of many Foundation constructors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh, you're right ;-). I didn't think hard enough, but doing |
||
NSParameterAssert(repository != nil); | ||
|
||
self = [super init]; | ||
if (self == nil) return nil; | ||
|
||
int gitError = git_remote_load(&_git_remote, repo.git_repository, name.UTF8String); | ||
if (gitError != GIT_OK) return nil; | ||
|
||
repository = repo; | ||
_repository = repo; | ||
|
||
return self; | ||
} | ||
|
||
- (id)initWithGitRemote:(git_remote *)remote { | ||
NSParameterAssert(remote != NULL); | ||
self = [super init]; | ||
if (self == nil) return nil; | ||
|
||
|
@@ -62,10 +67,10 @@ - (id)initWithGitRemote:(git_remote *)remote { | |
} | ||
|
||
- (GTRepository *)repository { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This definition is unnecessary. |
||
if (repository == nil) { | ||
repository = [[GTRepository alloc] initWithGitRepository:git_remote_owner(self.git_remote)]; | ||
if (_repository == nil) { | ||
_repository = [[GTRepository alloc] initWithGitRepository:git_remote_owner(self.git_remote)]; | ||
} | ||
return repository; | ||
return _repository; | ||
} | ||
|
||
- (NSString *)name { | ||
|
@@ -84,7 +89,7 @@ - (NSString *)URLString { | |
|
||
#pragma mark Fetch | ||
|
||
typedef int (^GTCredentialAcquireBlock)(git_cred **cred, GTCredentialType allowedTypes, NSURL *url); | ||
typedef int (^GTCredentialAcquireBlock)(git_cred **cred, GTCredentialType allowedTypes, NSString *url, NSString *username); | ||
|
||
typedef void (^GTRemoteFetchProgressBlock)(NSString *message, int length); | ||
|
||
|
@@ -100,7 +105,7 @@ - (NSString *)URLString { | |
__unsafe_unretained GTRemoteFetchUpdateTipsBlock updateTipsBlock; | ||
} GTRemoteFetchInfo; | ||
|
||
static int fetch_cred_acquire_cb(git_cred **cred, const char *urlStr, const char *username_from_url, unsigned int allowed_types, void *payload) { | ||
static int fetch_cred_acquire_cb(git_cred **cred, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload) { | ||
GTRemoteFetchInfo *info = (GTRemoteFetchInfo *)payload; | ||
|
||
if (info->credBlock == nil) { | ||
|
@@ -109,10 +114,7 @@ static int fetch_cred_acquire_cb(git_cred **cred, const char *urlStr, const char | |
return GIT_ERROR; | ||
} | ||
|
||
NSURL *url = [NSURL URLWithString:@(urlStr)]; | ||
NSCAssert(url != nil, @"Failed to convert %s to an URL", urlStr); | ||
|
||
return info->credBlock(cred, (GTCredentialType)allowed_types, url); | ||
return info->credBlock(cred, (GTCredentialType)allowed_types, @(url), @(username_from_url)); | ||
} | ||
|
||
static void fetch_progress(const char *str, int len, void *payload) { | ||
|
@@ -190,7 +192,7 @@ - (BOOL)fetchWithError:(NSError **)error credentials:(GTCredentialAcquireBlock)c | |
return YES; | ||
} | ||
|
||
- (void)stop { | ||
- (void)cancelOperation { | ||
git_remote_stop(self.git_remote); | ||
} | ||
|
||
|
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.
Is there a libgit2 API for this instead?
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.
Not that I can see, but there's a
git_branch_remote_name
that could be used in-remoteName
instead of fiddling with strings.In fact, this could be changed to use
git_remote_load
... But this raises a question : is it preferred to use Obj-C when possible, or should I always resort tolibgit2
? I would have a preference for the former (which is why I did that way), as it better insulates us from API changes — only one place to fix in case there's rumble ;-).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.
It's hard to make a general call one way or the other.
In this specific case, I'd say that our
remoteName
parsing is pretty scary, and more liable to break from libgit2 changes than a lookup function.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.
Wait, I don't follow anymore ;-). I say keep
-remote
like that, so the remote loading part gets written once inGTRemote
.About
-remoteName
,libgit2
branch API hasgit_branch_name
,git_branch_remote_name
andgit_branch_upstream_name
. I can switch-remoteName
to any of those calls, but I'm not a git-expert enough to know the actual difference betweenremote
&upstream
. I expectgit_branch_name
to return the path inrefs
, and it seems that's what it does since we're munging the path afterwards.