diff --git a/ObjectiveGit/Categories/NSData+Git.m b/ObjectiveGit/Categories/NSData+Git.m index 9d02e6ed..42d31f21 100644 --- a/ObjectiveGit/Categories/NSData+Git.m +++ b/ObjectiveGit/Categories/NSData+Git.m @@ -35,18 +35,14 @@ + (instancetype)git_dataWithBuffer:(git_buf *)buffer { if (buffer->size == 0) return [self data]; - // Ensure that the buffer is actually allocated dynamically, not pointing to - // some data which may disappear. - if (git_buf_grow(buffer, 0) != GIT_OK) return nil; - NSData *data = [self dataWithBytesNoCopy:buffer->ptr length:buffer->size freeWhenDone:YES]; - *buffer = (git_buf)GIT_BUF_INIT_CONST(0, NULL); + *buffer = (git_buf)GIT_BUF_INIT; return data; } - (git_buf)git_buf { - return (git_buf)GIT_BUF_INIT_CONST((void *)self.bytes, self.length); + return (git_buf){ (char *)self.bytes, 0, self.length }; } - (BOOL)git_containsNUL { diff --git a/ObjectiveGit/GTBlob.m b/ObjectiveGit/GTBlob.m index c4988109..0bffe622 100644 --- a/ObjectiveGit/GTBlob.m +++ b/ObjectiveGit/GTBlob.m @@ -36,7 +36,6 @@ #import "git2/blob.h" #import "git2/errors.h" -#import "git2/deprecated.h" @implementation GTBlob @@ -85,7 +84,7 @@ - (instancetype)initWithData:(NSData *)data inRepository:(GTRepository *)reposit NSParameterAssert(repository != nil); git_oid oid; - int gitError = git_blob_create_frombuffer(&oid, repository.git_repository, [data bytes], data.length); + int gitError = git_blob_create_from_buffer(&oid, repository.git_repository, [data bytes], data.length); if(gitError < GIT_OK) { if(error != NULL) { *error = [NSError git_errorFor:gitError description:@"Failed to create blob from NSData"]; @@ -101,7 +100,7 @@ - (instancetype)initWithFile:(NSURL *)file inRepository:(GTRepository *)reposito NSParameterAssert(repository != nil); git_oid oid; - int gitError = git_blob_create_fromdisk(&oid, repository.git_repository, [[file path] fileSystemRepresentation]); + int gitError = git_blob_create_from_disk(&oid, repository.git_repository, [[file path] fileSystemRepresentation]); if(gitError < GIT_OK) { if(error != NULL) { *error = [NSError git_errorFor:gitError description:@"Failed to create blob from NSURL"]; @@ -137,8 +136,9 @@ - (NSData *)data { - (NSData *)applyFiltersForPath:(NSString *)path error:(NSError **)error { NSCParameterAssert(path != nil); - git_buf buffer = GIT_BUF_INIT_CONST(0, NULL); - int gitError = git_blob_filtered_content(&buffer, self.git_blob, path.UTF8String, 1); + git_buf buffer = GIT_BUF_INIT; + git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT; + int gitError = git_blob_filter(&buffer, self.git_blob, path.UTF8String, &opts); if (gitError != GIT_OK) { if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to apply filters for path %@ to blob", path]; return nil; diff --git a/ObjectiveGit/GTBranch.m b/ObjectiveGit/GTBranch.m index 9cbbf7c3..c362218f 100644 --- a/ObjectiveGit/GTBranch.m +++ b/ObjectiveGit/GTBranch.m @@ -37,7 +37,7 @@ #import "git2/branch.h" #import "git2/errors.h" #import "git2/graph.h" -#import "git2/deprecated.h" +#import "git2/buffer.h" @implementation GTBranch @@ -116,7 +116,7 @@ - (GTOID *)OID { } - (NSString *)remoteName { - git_buf remote_name = GIT_BUF_INIT_CONST(0, NULL); + git_buf remote_name = GIT_BUF_INIT; int gitError = git_branch_remote_name(&remote_name, self.repository.git_repository, self.reference.name.UTF8String); if (gitError != GIT_OK) return nil; diff --git a/ObjectiveGit/GTConfiguration.m b/ObjectiveGit/GTConfiguration.m index 6c1e41e3..586a3220 100644 --- a/ObjectiveGit/GTConfiguration.m +++ b/ObjectiveGit/GTConfiguration.m @@ -17,7 +17,7 @@ #import "git2/config.h" #import "git2/errors.h" #import "git2/buffer.h" -#import "git2/deprecated.h" +#import "git2/strarray.h" @interface GTConfiguration () @property (nonatomic, readonly, assign) git_config *git_config; @@ -144,7 +144,7 @@ - (NSArray *)remotes { } } - git_strarray_free(&names); + git_strarray_dispose(&names); return remotes; } diff --git a/ObjectiveGit/GTCredential.m b/ObjectiveGit/GTCredential.m index 0aad1f76..d996f17b 100644 --- a/ObjectiveGit/GTCredential.m +++ b/ObjectiveGit/GTCredential.m @@ -11,7 +11,6 @@ #import "NSError+Git.h" #import "git2/errors.h" -#import "git2/deprecated.h" #import "git2/sys/errors.h" typedef GTCredential *(^GTCredentialProviderBlock)(GTCredentialType allowedTypes, NSString *URL, NSString *userName); @@ -41,14 +40,14 @@ - (GTCredential *)credentialForType:(GTCredentialType)type URL:(NSString *)URL u @end @interface GTCredential () -@property (nonatomic, assign, readonly) git_cred *git_cred; +@property (nonatomic, assign, readonly) git_credential *git_cred; @end @implementation GTCredential + (instancetype)credentialWithUserName:(NSString *)userName password:(NSString *)password error:(NSError **)error { - git_cred *cred; - int gitError = git_cred_userpass_plaintext_new(&cred, userName.UTF8String, password.UTF8String); + git_credential *cred; + int gitError = git_credential_userpass_plaintext_new(&cred, userName.UTF8String, password.UTF8String); if (gitError != GIT_OK) { 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]; return nil; @@ -63,8 +62,8 @@ + (instancetype)credentialWithUserName:(NSString *)userName publicKeyURL:(NSURL NSString *privateKeyPath = privateKeyURL.filePathURL.path; NSAssert(privateKeyPath != nil, @"Invalid file URL passed: %@", privateKeyURL); - git_cred *cred; - int gitError = git_cred_ssh_key_new(&cred, userName.UTF8String, publicKeyPath.fileSystemRepresentation, privateKeyPath.fileSystemRepresentation, passphrase.UTF8String); + git_credential *cred; + int gitError = git_credential_ssh_key_new(&cred, userName.UTF8String, publicKeyPath.fileSystemRepresentation, privateKeyPath.fileSystemRepresentation, passphrase.UTF8String); if (gitError != GIT_OK) { 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]; return nil; @@ -76,8 +75,8 @@ + (instancetype)credentialWithUserName:(NSString *)userName publicKeyURL:(NSURL + (instancetype)credentialWithUserName:(NSString *)userName publicKeyString:(NSString *)publicKeyString privateKeyString:(NSString *)privateKeyString passphrase:(NSString *)passphrase error:(NSError **)error { NSParameterAssert(privateKeyString != nil); - git_cred *cred; - int gitError = git_cred_ssh_key_memory_new(&cred, userName.UTF8String, publicKeyString.UTF8String, privateKeyString.UTF8String, passphrase.UTF8String); + git_credential *cred; + int gitError = git_credential_ssh_key_memory_new(&cred, userName.UTF8String, publicKeyString.UTF8String, privateKeyString.UTF8String, passphrase.UTF8String); if (gitError != GIT_OK) { 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]; return nil; @@ -86,7 +85,7 @@ + (instancetype)credentialWithUserName:(NSString *)userName publicKeyString:(NSS return [[self alloc] initWithGitCred:cred]; } -- (instancetype)initWithGitCred:(git_cred *)cred { +- (instancetype)initWithGitCred:(git_credential *)cred { NSParameterAssert(cred != nil); self = [self init]; @@ -99,8 +98,8 @@ - (instancetype)initWithGitCred:(git_cred *)cred { @end -int GTCredentialAcquireCallback(git_cred **git_cred, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload) { - NSCParameterAssert(git_cred != NULL); +int GTCredentialAcquireCallback(git_credential **cred, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload) { + NSCParameterAssert(cred != NULL); NSCParameterAssert(payload != NULL); GTCredentialAcquireCallbackInfo *info = payload; @@ -114,12 +113,12 @@ int GTCredentialAcquireCallback(git_cred **git_cred, const char *url, const char NSString *URL = (url != NULL ? @(url) : @""); NSString *userName = (username_from_url != NULL ? @(username_from_url) : nil); - GTCredential *cred = [provider credentialForType:(GTCredentialType)allowed_types URL:URL userName:userName]; - if (cred == nil) { + GTCredential *gtCred = [provider credentialForType:(GTCredentialType)allowed_types URL:URL userName:userName]; + if (gtCred == nil) { git_error_set_str(GIT_EUSER, "GTCredentialProvider failed to provide credentials."); return GIT_ERROR; } - *git_cred = cred.git_cred; + *cred = gtCred.git_cred; return GIT_OK; } diff --git a/ObjectiveGit/GTDiff.m b/ObjectiveGit/GTDiff.m index 28c0ca2a..7dbb28ea 100644 --- a/ObjectiveGit/GTDiff.m +++ b/ObjectiveGit/GTDiff.m @@ -18,7 +18,7 @@ #import "EXTScope.h" #import "git2/errors.h" -#import "git2/deprecated.h" +#import "git2/strarray.h" NSString *const GTDiffOptionsFlagsKey = @"GTDiffOptionsFlagsKey"; NSString *const GTDiffOptionsContextLinesKey = @"GTDiffOptionsContextLinesKey"; @@ -72,7 +72,7 @@ + (int)handleParsedOptionsDictionary:(NSDictionary *)dictionary usingBlock:(int git_strarray strArray = pathSpec.git_strarray; if (pathSpec != nil) newOptions.pathspec = strArray; @onExit { - git_strarray_free((git_strarray *)&strArray); + git_strarray_dispose((git_strarray *)&strArray); }; git_diff_options *optionsPtr = &newOptions; diff --git a/ObjectiveGit/GTDiffPatch.m b/ObjectiveGit/GTDiffPatch.m index 1f956440..8020b729 100644 --- a/ObjectiveGit/GTDiffPatch.m +++ b/ObjectiveGit/GTDiffPatch.m @@ -9,7 +9,7 @@ #import "GTDiffPatch.h" #import "GTDiffHunk.h" -#import "git2/deprecated.h" +#import "git2/buffer.h" @interface GTDiffPatch () @@ -66,7 +66,7 @@ - (NSUInteger)sizeWithContext:(BOOL)includeContext hunkHeaders:(BOOL)includeHunk } - (NSData *)patchData { - git_buf buf = GIT_BUF_INIT_CONST(0, NULL); + git_buf buf = GIT_BUF_INIT; git_patch_to_buf(&buf, self.git_patch); NSData *buffer = [[NSData alloc] initWithBytes:buf.ptr length:buf.size]; diff --git a/ObjectiveGit/GTFilterList.m b/ObjectiveGit/GTFilterList.m index f325b75f..d381c805 100644 --- a/ObjectiveGit/GTFilterList.m +++ b/ObjectiveGit/GTFilterList.m @@ -14,7 +14,7 @@ #import "NSError+Git.h" #import "git2/errors.h" -#import "git2/deprecated.h" +#import "git2/buffer.h" @interface GTFilterList () @@ -54,9 +54,8 @@ - (void)dealloc { - (NSData *)applyToData:(NSData *)inputData error:(NSError **)error { NSParameterAssert(inputData != nil); - git_buf input = inputData.git_buf; - git_buf output = GIT_BUF_INIT_CONST(0, NULL); - int gitError = git_filter_list_apply_to_data(&output, self.git_filter_list, &input); + git_buf output = GIT_BUF_INIT; + int gitError = git_filter_list_apply_to_buffer(&output, self.git_filter_list, inputData.bytes, inputData.length); if (gitError != GIT_OK) { 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 NSParameterAssert(relativePath != nil); NSParameterAssert(repository != nil); - git_buf output = GIT_BUF_INIT_CONST(0, NULL); + git_buf output = GIT_BUF_INIT; // fixme: This is a workaround for an issue where `git_filter_list_apply_to_file` // will not resolve relative paths against the worktree. It should be reverted when // libgit2 has been updated to resolve that. @@ -88,7 +87,7 @@ - (NSData *)applyToPath:(NSString *)relativePath inRepository:(GTRepository *)re - (NSData *)applyToBlob:(GTBlob *)blob error:(NSError **)error { NSParameterAssert(blob != nil); - git_buf output = GIT_BUF_INIT_CONST(0, NULL); + git_buf output = GIT_BUF_INIT; int gitError = git_filter_list_apply_to_blob(&output, self.git_filter_list, blob.git_blob); if (gitError != GIT_OK) { diff --git a/ObjectiveGit/GTIndex.m b/ObjectiveGit/GTIndex.m index e27384e4..651650bc 100644 --- a/ObjectiveGit/GTIndex.m +++ b/ObjectiveGit/GTIndex.m @@ -41,7 +41,7 @@ #import "NSError+Git.h" #import "git2/errors.h" -#import "git2/deprecated.h" +#import "git2/index.h" // The block synonymous with libgit2's `git_index_matched_path_cb` callback. typedef BOOL (^GTIndexPathspecMatchedBlock)(NSString *matchedPathspec, NSString *path, BOOL *stop); @@ -197,7 +197,7 @@ - (BOOL)addData:(NSData *)data withPath:(NSString *)path error:(NSError **)error entry.path = [path cStringUsingEncoding:NSUTF8StringEncoding]; entry.mode = GIT_FILEMODE_BLOB; - int status = git_index_add_frombuffer(self.git_index, &entry, [data bytes], [data length]); + int status = git_index_add_from_buffer(self.git_index, &entry, [data bytes], [data length]); if (status != GIT_OK) { if (error != NULL) *error = [NSError git_errorFor:status description:@"Failed to add data with name %@ into index.", path]; diff --git a/ObjectiveGit/GTOID.m b/ObjectiveGit/GTOID.m index d4992658..23412df4 100644 --- a/ObjectiveGit/GTOID.m +++ b/ObjectiveGit/GTOID.m @@ -11,7 +11,6 @@ #import "git2/errors.h" #import "git2/odb.h" -#import "git2/deprecated.h" @interface GTOID () { git_oid _git_oid; @@ -30,7 +29,7 @@ - (const git_oid *)git_oid { - (NSString *)SHA { char *SHA = git_oid_tostr_s(self.git_oid); NSString *str = [[NSString alloc] initWithBytes:SHA - length:GIT_OID_HEXSZ + length:GIT_OID_SHA1_HEXSIZE encoding:NSUTF8StringEncoding]; NSAssert(str != nil, @"Failed to create SHA string"); return str; @@ -110,7 +109,7 @@ - (NSString *)description { - (NSUInteger)hash { // Hash the raw OID. - NSData *data = [[NSData alloc] initWithBytesNoCopy:_git_oid.id length:GIT_OID_RAWSZ freeWhenDone:NO]; + NSData *data = [[NSData alloc] initWithBytesNoCopy:_git_oid.id length:GIT_OID_SHA1_SIZE freeWhenDone:NO]; return data.hash; } diff --git a/ObjectiveGit/GTReference.m b/ObjectiveGit/GTReference.m index afc49ab6..570a56a1 100644 --- a/ObjectiveGit/GTReference.m +++ b/ObjectiveGit/GTReference.m @@ -35,7 +35,7 @@ #import "GTRepository+References.h" #import "git2/errors.h" -#import "git2/deprecated.h" +#import "git2/refs.h" @interface GTReference () @property (nonatomic, readonly, assign) git_reference *git_reference; @@ -235,7 +235,9 @@ - (GTReflog *)reflog { } + (BOOL)isValidReferenceName:(NSString *)refName { - return git_reference_is_valid_name(refName.UTF8String) == 1; + int valid = 0; + int result = git_reference_name_is_valid(&valid, refName.UTF8String); + return (result == 0 && valid == 1); } #pragma mark NSObject diff --git a/ObjectiveGit/GTRemote.m b/ObjectiveGit/GTRemote.m index ce7dc153..9b25014d 100644 --- a/ObjectiveGit/GTRemote.m +++ b/ObjectiveGit/GTRemote.m @@ -17,7 +17,6 @@ #import "EXTScope.h" #import "git2/errors.h" -#import "git2/deprecated.h" NSString * const GTRemoteRenameProblematicRefSpecs = @"GTRemoteRenameProblematicRefSpecs"; @@ -105,7 +104,9 @@ - (NSString *)description { + (BOOL)isValidRemoteName:(NSString *)name { NSParameterAssert(name != nil); - return (git_remote_is_valid_name(name.UTF8String) == 1 ? YES : NO); + int valid = 0; + int result = git_remote_name_is_valid(&valid, name.UTF8String); + return (result == 0 && valid == 1) ? YES : NO; } #pragma mark Properties @@ -158,7 +159,7 @@ - (BOOL)rename:(NSString *)name error:(NSError **)error { if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to rename remote" userInfo:userInfo failureReason:@"Couldn't rename remote %@ to %@", self.name, name]; } - git_strarray_free(&problematic_refspecs); + git_strarray_dispose(&problematic_refspecs); return gitError == GIT_OK; } @@ -169,7 +170,7 @@ - (NSArray *)fetchRefspecs { if (gitError != GIT_OK) return nil; @onExit { - git_strarray_free(&refspecs); + git_strarray_dispose(&refspecs); }; return [NSArray git_arrayWithStrarray:refspecs]; @@ -182,7 +183,7 @@ - (NSArray *)pushRefspecs { if (gitError != GIT_OK) return nil; @onExit { - git_strarray_free(&refspecs); + git_strarray_dispose(&refspecs); }; return [NSArray git_arrayWithStrarray:refspecs]; diff --git a/ObjectiveGit/GTRepository+RemoteOperations.m b/ObjectiveGit/GTRepository+RemoteOperations.m index 00e4bcfb..5d477472 100644 --- a/ObjectiveGit/GTRepository+RemoteOperations.m +++ b/ObjectiveGit/GTRepository+RemoteOperations.m @@ -24,7 +24,6 @@ #import "git2/remote.h" #import "git2/notes.h" #import "git2/buffer.h" -#import "git2/deprecated.h" NSString *const GTRepositoryRemoteOptionsCredentialProvider = @"GTRepositoryRemoteOptionsCredentialProvider"; NSString *const GTRepositoryRemoteOptionsFetchPrune = @"GTRepositoryRemoteOptionsFetchPrune"; @@ -98,7 +97,7 @@ - (BOOL)fetchRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error } @onExit { - git_strarray_free(&refspecs); + git_strarray_dispose(&refspecs); }; NSString *reflog_message = [NSString stringWithFormat:@"fetching remote %@", remote.name]; diff --git a/ObjectiveGit/GTRepository+Status.m b/ObjectiveGit/GTRepository+Status.m index e662c854..5b0db99e 100644 --- a/ObjectiveGit/GTRepository+Status.m +++ b/ObjectiveGit/GTRepository+Status.m @@ -15,7 +15,6 @@ #import "EXTScope.h" #import "git2/errors.h" -#import "git2/deprecated.h" NSString *const GTRepositoryStatusOptionsShowKey = @"GTRepositoryStatusOptionsShow"; NSString *const GTRepositoryStatusOptionsFlagsKey = @"GTRepositoryStatusOptionsFlags"; @@ -42,7 +41,7 @@ - (BOOL)enumerateFileStatusWithOptions:(NSDictionary *)options error:(NSError ** int err = git_status_list_new(&statusList, self.git_repository, &gitOptions); @onExit { git_status_list_free(statusList); - if (gitOptions.pathspec.count > 0) git_strarray_free(&gitOptions.pathspec); + if (gitOptions.pathspec.count > 0) git_strarray_dispose(&gitOptions.pathspec); }; if (err != GIT_OK) {