Skip to content

Commit 4c5d171

Browse files
committed
Merge pull request #466 from libgit2/bump-libgit2
[WIP] Bump libgit2
2 parents c3188a4 + b48d617 commit 4c5d171

File tree

6 files changed

+44
-77
lines changed

6 files changed

+44
-77
lines changed

External/libgit2

Submodule libgit2 updated 1616 files

ObjectiveGit/GTDiffDelta.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ + (instancetype)diffDeltaFromBlob:(GTBlob *)oldBlob forPath:(NSString *)oldBlobP
7373
__block git_diff_delta diffDelta;
7474

7575
int returnValue = [GTDiff handleParsedOptionsDictionary:options usingBlock:^(git_diff_options *optionsStruct) {
76-
return git_diff_blobs(oldBlob.git_blob, oldBlobPath.UTF8String, newBlob.git_blob, newBlobPath.UTF8String, optionsStruct, &GTDiffDeltaCallback, NULL, NULL, &diffDelta);
76+
return git_diff_blobs(oldBlob.git_blob, oldBlobPath.UTF8String, newBlob.git_blob, newBlobPath.UTF8String, optionsStruct, &GTDiffDeltaCallback, NULL, NULL, NULL, &diffDelta);
7777
}];
7878

7979
if (returnValue != GIT_OK) {
@@ -94,7 +94,7 @@ + (instancetype)diffDeltaFromBlob:(GTBlob *)blob forPath:(NSString *)blobPath to
9494
__block git_diff_delta diffDelta;
9595

9696
int returnValue = [GTDiff handleParsedOptionsDictionary:options usingBlock:^(git_diff_options *optionsStruct) {
97-
return git_diff_blob_to_buffer(blob.git_blob, blobPath.UTF8String, data.bytes, data.length, dataPath.UTF8String, optionsStruct, &GTDiffDeltaCallback, NULL, NULL, &diffDelta);
97+
return git_diff_blob_to_buffer(blob.git_blob, blobPath.UTF8String, data.bytes, data.length, dataPath.UTF8String, optionsStruct, &GTDiffDeltaCallback, NULL, NULL, NULL, &diffDelta);
9898
}];
9999

100100
if (returnValue != GIT_OK) {
@@ -115,7 +115,7 @@ + (instancetype)diffDeltaFromData:(NSData *)oldData forPath:(NSString *)oldDataP
115115
__block git_diff_delta diffDelta;
116116

117117
int returnValue = [GTDiff handleParsedOptionsDictionary:options usingBlock:^(git_diff_options *optionsStruct) {
118-
return git_diff_buffers(oldData.bytes, oldData.length, oldDataPath.UTF8String, newData.bytes, newData.length, newDataPath.UTF8String, optionsStruct, &GTDiffDeltaCallback, NULL, NULL, &diffDelta);
118+
return git_diff_buffers(oldData.bytes, oldData.length, oldDataPath.UTF8String, newData.bytes, newData.length, newDataPath.UTF8String, optionsStruct, &GTDiffDeltaCallback, NULL, NULL, NULL, &diffDelta);
119119
}];
120120

121121
if (returnValue != GIT_OK) {

ObjectiveGit/GTRemote.m

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ - (NSString *)URLString {
115115
}
116116

117117
- (void)setURLString:(NSString *)URLString {
118-
git_remote_set_url(self.git_remote, URLString.UTF8String);
118+
git_remote_set_url(self.repository.git_repository, self.name.UTF8String, URLString.UTF8String);
119119
}
120120

121121
- (NSString *)pushURLString {
@@ -126,23 +126,7 @@ - (NSString *)pushURLString {
126126
}
127127

128128
- (void)setPushURLString:(NSString *)pushURLString {
129-
git_remote_set_pushurl(self.git_remote, pushURLString.UTF8String);
130-
}
131-
132-
- (BOOL)updatesFetchHead {
133-
return git_remote_update_fetchhead(self.git_remote) != 0;
134-
}
135-
136-
- (void)setUpdatesFetchHead:(BOOL)updatesFetchHead {
137-
git_remote_set_update_fetchhead(self.git_remote, updatesFetchHead);
138-
}
139-
140-
- (GTRemoteAutoTagOption)autoTag {
141-
return (GTRemoteAutoTagOption)git_remote_autotag(self.git_remote);
142-
}
143-
144-
- (void)setAutoTag:(GTRemoteAutoTagOption)autoTag {
145-
git_remote_set_autotag(self.git_remote, (git_remote_autotag_option_t)autoTag);
129+
git_remote_set_pushurl(self.repository.git_repository, self.name.UTF8String, pushURLString.UTF8String);
146130
}
147131

148132
- (BOOL)isConnected {
@@ -196,45 +180,34 @@ - (NSArray *)pushRefspecs {
196180

197181
#pragma mark Update the remote
198182

199-
- (BOOL)saveRemote:(NSError **)error {
200-
int gitError = git_remote_save(self.git_remote);
201-
if (gitError != GIT_OK) {
202-
if (error != NULL) {
203-
*error = [NSError git_errorFor:gitError description:@"Failed to save remote configuration."];
204-
}
205-
return NO;
206-
}
207-
return YES;
208-
}
209-
210183
- (BOOL)updateURLString:(NSString *)URLString error:(NSError **)error {
211184
NSParameterAssert(URLString != nil);
212185

213186
if ([self.URLString isEqualToString:URLString]) return YES;
214187

215-
int gitError = git_remote_set_url(self.git_remote, URLString.UTF8String);
188+
int gitError = git_remote_set_url(self.repository.git_repository, self.name.UTF8String, URLString.UTF8String);
216189
if (gitError != GIT_OK) {
217190
if (error != NULL) {
218191
*error = [NSError git_errorFor:gitError description:@"Failed to update remote URL string."];
219192
}
220193
return NO;
221194
}
222-
return [self saveRemote:error];
195+
return YES;
223196
}
224197

225198
- (BOOL)addFetchRefspec:(NSString *)fetchRefspec error:(NSError **)error {
226199
NSParameterAssert(fetchRefspec != nil);
227200

228201
if ([self.fetchRefspecs containsObject:fetchRefspec]) return YES;
229202

230-
int gitError = git_remote_add_fetch(self.git_remote, fetchRefspec.UTF8String);
203+
int gitError = git_remote_add_fetch(self.repository.git_repository, self.name.UTF8String, fetchRefspec.UTF8String);
231204
if (gitError != GIT_OK) {
232205
if (error != NULL) {
233206
*error = [NSError git_errorFor:gitError description:@"Failed to add fetch refspec."];
234207
}
235208
return NO;
236209
}
237-
return [self saveRemote:error];
210+
return YES;
238211
}
239212

240213
@end

ObjectiveGit/GTRepository+RemoteOperations.m

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
#import "git2/errors.h"
2323
#import "git2/remote.h"
24-
#import "git2/push.h"
2524

2625
NSString *const GTRepositoryRemoteOptionsCredentialProvider = @"GTRepositoryRemoteOptionsCredentialProvider";
2726

@@ -62,10 +61,10 @@ int GTRemotePushTransferProgressCallback(unsigned int current, unsigned int tota
6261
return (stop == YES ? GIT_EUSER : 0);
6362
}
6463

65-
#pragma mark -
66-
#pragma mark Fetch
64+
#pragma mark - Fetch
6765

6866
- (BOOL)fetchRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error:(NSError **)error progress:(GTRemoteFetchTransferProgressBlock)progressBlock {
67+
6968
GTCredentialProvider *credProvider = options[GTRepositoryRemoteOptionsCredentialProvider];
7069
GTRemoteConnectionInfo connectionInfo = {
7170
.credProvider = {credProvider},
@@ -79,14 +78,11 @@ - (BOOL)fetchRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error
7978
.payload = &connectionInfo,
8079
};
8180

82-
int gitError = git_remote_set_callbacks(remote.git_remote, &remote_callbacks);
83-
if (gitError != GIT_OK) {
84-
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to set callbacks on remote"];
85-
return NO;
86-
}
81+
git_fetch_options fetchOptions = GIT_FETCH_OPTIONS_INIT;
82+
fetchOptions.callbacks = remote_callbacks;
8783

8884
__block git_strarray refspecs;
89-
gitError = git_remote_get_fetch_refspecs(&refspecs, remote.git_remote);
85+
int gitError = git_remote_get_fetch_refspecs(&refspecs, remote.git_remote);
9086
if (gitError != GIT_OK) {
9187
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to get fetch refspecs for remote"];
9288
return NO;
@@ -96,7 +92,9 @@ - (BOOL)fetchRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error
9692
git_strarray_free(&refspecs);
9793
};
9894

99-
gitError = git_remote_fetch(remote.git_remote, &refspecs, NULL);
95+
NSString *reflog_message = [NSString stringWithFormat:@"fetching remote %@", remote.name];
96+
97+
gitError = git_remote_fetch(remote.git_remote, &refspecs, &fetchOptions, reflog_message.UTF8String);
10098
if (gitError != GIT_OK) {
10199
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to fetch from remote"];
102100
return NO;
@@ -105,8 +103,7 @@ - (BOOL)fetchRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error
105103
return YES;
106104
}
107105

108-
#pragma mark -
109-
#pragma mark Fetch Head enumeration
106+
#pragma mark - Fetch Head Enumeration
110107

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

@@ -210,6 +207,7 @@ - (BOOL)deleteBranch:(GTBranch *)branch fromRemote:(GTRemote *)remote withOption
210207
#pragma mark - Push (Private)
211208

212209
- (BOOL)pushRefspecs:(NSArray *)refspecs toRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error:(NSError **)error progress:(GTRemotePushTransferProgressBlock)progressBlock {
210+
213211
int gitError;
214212
GTCredentialProvider *credProvider = options[GTRepositoryRemoteOptionsCredentialProvider];
215213

@@ -224,21 +222,13 @@ - (BOOL)pushRefspecs:(NSArray *)refspecs toRemote:(GTRemote *)remote withOptions
224222
remote_callbacks.transfer_progress = GTRemoteFetchTransferProgressCallback,
225223
remote_callbacks.payload = &connectionInfo,
226224

227-
gitError = git_remote_set_callbacks(remote.git_remote, &remote_callbacks);
228-
if (gitError != GIT_OK) {
229-
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to set callbacks on remote"];
230-
return NO;
231-
}
232-
233-
gitError = git_remote_connect(remote.git_remote, GIT_DIRECTION_PUSH);
225+
gitError = git_remote_connect(remote.git_remote, GIT_DIRECTION_PUSH, &remote_callbacks);
234226
if (gitError != GIT_OK) {
235227
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to connect remote"];
236228
return NO;
237229
}
238230
@onExit {
239231
git_remote_disconnect(remote.git_remote);
240-
// Clear out callbacks by overwriting with an effectively empty git_remote_callbacks struct
241-
git_remote_set_callbacks(remote.git_remote, &((git_remote_callbacks)GIT_REMOTE_CALLBACKS_INIT));
242232
};
243233

244234
git_push_options push_options = GIT_PUSH_OPTIONS_INIT;
@@ -257,7 +247,12 @@ - (BOOL)pushRefspecs:(NSArray *)refspecs toRemote:(GTRemote *)remote withOptions
257247
return NO;
258248
}
259249

260-
gitError = git_remote_update_tips(remote.git_remote, NULL);
250+
int update_fetchhead = 1;
251+
// Ignored for push
252+
git_remote_autotag_option_t download_tags = GIT_REMOTE_DOWNLOAD_TAGS_FALLBACK;
253+
NSString *reflog_message = [NSString stringWithFormat:@"pushing remote %@", remote.name];
254+
255+
gitError = git_remote_update_tips(remote.git_remote, &remote_callbacks, update_fetchhead, download_tags, reflog_message.UTF8String);
261256
if (gitError != GIT_OK) {
262257
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Update tips failed"];
263258
return NO;

ObjectiveGit/GTRepository.m

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -212,19 +212,12 @@ static int transferProgressCallback(const git_transfer_progress *progress, void
212212
static int remoteCreate(git_remote **remote, git_repository *repo, const char *name, const char *url, void *payload)
213213
{
214214
int error;
215-
struct GTRemoteCreatePayload *pld = payload;
216-
git_remote_callbacks *callbacks = &pld->remoteCallbacks;
217-
218215
if ((error = git_remote_create(remote, repo, name, url)) < 0)
219216
return error;
220217

221-
return git_remote_set_callbacks(*remote, callbacks);
218+
return GIT_OK;
222219
}
223220

224-
struct GTRemoteCreatePayload {
225-
git_remote_callbacks remoteCallbacks;
226-
};
227-
228221
+ (instancetype)cloneFromURL:(NSURL *)originURL toWorkingDirectory:(NSURL *)workdirURL options:(NSDictionary *)options error:(NSError **)error transferProgressBlock:(void (^)(const git_transfer_progress *, BOOL *stop))transferProgressBlock checkoutProgressBlock:(void (^)(NSString *path, NSUInteger completedSteps, NSUInteger totalSteps))checkoutProgressBlock {
229222

230223
git_clone_options cloneOptions = GIT_CLONE_OPTIONS_INIT;
@@ -248,22 +241,19 @@ + (instancetype)cloneFromURL:(NSURL *)originURL toWorkingDirectory:(NSURL *)work
248241
.credProvider = {provider},
249242
};
250243

251-
cloneOptions.remote_callbacks.version = GIT_REMOTE_CALLBACKS_VERSION;
244+
git_fetch_options fetchOptions = GIT_FETCH_OPTIONS_INIT;
245+
fetchOptions.callbacks.version = GIT_REMOTE_CALLBACKS_VERSION;
252246

253247
if (provider) {
254-
cloneOptions.remote_callbacks.credentials = GTCredentialAcquireCallback;
248+
fetchOptions.callbacks.credentials = GTCredentialAcquireCallback;
255249
}
256250

257251
payload.transferProgressBlock = transferProgressBlock;
258252

259-
cloneOptions.remote_callbacks.transfer_progress = transferProgressCallback;
260-
cloneOptions.remote_callbacks.payload = &payload;
261-
262-
struct GTRemoteCreatePayload remoteCreatePayload;
263-
remoteCreatePayload.remoteCallbacks = cloneOptions.remote_callbacks;
264-
253+
fetchOptions.callbacks.transfer_progress = transferProgressCallback;
254+
fetchOptions.callbacks.payload = &payload;
255+
cloneOptions.fetch_opts = fetchOptions;
265256
cloneOptions.remote_cb = remoteCreate;
266-
cloneOptions.remote_cb_payload = &remoteCreatePayload;
267257

268258
BOOL localClone = [options[GTRepositoryCloneOptionsCloneLocal] boolValue];
269259
if (localClone) {
@@ -295,6 +285,8 @@ + (instancetype)cloneFromURL:(NSURL *)originURL toWorkingDirectory:(NSURL *)work
295285
}
296286

297287
return [[self alloc] initWithGitRepository:repository];
288+
289+
return nil;
298290
}
299291

300292
- (id)lookUpObjectByGitOid:(const git_oid *)oid objectType:(GTObjectType)type error:(NSError **)error {

ObjectiveGitTests/GTRemoteSpec.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616

1717
__block GTRemote *remote = nil;
1818
__block GTRepository *repository = nil;
19+
__block GTConfiguration *configuration = nil;
1920
NSString *fetchRefspec = @"+refs/heads/*:refs/remotes/origin/*";
2021

2122
beforeEach(^{
2223
repository = self.testAppFixtureRepository;
2324
expect(repository).notTo(beNil());
2425

2526
NSError *error = nil;
26-
GTConfiguration *configuration = [repository configurationWithError:&error];
27+
configuration = [repository configurationWithError:&error];
2728
expect(configuration).notTo(beNil());
2829
expect(error).to(beNil());
2930

@@ -53,6 +54,9 @@
5354
expect(@([remote updateURLString:newURLString error:&error])).to(beTruthy());
5455
expect(error).to(beNil());
5556

57+
// Reload remote from disk to pick up the change
58+
remote = configuration.remotes[0];
59+
5660
expect(remote.URLString).to(equal(newURLString));
5761
});
5862

@@ -65,6 +69,9 @@
6569
expect(@([remote addFetchRefspec:newFetchRefspec error:&error])).to(beTruthy());
6670
expect(error).to(beNil());
6771

72+
// Reload remote from disk to pick up the change
73+
remote = configuration.remotes[0];
74+
6875
expect(remote.fetchRefspecs).to(equal((@[ fetchRefspec, newFetchRefspec ])));
6976
});
7077
});

0 commit comments

Comments
 (0)