Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update fetch and push with new API for callbacks
  • Loading branch information
phatblat committed Jun 22, 2015
commit 9ad1a94949bad0b728dd6e4b039fed5cc37ba7b1
40 changes: 19 additions & 21 deletions ObjectiveGit/GTRepository+RemoteOperations.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ int GTRemotePushTransferProgressCallback(unsigned int current, unsigned int tota
return (stop == YES ? GIT_EUSER : 0);
}

#pragma mark -
#pragma mark Fetch
#pragma mark - Fetch

- (BOOL)fetchRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error:(NSError **)error progress:(GTRemoteFetchTransferProgressBlock)progressBlock {
#if 0

GTCredentialProvider *credProvider = options[GTRepositoryRemoteOptionsCredentialProvider];
GTRemoteConnectionInfo connectionInfo = {
.credProvider = {credProvider},
Expand All @@ -79,12 +78,15 @@ - (BOOL)fetchRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error
.payload = &connectionInfo,
};

int gitError = git_remote_set_callbacks(remote.git_remote, &remote_callbacks);
git_fetch_options fetch_options;
int gitError = git_fetch_init_options(&fetch_options, GIT_FETCH_OPTIONS_VERSION);
if (gitError != GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to set callbacks on remote"];
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to init fetch options"];
return NO;
}

fetch_options.callbacks = remote_callbacks;

__block git_strarray refspecs;
gitError = git_remote_get_fetch_refspecs(&refspecs, remote.git_remote);
if (gitError != GIT_OK) {
Expand All @@ -96,18 +98,18 @@ - (BOOL)fetchRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error
git_strarray_free(&refspecs);
};

gitError = git_remote_fetch(remote.git_remote, &refspecs, NULL);
NSString *reflog_message = [NSString stringWithFormat:@"fetching remote %@", remote.name];

gitError = git_remote_fetch(remote.git_remote, &refspecs, &fetch_options, reflog_message.UTF8String);
if (gitError != GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to fetch from remote"];
return NO;
}
#endif

return YES;
}

#pragma mark -
#pragma mark Fetch Head enumeration
#pragma mark - Fetch Head Enumeration

typedef void (^GTRemoteEnumerateFetchHeadEntryBlock)(GTFetchHeadEntry *entry, BOOL *stop);

Expand Down Expand Up @@ -211,7 +213,7 @@ - (BOOL)deleteBranch:(GTBranch *)branch fromRemote:(GTRemote *)remote withOption
#pragma mark - Push (Private)

- (BOOL)pushRefspecs:(NSArray *)refspecs toRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error:(NSError **)error progress:(GTRemotePushTransferProgressBlock)progressBlock {
#if 0

int gitError;
GTCredentialProvider *credProvider = options[GTRepositoryRemoteOptionsCredentialProvider];

Expand All @@ -226,21 +228,13 @@ - (BOOL)pushRefspecs:(NSArray *)refspecs toRemote:(GTRemote *)remote withOptions
remote_callbacks.transfer_progress = GTRemoteFetchTransferProgressCallback,
remote_callbacks.payload = &connectionInfo,

gitError = git_remote_set_callbacks(remote.git_remote, &remote_callbacks);
if (gitError != GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to set callbacks on remote"];
return NO;
}

gitError = git_remote_connect(remote.git_remote, GIT_DIRECTION_PUSH);
gitError = git_remote_connect(remote.git_remote, GIT_DIRECTION_PUSH, &remote_callbacks);
if (gitError != GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to connect remote"];
return NO;
}
@onExit {
git_remote_disconnect(remote.git_remote);
// Clear out callbacks by overwriting with an effectively empty git_remote_callbacks struct
git_remote_set_callbacks(remote.git_remote, &((git_remote_callbacks)GIT_REMOTE_CALLBACKS_INIT));
};

git_push_options push_options = GIT_PUSH_OPTIONS_INIT;
Expand All @@ -259,12 +253,16 @@ - (BOOL)pushRefspecs:(NSArray *)refspecs toRemote:(GTRemote *)remote withOptions
return NO;
}

gitError = git_remote_update_tips(remote.git_remote, NULL);
int update_fetchhead = 1;
// Ignored for push
git_remote_autotag_option_t download_tags = GIT_REMOTE_DOWNLOAD_TAGS_FALLBACK;
NSString *reflog_message = [NSString stringWithFormat:@"pushing remote %@", remote.name];

gitError = git_remote_update_tips(remote.git_remote, &remote_callbacks, update_fetchhead, download_tags, reflog_message.UTF8String);
if (gitError != GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Update tips failed"];
return NO;
}
#endif

return YES;
}
Expand Down