Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 2 additions & 6 deletions ObjectiveGit/Categories/NSData+Git.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions ObjectiveGit/GTBlob.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

#import "git2/blob.h"
#import "git2/errors.h"
#import "git2/deprecated.h"

@implementation GTBlob

Expand Down Expand Up @@ -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"];
Expand All @@ -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"];
Expand Down Expand Up @@ -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);
Comment on lines +140 to +141
if (gitError != GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to apply filters for path %@ to blob", path];
return nil;
Expand Down
4 changes: 2 additions & 2 deletions ObjectiveGit/GTBranch.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions ObjectiveGit/GTConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -144,7 +144,7 @@ - (NSArray *)remotes {
}
}

git_strarray_free(&names);
git_strarray_dispose(&names);

return remotes;
}
Expand Down
27 changes: 13 additions & 14 deletions ObjectiveGit/GTCredential.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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];

Expand All @@ -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;
Expand All @@ -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;
}
4 changes: 2 additions & 2 deletions ObjectiveGit/GTDiff.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions ObjectiveGit/GTDiffPatch.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "GTDiffPatch.h"

#import "GTDiffHunk.h"
#import "git2/deprecated.h"
#import "git2/buffer.h"

@interface GTDiffPatch ()

Expand Down Expand Up @@ -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];
Expand Down
11 changes: 5 additions & 6 deletions ObjectiveGit/GTFilterList.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#import "NSError+Git.h"

#import "git2/errors.h"
#import "git2/deprecated.h"
#import "git2/buffer.h"

@interface GTFilterList ()

Expand Down Expand Up @@ -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"];
Expand All @@ -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.
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions ObjectiveGit/GTIndex.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down
5 changes: 2 additions & 3 deletions ObjectiveGit/GTOID.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#import "git2/errors.h"
#import "git2/odb.h"
#import "git2/deprecated.h"

@interface GTOID () {
git_oid _git_oid;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions ObjectiveGit/GTReference.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions ObjectiveGit/GTRemote.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#import "EXTScope.h"

#import "git2/errors.h"
#import "git2/deprecated.h"

NSString * const GTRemoteRenameProblematicRefSpecs = @"GTRemoteRenameProblematicRefSpecs";

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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];
Expand All @@ -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];
Expand Down
3 changes: 1 addition & 2 deletions ObjectiveGit/GTRepository+RemoteOperations.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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];
Expand Down
3 changes: 1 addition & 2 deletions ObjectiveGit/GTRepository+Status.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#import "EXTScope.h"

#import "git2/errors.h"
#import "git2/deprecated.h"

NSString *const GTRepositoryStatusOptionsShowKey = @"GTRepositoryStatusOptionsShow";
NSString *const GTRepositoryStatusOptionsFlagsKey = @"GTRepositoryStatusOptionsFlags";
Expand All @@ -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) {
Expand Down
Loading