Skip to content

Commit 3139f2a

Browse files
authored
Merge pull request #102 from gitx/RemoveDeprecatedAPIshims
Remove deprecated API shims
2 parents ea0e07b + 55c7205 commit 3139f2a

14 files changed

Lines changed: 49 additions & 55 deletions

ObjectiveGit/Categories/NSData+Git.m

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,14 @@ + (instancetype)git_dataWithBuffer:(git_buf *)buffer {
3535

3636
if (buffer->size == 0) return [self data];
3737

38-
// Ensure that the buffer is actually allocated dynamically, not pointing to
39-
// some data which may disappear.
40-
if (git_buf_grow(buffer, 0) != GIT_OK) return nil;
41-
4238
NSData *data = [self dataWithBytesNoCopy:buffer->ptr length:buffer->size freeWhenDone:YES];
43-
*buffer = (git_buf)GIT_BUF_INIT_CONST(0, NULL);
39+
*buffer = (git_buf)GIT_BUF_INIT;
4440

4541
return data;
4642
}
4743

4844
- (git_buf)git_buf {
49-
return (git_buf)GIT_BUF_INIT_CONST((void *)self.bytes, self.length);
45+
return (git_buf){ (char *)self.bytes, 0, self.length };
5046
}
5147

5248
- (BOOL)git_containsNUL {

ObjectiveGit/GTBlob.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
#import "git2/blob.h"
3838
#import "git2/errors.h"
39-
#import "git2/deprecated.h"
4039

4140
@implementation GTBlob
4241

@@ -85,7 +84,7 @@ - (instancetype)initWithData:(NSData *)data inRepository:(GTRepository *)reposit
8584
NSParameterAssert(repository != nil);
8685

8786
git_oid oid;
88-
int gitError = git_blob_create_frombuffer(&oid, repository.git_repository, [data bytes], data.length);
87+
int gitError = git_blob_create_from_buffer(&oid, repository.git_repository, [data bytes], data.length);
8988
if(gitError < GIT_OK) {
9089
if(error != NULL) {
9190
*error = [NSError git_errorFor:gitError description:@"Failed to create blob from NSData"];
@@ -101,7 +100,7 @@ - (instancetype)initWithFile:(NSURL *)file inRepository:(GTRepository *)reposito
101100
NSParameterAssert(repository != nil);
102101

103102
git_oid oid;
104-
int gitError = git_blob_create_fromdisk(&oid, repository.git_repository, [[file path] fileSystemRepresentation]);
103+
int gitError = git_blob_create_from_disk(&oid, repository.git_repository, [[file path] fileSystemRepresentation]);
105104
if(gitError < GIT_OK) {
106105
if(error != NULL) {
107106
*error = [NSError git_errorFor:gitError description:@"Failed to create blob from NSURL"];
@@ -137,8 +136,9 @@ - (NSData *)data {
137136
- (NSData *)applyFiltersForPath:(NSString *)path error:(NSError **)error {
138137
NSCParameterAssert(path != nil);
139138

140-
git_buf buffer = GIT_BUF_INIT_CONST(0, NULL);
141-
int gitError = git_blob_filtered_content(&buffer, self.git_blob, path.UTF8String, 1);
139+
git_buf buffer = GIT_BUF_INIT;
140+
git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT;
141+
int gitError = git_blob_filter(&buffer, self.git_blob, path.UTF8String, &opts);
142142
if (gitError != GIT_OK) {
143143
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to apply filters for path %@ to blob", path];
144144
return nil;

ObjectiveGit/GTBranch.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#import "git2/branch.h"
3838
#import "git2/errors.h"
3939
#import "git2/graph.h"
40-
#import "git2/deprecated.h"
40+
#import "git2/buffer.h"
4141

4242
@implementation GTBranch
4343

@@ -116,7 +116,7 @@ - (GTOID *)OID {
116116
}
117117

118118
- (NSString *)remoteName {
119-
git_buf remote_name = GIT_BUF_INIT_CONST(0, NULL);
119+
git_buf remote_name = GIT_BUF_INIT;
120120
int gitError = git_branch_remote_name(&remote_name, self.repository.git_repository, self.reference.name.UTF8String);
121121
if (gitError != GIT_OK) return nil;
122122

ObjectiveGit/GTConfiguration.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#import "git2/config.h"
1818
#import "git2/errors.h"
1919
#import "git2/buffer.h"
20-
#import "git2/deprecated.h"
20+
#import "git2/strarray.h"
2121

2222
@interface GTConfiguration ()
2323
@property (nonatomic, readonly, assign) git_config *git_config;
@@ -144,7 +144,7 @@ - (NSArray *)remotes {
144144
}
145145
}
146146

147-
git_strarray_free(&names);
147+
git_strarray_dispose(&names);
148148

149149
return remotes;
150150
}

ObjectiveGit/GTCredential.m

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#import "NSError+Git.h"
1212

1313
#import "git2/errors.h"
14-
#import "git2/deprecated.h"
1514
#import "git2/sys/errors.h"
1615

1716
typedef GTCredential *(^GTCredentialProviderBlock)(GTCredentialType allowedTypes, NSString *URL, NSString *userName);
@@ -41,14 +40,14 @@ - (GTCredential *)credentialForType:(GTCredentialType)type URL:(NSString *)URL u
4140
@end
4241

4342
@interface GTCredential ()
44-
@property (nonatomic, assign, readonly) git_cred *git_cred;
43+
@property (nonatomic, assign, readonly) git_credential *git_cred;
4544
@end
4645

4746
@implementation GTCredential
4847

4948
+ (instancetype)credentialWithUserName:(NSString *)userName password:(NSString *)password error:(NSError **)error {
50-
git_cred *cred;
51-
int gitError = git_cred_userpass_plaintext_new(&cred, userName.UTF8String, password.UTF8String);
49+
git_credential *cred;
50+
int gitError = git_credential_userpass_plaintext_new(&cred, userName.UTF8String, password.UTF8String);
5251
if (gitError != GIT_OK) {
5352
if (error) *error = [NSError git_errorFor:gitError description:@"Failed to create credentials object" failureReason:@"There was an error creating a credential object for username %@.", userName];
5453
return nil;
@@ -63,8 +62,8 @@ + (instancetype)credentialWithUserName:(NSString *)userName publicKeyURL:(NSURL
6362
NSString *privateKeyPath = privateKeyURL.filePathURL.path;
6463
NSAssert(privateKeyPath != nil, @"Invalid file URL passed: %@", privateKeyURL);
6564

66-
git_cred *cred;
67-
int gitError = git_cred_ssh_key_new(&cred, userName.UTF8String, publicKeyPath.fileSystemRepresentation, privateKeyPath.fileSystemRepresentation, passphrase.UTF8String);
65+
git_credential *cred;
66+
int gitError = git_credential_ssh_key_new(&cred, userName.UTF8String, publicKeyPath.fileSystemRepresentation, privateKeyPath.fileSystemRepresentation, passphrase.UTF8String);
6867
if (gitError != GIT_OK) {
6968
if (error) *error = [NSError git_errorFor:gitError description:@"Failed to create credentials object" failureReason:@"There was an error creating a credential object for username %@ with the provided public/private key pair.\nPublic key: %@\nPrivate key: %@", userName, publicKeyURL, privateKeyURL];
7069
return nil;
@@ -76,8 +75,8 @@ + (instancetype)credentialWithUserName:(NSString *)userName publicKeyURL:(NSURL
7675
+ (instancetype)credentialWithUserName:(NSString *)userName publicKeyString:(NSString *)publicKeyString privateKeyString:(NSString *)privateKeyString passphrase:(NSString *)passphrase error:(NSError **)error {
7776
NSParameterAssert(privateKeyString != nil);
7877

79-
git_cred *cred;
80-
int gitError = git_cred_ssh_key_memory_new(&cred, userName.UTF8String, publicKeyString.UTF8String, privateKeyString.UTF8String, passphrase.UTF8String);
78+
git_credential *cred;
79+
int gitError = git_credential_ssh_key_memory_new(&cred, userName.UTF8String, publicKeyString.UTF8String, privateKeyString.UTF8String, passphrase.UTF8String);
8180
if (gitError != GIT_OK) {
8281
if (error) *error = [NSError git_errorFor:gitError description:@"Failed to create credentials object" failureReason:@"There was an error creating a credential object for username %@ with the provided public/private key pair.\nPublic key: %@", userName, publicKeyString];
8382
return nil;
@@ -86,7 +85,7 @@ + (instancetype)credentialWithUserName:(NSString *)userName publicKeyString:(NSS
8685
return [[self alloc] initWithGitCred:cred];
8786
}
8887

89-
- (instancetype)initWithGitCred:(git_cred *)cred {
88+
- (instancetype)initWithGitCred:(git_credential *)cred {
9089
NSParameterAssert(cred != nil);
9190
self = [self init];
9291

@@ -99,8 +98,8 @@ - (instancetype)initWithGitCred:(git_cred *)cred {
9998

10099
@end
101100

102-
int GTCredentialAcquireCallback(git_cred **git_cred, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload) {
103-
NSCParameterAssert(git_cred != NULL);
101+
int GTCredentialAcquireCallback(git_credential **cred, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload) {
102+
NSCParameterAssert(cred != NULL);
104103
NSCParameterAssert(payload != NULL);
105104

106105
GTCredentialAcquireCallbackInfo *info = payload;
@@ -114,12 +113,12 @@ int GTCredentialAcquireCallback(git_cred **git_cred, const char *url, const char
114113
NSString *URL = (url != NULL ? @(url) : @"");
115114
NSString *userName = (username_from_url != NULL ? @(username_from_url) : nil);
116115

117-
GTCredential *cred = [provider credentialForType:(GTCredentialType)allowed_types URL:URL userName:userName];
118-
if (cred == nil) {
116+
GTCredential *gtCred = [provider credentialForType:(GTCredentialType)allowed_types URL:URL userName:userName];
117+
if (gtCred == nil) {
119118
git_error_set_str(GIT_EUSER, "GTCredentialProvider failed to provide credentials.");
120119
return GIT_ERROR;
121120
}
122121

123-
*git_cred = cred.git_cred;
122+
*cred = gtCred.git_cred;
124123
return GIT_OK;
125124
}

ObjectiveGit/GTDiff.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#import "EXTScope.h"
1919

2020
#import "git2/errors.h"
21-
#import "git2/deprecated.h"
21+
#import "git2/strarray.h"
2222

2323
NSString *const GTDiffOptionsFlagsKey = @"GTDiffOptionsFlagsKey";
2424
NSString *const GTDiffOptionsContextLinesKey = @"GTDiffOptionsContextLinesKey";
@@ -72,7 +72,7 @@ + (int)handleParsedOptionsDictionary:(NSDictionary *)dictionary usingBlock:(int
7272
git_strarray strArray = pathSpec.git_strarray;
7373
if (pathSpec != nil) newOptions.pathspec = strArray;
7474
@onExit {
75-
git_strarray_free((git_strarray *)&strArray);
75+
git_strarray_dispose((git_strarray *)&strArray);
7676
};
7777

7878
git_diff_options *optionsPtr = &newOptions;

ObjectiveGit/GTDiffPatch.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#import "GTDiffPatch.h"
1010

1111
#import "GTDiffHunk.h"
12-
#import "git2/deprecated.h"
12+
#import "git2/buffer.h"
1313

1414
@interface GTDiffPatch ()
1515

@@ -66,7 +66,7 @@ - (NSUInteger)sizeWithContext:(BOOL)includeContext hunkHeaders:(BOOL)includeHunk
6666
}
6767

6868
- (NSData *)patchData {
69-
git_buf buf = GIT_BUF_INIT_CONST(0, NULL);
69+
git_buf buf = GIT_BUF_INIT;
7070
git_patch_to_buf(&buf, self.git_patch);
7171

7272
NSData *buffer = [[NSData alloc] initWithBytes:buf.ptr length:buf.size];

ObjectiveGit/GTFilterList.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#import "NSError+Git.h"
1515

1616
#import "git2/errors.h"
17-
#import "git2/deprecated.h"
17+
#import "git2/buffer.h"
1818

1919
@interface GTFilterList ()
2020

@@ -54,9 +54,8 @@ - (void)dealloc {
5454
- (NSData *)applyToData:(NSData *)inputData error:(NSError **)error {
5555
NSParameterAssert(inputData != nil);
5656

57-
git_buf input = inputData.git_buf;
58-
git_buf output = GIT_BUF_INIT_CONST(0, NULL);
59-
int gitError = git_filter_list_apply_to_data(&output, self.git_filter_list, &input);
57+
git_buf output = GIT_BUF_INIT;
58+
int gitError = git_filter_list_apply_to_buffer(&output, self.git_filter_list, inputData.bytes, inputData.length);
6059

6160
if (gitError != GIT_OK) {
6261
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to apply filter list to data buffer"];
@@ -70,7 +69,7 @@ - (NSData *)applyToPath:(NSString *)relativePath inRepository:(GTRepository *)re
7069
NSParameterAssert(relativePath != nil);
7170
NSParameterAssert(repository != nil);
7271

73-
git_buf output = GIT_BUF_INIT_CONST(0, NULL);
72+
git_buf output = GIT_BUF_INIT;
7473
// fixme: This is a workaround for an issue where `git_filter_list_apply_to_file`
7574
// will not resolve relative paths against the worktree. It should be reverted when
7675
// libgit2 has been updated to resolve that.
@@ -88,7 +87,7 @@ - (NSData *)applyToPath:(NSString *)relativePath inRepository:(GTRepository *)re
8887
- (NSData *)applyToBlob:(GTBlob *)blob error:(NSError **)error {
8988
NSParameterAssert(blob != nil);
9089

91-
git_buf output = GIT_BUF_INIT_CONST(0, NULL);
90+
git_buf output = GIT_BUF_INIT;
9291
int gitError = git_filter_list_apply_to_blob(&output, self.git_filter_list, blob.git_blob);
9392

9493
if (gitError != GIT_OK) {

ObjectiveGit/GTIndex.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#import "NSError+Git.h"
4242

4343
#import "git2/errors.h"
44-
#import "git2/deprecated.h"
44+
#import "git2/index.h"
4545

4646
// The block synonymous with libgit2's `git_index_matched_path_cb` callback.
4747
typedef BOOL (^GTIndexPathspecMatchedBlock)(NSString *matchedPathspec, NSString *path, BOOL *stop);
@@ -197,7 +197,7 @@ - (BOOL)addData:(NSData *)data withPath:(NSString *)path error:(NSError **)error
197197
entry.path = [path cStringUsingEncoding:NSUTF8StringEncoding];
198198
entry.mode = GIT_FILEMODE_BLOB;
199199

200-
int status = git_index_add_frombuffer(self.git_index, &entry, [data bytes], [data length]);
200+
int status = git_index_add_from_buffer(self.git_index, &entry, [data bytes], [data length]);
201201

202202
if (status != GIT_OK) {
203203
if (error != NULL) *error = [NSError git_errorFor:status description:@"Failed to add data with name %@ into index.", path];

ObjectiveGit/GTOID.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#import "git2/errors.h"
1313
#import "git2/odb.h"
14-
#import "git2/deprecated.h"
1514

1615
@interface GTOID () {
1716
git_oid _git_oid;
@@ -30,7 +29,7 @@ - (const git_oid *)git_oid {
3029
- (NSString *)SHA {
3130
char *SHA = git_oid_tostr_s(self.git_oid);
3231
NSString *str = [[NSString alloc] initWithBytes:SHA
33-
length:GIT_OID_HEXSZ
32+
length:GIT_OID_SHA1_HEXSIZE
3433
encoding:NSUTF8StringEncoding];
3534
NSAssert(str != nil, @"Failed to create SHA string");
3635
return str;
@@ -110,7 +109,7 @@ - (NSString *)description {
110109

111110
- (NSUInteger)hash {
112111
// Hash the raw OID.
113-
NSData *data = [[NSData alloc] initWithBytesNoCopy:_git_oid.id length:GIT_OID_RAWSZ freeWhenDone:NO];
112+
NSData *data = [[NSData alloc] initWithBytesNoCopy:_git_oid.id length:GIT_OID_SHA1_SIZE freeWhenDone:NO];
114113
return data.hash;
115114
}
116115

0 commit comments

Comments
 (0)