From 99ccb2f28214357d2fd69c5c68c31b45882b83ff Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 6 Mar 2015 11:07:05 -0500 Subject: [PATCH 1/9] Bump libgit2. --- External/libgit2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/External/libgit2 b/External/libgit2 index d5712ed2b..bdf0e7345 160000 --- a/External/libgit2 +++ b/External/libgit2 @@ -1 +1 @@ -Subproject commit d5712ed2b33a18a4f9417d112bda7813c0570caa +Subproject commit bdf0e734506b5b18234d48a0e7c6995aeda30b9d From 291a0a017dbeb820ccda8dab49b32196b80c4e2c Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 6 Mar 2015 11:37:02 -0500 Subject: [PATCH 2/9] Filter options have been renamed. --- ObjectiveGit/GTFilterList.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ObjectiveGit/GTFilterList.h b/ObjectiveGit/GTFilterList.h index 0473d3f2e..dbaa0a556 100644 --- a/ObjectiveGit/GTFilterList.h +++ b/ObjectiveGit/GTFilterList.h @@ -14,8 +14,8 @@ /// The options for loading a filter list. See libgit2 for more information. typedef NS_OPTIONS(NSInteger, GTFilterListOptions) { - GTFilterListOptionsDefault = GIT_FILTER_OPT_DEFAULT, - GTFilterListOptionsAllowUnsafe = GIT_FILTER_OPT_ALLOW_UNSAFE, + GTFilterListOptionsDefault = GIT_FILTER_DEFAULT, + GTFilterListOptionsAllowUnsafe = GIT_FILTER_ALLOW_UNSAFE, }; /// An opaque list of filters that apply to a given path. From c97e29c94a127fc40d888c3205e0cbcac380e707 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 6 Mar 2015 11:37:41 -0500 Subject: [PATCH 3/9] Lots of libgit2 API no longer takes a signature and/or message. --- ObjectiveGit/GTReference.h | 5 +---- ObjectiveGit/GTReference.m | 8 ++++---- ObjectiveGit/GTRepository+RemoteOperations.m | 4 ++-- ObjectiveGit/GTRepository+Reset.m | 2 +- ObjectiveGit/GTRepository.h | 12 +++--------- ObjectiveGit/GTRepository.m | 16 ++++++++-------- 6 files changed, 19 insertions(+), 28 deletions(-) diff --git a/ObjectiveGit/GTReference.h b/ObjectiveGit/GTReference.h index 5d8f44e68..c97d7f96a 100644 --- a/ObjectiveGit/GTReference.h +++ b/ObjectiveGit/GTReference.h @@ -28,7 +28,6 @@ @class GTOID; @class GTReflog; -@class GTSignature; typedef NS_ENUM(NSInteger, GTReferenceErrorCode) { GTReferenceErrorCodeInvalidReference = -4, @@ -89,14 +88,12 @@ typedef NS_OPTIONS(NSInteger, GTReferenceType) { /// Note that this does *not* change the receiver's target. /// /// newTarget - The target for the new reference. This must not be nil. -/// signature - A signature for the committer updating this ref, used for -/// creating a reflog entry. This may be nil. /// message - A message to use when creating the reflog entry for this action. /// This may be nil. /// error - The error if one occurred. /// /// Returns the updated reference, or nil if an error occurred. -- (GTReference *)referenceByUpdatingTarget:(NSString *)newTarget committer:(GTSignature *)signature message:(NSString *)message error:(NSError **)error; +- (GTReference *)referenceByUpdatingTarget:(NSString *)newTarget message:(NSString *)message error:(NSError **)error; /// The name of the reference. @property (nonatomic, readonly, copy) NSString *name; diff --git a/ObjectiveGit/GTReference.m b/ObjectiveGit/GTReference.m index 74aaa8496..7f667cc2f 100644 --- a/ObjectiveGit/GTReference.m +++ b/ObjectiveGit/GTReference.m @@ -128,7 +128,7 @@ - (GTReference *)referenceByRenaming:(NSString *)newName error:(NSError **)error NSParameterAssert(newName != nil); git_reference *newRef = NULL; - int gitError = git_reference_rename(&newRef, self.git_reference, newName.UTF8String, 0, [self.repository userSignatureForNow].git_signature, NULL); + int gitError = git_reference_rename(&newRef, self.git_reference, newName.UTF8String, 0, NULL); if (gitError != GIT_OK) { if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to rename reference %@ to %@.", self.name, newName]; return nil; @@ -173,7 +173,7 @@ - (NSString *)targetSHA { return [self.resolvedTarget SHA]; } -- (GTReference *)referenceByUpdatingTarget:(NSString *)newTarget committer:(GTSignature *)signature message:(NSString *)message error:(NSError **)error { +- (GTReference *)referenceByUpdatingTarget:(NSString *)newTarget message:(NSString *)message error:(NSError **)error { NSParameterAssert(newTarget != nil); int gitError; @@ -182,9 +182,9 @@ - (GTReference *)referenceByUpdatingTarget:(NSString *)newTarget committer:(GTSi GTOID *oid = [[GTOID alloc] initWithSHA:newTarget error:error]; if (oid == nil) return nil; - gitError = git_reference_set_target(&newRef, self.git_reference, oid.git_oid, signature.git_signature, message.UTF8String); + gitError = git_reference_set_target(&newRef, self.git_reference, oid.git_oid, message.UTF8String); } else { - gitError = git_reference_symbolic_set_target(&newRef, self.git_reference, newTarget.UTF8String, signature.git_signature, message.UTF8String); + gitError = git_reference_symbolic_set_target(&newRef, self.git_reference, newTarget.UTF8String, message.UTF8String); } if (gitError != GIT_OK) { diff --git a/ObjectiveGit/GTRepository+RemoteOperations.m b/ObjectiveGit/GTRepository+RemoteOperations.m index 70d0a6f18..302ffbabf 100644 --- a/ObjectiveGit/GTRepository+RemoteOperations.m +++ b/ObjectiveGit/GTRepository+RemoteOperations.m @@ -95,7 +95,7 @@ - (BOOL)fetchRemote:(GTRemote *)remote withOptions:(NSDictionary *)options error git_strarray_free(&refspecs); }; - gitError = git_remote_fetch(remote.git_remote, &refspecs, self.userSignatureForNow.git_signature, NULL); + gitError = git_remote_fetch(remote.git_remote, &refspecs, NULL); if (gitError != GIT_OK) { if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to fetch from remote"]; return NO; @@ -246,7 +246,7 @@ - (BOOL)pushRefspecs:(NSArray *)refspecs toRemote:(GTRemote *)remote withOptions return NO; } - gitError = git_remote_update_tips(remote.git_remote, self.userSignatureForNow.git_signature, NULL); + gitError = git_remote_update_tips(remote.git_remote, NULL); if (gitError != GIT_OK) { if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Update tips failed"]; return NO; diff --git a/ObjectiveGit/GTRepository+Reset.m b/ObjectiveGit/GTRepository+Reset.m index ebf794fce..71d24b1f0 100644 --- a/ObjectiveGit/GTRepository+Reset.m +++ b/ObjectiveGit/GTRepository+Reset.m @@ -20,7 +20,7 @@ - (BOOL)resetToCommit:(GTCommit *)commit resetType:(GTRepositoryResetType)resetT NSParameterAssert(commit != nil); git_checkout_options options = GIT_CHECKOUT_OPTIONS_INIT; - int gitError = git_reset(self.git_repository, commit.git_object, (git_reset_t)resetType, &options, (git_signature *)[self userSignatureForNow].git_signature, NULL); + int gitError = git_reset(self.git_repository, commit.git_object, (git_reset_t)resetType, &options); if (gitError != GIT_OK) { if (error != NULL) { *error = [NSError git_errorFor:gitError description:@"Failed to reset repository to commit %@.", commit.SHA]; diff --git a/ObjectiveGit/GTRepository.h b/ObjectiveGit/GTRepository.h index 5e011b7e7..f534e4636 100644 --- a/ObjectiveGit/GTRepository.h +++ b/ObjectiveGit/GTRepository.h @@ -279,41 +279,35 @@ extern NSString * const GTRepositoryInitOptionsOriginURLString; /// /// name - The full name for the new reference. This must not be nil. /// targetOID - The OID that the new ref should point to. This must not be nil. -/// signature - A signature for the committer creating this ref, used for -/// creating a reflog entry. This may be nil. /// message - A message to use when creating the reflog entry for this action. /// This may be nil. /// error - If not NULL, set to any error that occurs. /// /// Returns the created ref, or nil if an error occurred. -- (GTReference *)createReferenceNamed:(NSString *)name fromOID:(GTOID *)targetOID committer:(GTSignature *)signature message:(NSString *)message error:(NSError **)error; +- (GTReference *)createReferenceNamed:(NSString *)name fromOID:(GTOID *)targetOID message:(NSString *)message error:(NSError **)error; /// Creates a symbolic reference to another ref. /// /// name - The full name for the new reference. This must not be nil. /// targetRef - The ref that the new ref should point to. This must not be nil. -/// signature - A signature for the committer creating this ref, used for -/// creating a reflog entry. This may be nil. /// message - A message to use when creating the reflog entry for this action. /// This may be nil. /// error - If not NULL, set to any error that occurs. /// /// Returns the created ref, or nil if an error occurred. -- (GTReference *)createReferenceNamed:(NSString *)name fromReference:(GTReference *)targetRef committer:(GTSignature *)signature message:(NSString *)message error:(NSError **)error; +- (GTReference *)createReferenceNamed:(NSString *)name fromReference:(GTReference *)targetRef message:(NSString *)message error:(NSError **)error; /// Create a new local branch pointing to the given OID. /// /// name - The name for the new branch (e.g., `master`). This must not be /// nil. /// targetOID - The OID to create the new branch off. This must not be nil. -/// signature - A signature for the committer creating this branch, used for -/// creating a reflog entry. This may be nil. /// message - A message to use when creating the reflog entry for this action. /// This may be nil. /// error - If not NULL, set to any error that occurs. /// /// Returns the new branch, or nil if an error occurred. -- (GTBranch *)createBranchNamed:(NSString *)name fromOID:(GTOID *)targetOID committer:(GTSignature *)signature message:(NSString *)message error:(NSError **)error; +- (GTBranch *)createBranchNamed:(NSString *)name fromOID:(GTOID *)targetOID message:(NSString *)message error:(NSError **)error; /// Get the current branch. /// diff --git a/ObjectiveGit/GTRepository.m b/ObjectiveGit/GTRepository.m index 5f385dda7..c47e44cbc 100644 --- a/ObjectiveGit/GTRepository.m +++ b/ObjectiveGit/GTRepository.m @@ -493,12 +493,12 @@ - (NSUInteger)numberOfCommitsInCurrentBranch:(NSError **)error { return [currentBranch numberOfCommitsWithError:error]; } -- (GTReference *)createReferenceNamed:(NSString *)name fromOID:(GTOID *)targetOID committer:(GTSignature *)signature message:(NSString *)message error:(NSError **)error { +- (GTReference *)createReferenceNamed:(NSString *)name fromOID:(GTOID *)targetOID message:(NSString *)message error:(NSError **)error { NSParameterAssert(name != nil); NSParameterAssert(targetOID != nil); git_reference *ref; - int gitError = git_reference_create(&ref, self.git_repository, name.UTF8String, targetOID.git_oid, 0, signature.git_signature, message.UTF8String); + int gitError = git_reference_create(&ref, self.git_repository, name.UTF8String, targetOID.git_oid, 0, message.UTF8String); if (gitError != GIT_OK) { if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to create direct reference to %@", targetOID]; return nil; @@ -507,13 +507,13 @@ - (GTReference *)createReferenceNamed:(NSString *)name fromOID:(GTOID *)targetOI return [[GTReference alloc] initWithGitReference:ref repository:self]; } -- (GTReference *)createReferenceNamed:(NSString *)name fromReference:(GTReference *)targetRef committer:(GTSignature *)signature message:(NSString *)message error:(NSError **)error { +- (GTReference *)createReferenceNamed:(NSString *)name fromReference:(GTReference *)targetRef message:(NSString *)message error:(NSError **)error { NSParameterAssert(name != nil); NSParameterAssert(targetRef != nil); NSParameterAssert(targetRef.name != nil); git_reference *ref; - int gitError = git_reference_symbolic_create(&ref, self.git_repository, name.UTF8String, targetRef.name.UTF8String, 0, signature.git_signature, message.UTF8String); + int gitError = git_reference_symbolic_create(&ref, self.git_repository, name.UTF8String, targetRef.name.UTF8String, 0, message.UTF8String); if (gitError != GIT_OK) { if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to create symbolic reference to %@", targetRef]; return nil; @@ -522,11 +522,11 @@ - (GTReference *)createReferenceNamed:(NSString *)name fromReference:(GTReferenc return [[GTReference alloc] initWithGitReference:ref repository:self]; } -- (GTBranch *)createBranchNamed:(NSString *)name fromOID:(GTOID *)targetOID committer:(GTSignature *)signature message:(NSString *)message error:(NSError **)error { +- (GTBranch *)createBranchNamed:(NSString *)name fromOID:(GTOID *)targetOID message:(NSString *)message error:(NSError **)error { NSParameterAssert(name != nil); NSParameterAssert(targetOID != nil); - GTReference *newRef = [self createReferenceNamed:[GTBranch.localNamePrefix stringByAppendingString:name] fromOID:targetOID committer:signature message:message error:error]; + GTReference *newRef = [self createReferenceNamed:[GTBranch.localNamePrefix stringByAppendingString:name] fromOID:targetOID message:message error:error]; if (newRef == nil) return nil; return [GTBranch branchWithReference:newRef repository:self]; @@ -800,7 +800,7 @@ static int checkoutNotifyCallback(git_checkout_notify_t why, const char *path, c - (BOOL)moveHEADToReference:(GTReference *)reference error:(NSError **)error { NSParameterAssert(reference != nil); - int gitError = git_repository_set_head(self.git_repository, reference.name.UTF8String, [self userSignatureForNow].git_signature, NULL); + int gitError = git_repository_set_head(self.git_repository, reference.name.UTF8String); if (gitError != GIT_OK) { if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to move HEAD to reference %@", reference.name]; } @@ -811,7 +811,7 @@ - (BOOL)moveHEADToReference:(GTReference *)reference error:(NSError **)error { - (BOOL)moveHEADToCommit:(GTCommit *)commit error:(NSError **)error { NSParameterAssert(commit != nil); - int gitError = git_repository_set_head_detached(self.git_repository, commit.OID.git_oid, [self userSignatureForNow].git_signature, NULL); + int gitError = git_repository_set_head_detached(self.git_repository, commit.OID.git_oid); if (gitError != GIT_OK) { if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to move HEAD to commit %@", commit.SHA]; } From a078654d7060855d9a3663848400266bf59bf2fd Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 6 Mar 2015 11:38:02 -0500 Subject: [PATCH 4/9] There is no longer any such checkout strategy as safe create. --- ObjectiveGit/GTRepository.h | 1 - 1 file changed, 1 deletion(-) diff --git a/ObjectiveGit/GTRepository.h b/ObjectiveGit/GTRepository.h index f534e4636..950406491 100644 --- a/ObjectiveGit/GTRepository.h +++ b/ObjectiveGit/GTRepository.h @@ -57,7 +57,6 @@ typedef NS_OPTIONS(NSInteger, GTCheckoutStrategyType) { GTCheckoutStrategyNone = GIT_CHECKOUT_NONE, GTCheckoutStrategySafe = GIT_CHECKOUT_SAFE, - GTCheckoutStrategySafeCreate = GIT_CHECKOUT_SAFE_CREATE, GTCheckoutStrategyForce = GIT_CHECKOUT_FORCE, GTCheckoutStrategyAllowConflicts = GIT_CHECKOUT_ALLOW_CONFLICTS, GTCheckoutStrategyRemoveUntracked = GIT_CHECKOUT_REMOVE_UNTRACKED, From 1392d05b7d5c571e63cb50a57b975455cdc24104 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 6 Mar 2015 11:38:07 -0500 Subject: [PATCH 5/9] Checkout safe. --- ObjectiveGit/GTRepository.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ObjectiveGit/GTRepository.m b/ObjectiveGit/GTRepository.m index c47e44cbc..c60917896 100644 --- a/ObjectiveGit/GTRepository.m +++ b/ObjectiveGit/GTRepository.m @@ -236,7 +236,7 @@ + (id)cloneFromURL:(NSURL *)originURL toWorkingDirectory:(NSURL *)workdirURL opt if (withCheckout) { git_checkout_options checkoutOptions = GIT_CHECKOUT_OPTIONS_INIT; - checkoutOptions.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; + checkoutOptions.checkout_strategy = GIT_CHECKOUT_SAFE; checkoutOptions.progress_cb = checkoutProgressCallback; checkoutOptions.progress_payload = (__bridge void *)checkoutProgressBlock; cloneOptions.checkout_opts = checkoutOptions; From 9539a4fd1a923a321a797fd48f8ef9b703954c03 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 6 Mar 2015 12:21:15 -0500 Subject: [PATCH 6/9] Fix up the tests. --- ObjectiveGitTests/GTBranchSpec.m | 4 ++-- ObjectiveGitTests/GTReferenceSpec.m | 10 +++++----- ObjectiveGitTests/GTRemotePushSpec.m | 2 +- ObjectiveGitTests/GTRepositorySpec.m | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ObjectiveGitTests/GTBranchSpec.m b/ObjectiveGitTests/GTBranchSpec.m index f3537ea1e..9a502ed3e 100644 --- a/ObjectiveGitTests/GTBranchSpec.m +++ b/ObjectiveGitTests/GTBranchSpec.m @@ -122,7 +122,7 @@ static NSString * const originalSHA = @"a4bca6b67a5483169963572ee3da563da33712f7"; static NSString * const updatedSHA = @"6b0c1c8b8816416089c534e474f4c692a76ac14f"; expect([masterBranch targetCommitAndReturnError:NULL].SHA).to(equal(originalSHA)); - [masterBranch.reference referenceByUpdatingTarget:updatedSHA committer:nil message:nil error:NULL]; + [masterBranch.reference referenceByUpdatingTarget:updatedSHA message:nil error:NULL]; GTBranch *reloadedBranch = [masterBranch reloadedBranchWithError:NULL]; expect(reloadedBranch).notTo(beNil()); @@ -158,7 +158,7 @@ GTOID *OID = [[GTOID alloc] initWithSHA:@"6b0c1c8b8816416089c534e474f4c692a76ac14f"]; NSError *error = nil; - GTReference *otherRef = [repository createReferenceNamed:@"refs/heads/yet-another-branch" fromOID:OID committer:nil message:nil error:&error]; + GTReference *otherRef = [repository createReferenceNamed:@"refs/heads/yet-another-branch" fromOID:OID message:nil error:&error]; expect(otherRef).notTo(beNil()); expect(error).to(beNil()); diff --git a/ObjectiveGitTests/GTReferenceSpec.m b/ObjectiveGitTests/GTReferenceSpec.m index 54bb2e687..e8f75d77e 100644 --- a/ObjectiveGitTests/GTReferenceSpec.m +++ b/ObjectiveGitTests/GTReferenceSpec.m @@ -62,7 +62,7 @@ expect(repository).notTo(beNil()); NSError *error; - reference = [repository createReferenceNamed:testRefName fromOID:testRefOID committer:nil message:nil error:&error]; + reference = [repository createReferenceNamed:testRefName fromOID:testRefOID message:nil error:&error]; expect(reference).notTo(beNil()); expect(reference.name).to(equal(testRefName)); expect(reference.targetSHA).to(equal(testRefOID.SHA)); @@ -80,7 +80,7 @@ it(@"should be able to change the target", ^{ NSString *newRefTarget = @"5b5b025afb0b4c913b4c338a42934a3863bf3644"; - GTReference *updatedRef = [reference referenceByUpdatingTarget:newRefTarget committer:nil message:nil error:NULL]; + GTReference *updatedRef = [reference referenceByUpdatingTarget:newRefTarget message:nil error:NULL]; expect(updatedRef).notTo(beNil()); expect(updatedRef.name).to(equal(testRefName)); expect(updatedRef.targetSHA).to(equal(newRefTarget)); @@ -154,7 +154,7 @@ expect(target).notTo(beNil()); NSError *error = nil; - GTReference *ref = [bareRepository createReferenceNamed:@"refs/heads/unit_test" fromReference:target committer:nil message:nil error:&error]; + GTReference *ref = [bareRepository createReferenceNamed:@"refs/heads/unit_test" fromReference:target message:nil error:&error]; expect(error).to(beNil()); expect(ref).notTo(beNil()); @@ -166,7 +166,7 @@ GTOID *target = [[GTOID alloc] initWithSHA:@"36060c58702ed4c2a40832c51758d5344201d89a"]; NSError *error = nil; - GTReference *ref = [bareRepository createReferenceNamed:@"refs/heads/unit_test" fromOID:target committer:nil message:nil error:&error]; + GTReference *ref = [bareRepository createReferenceNamed:@"refs/heads/unit_test" fromOID:target message:nil error:&error]; expect(error).to(beNil()); expect(ref).notTo(beNil()); @@ -179,7 +179,7 @@ GTOID *target = [[GTOID alloc] initWithSHA:@"36060c58702ed4c2a40832c51758d5344201d89a"]; NSError *error = nil; - GTReference *ref = [bareRepository createReferenceNamed:@"refs/heads/unit_test" fromOID:target committer:nil message:nil error:&error]; + GTReference *ref = [bareRepository createReferenceNamed:@"refs/heads/unit_test" fromOID:target message:nil error:&error]; expect(error).to(beNil()); expect(ref).notTo(beNil()); diff --git a/ObjectiveGitTests/GTRemotePushSpec.m b/ObjectiveGitTests/GTRemotePushSpec.m index 59e27d8e1..1c1b1265d 100644 --- a/ObjectiveGitTests/GTRemotePushSpec.m +++ b/ObjectiveGitTests/GTRemotePushSpec.m @@ -186,7 +186,7 @@ GTBranch *branch1 = localBranchWithName(@"master", localRepo); // Create refs/heads/new_master on local - [localRepo createReferenceNamed:@"refs/heads/new_master" fromReference:branch1.reference committer:localRepo.userSignatureForNow message:@"Create new_master branch" error:&error]; + [localRepo createReferenceNamed:@"refs/heads/new_master" fromReference:branch1.reference message:@"Create new_master branch" error:&error]; GTBranch *branch2 = localBranchWithName(@"new_master", localRepo); BOOL result = [localRepo pushBranches:@[ branch1, branch2 ] toRemote:remote withOptions:nil error:&error progress:NULL]; diff --git a/ObjectiveGitTests/GTRepositorySpec.m b/ObjectiveGitTests/GTRepositorySpec.m index de2dbb46d..bab83c79e 100644 --- a/ObjectiveGitTests/GTRepositorySpec.m +++ b/ObjectiveGitTests/GTRepositorySpec.m @@ -276,7 +276,7 @@ NSString *branchName = @"new-test-branch"; NSError *error = nil; - GTBranch *newBranch = [repository createBranchNamed:branchName fromOID:[[GTOID alloc] initWithSHA:currentBranch.SHA] committer:nil message:nil error:&error]; + GTBranch *newBranch = [repository createBranchNamed:branchName fromOID:[[GTOID alloc] initWithSHA:currentBranch.SHA] message:nil error:&error]; expect(newBranch).notTo(beNil()); expect(error).to(beNil()); From 84b0a3da43255456d86ecca5468eacc3d853cb5a Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 6 Mar 2015 14:05:38 -0500 Subject: [PATCH 7/9] Copy configuration strings out into a buffer. --- ObjectiveGit/GTConfiguration.m | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ObjectiveGit/GTConfiguration.m b/ObjectiveGit/GTConfiguration.m index 705897a21..a0e2349c4 100644 --- a/ObjectiveGit/GTConfiguration.m +++ b/ObjectiveGit/GTConfiguration.m @@ -15,6 +15,7 @@ #import "git2/config.h" #import "git2/errors.h" +#import "git2/buffer.h" @interface GTConfiguration () @property (nonatomic, readonly, assign) git_config *git_config; @@ -58,11 +59,13 @@ - (void)setString:(NSString *)s forKey:(NSString *)key { } - (NSString *)stringForKey:(NSString *)key { - const char *string = NULL; - git_config_get_string(&string, self.git_config, key.UTF8String); - if (string == NULL) return nil; + git_buf buffer = {}; + if (git_config_get_string_buf(&buffer, self.git_config, key.UTF8String) != 0) return nil; - return [NSString stringWithUTF8String:string]; + NSString *string = [[NSString alloc] initWithBytes:buffer.ptr length:buffer.size encoding:NSUTF8StringEncoding]; + git_buf_free(&buffer); + + return string; } - (void)setBool:(BOOL)b forKey:(NSString *)key { From e1fdaae61f821126ec9b827a77dffe449e127cc7 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 6 Mar 2015 14:31:46 -0500 Subject: [PATCH 8/9] Work around relative/absolute path stuff. --- ObjectiveGit/GTFilterList.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ObjectiveGit/GTFilterList.m b/ObjectiveGit/GTFilterList.m index ffa37669c..0f47a88d4 100644 --- a/ObjectiveGit/GTFilterList.m +++ b/ObjectiveGit/GTFilterList.m @@ -65,7 +65,11 @@ - (NSData *)applyToPath:(NSString *)relativePath inRepository:(GTRepository *)re NSParameterAssert(repository != nil); git_buf output = GIT_BUF_INIT_CONST(0, NULL); - int gitError = git_filter_list_apply_to_file(&output, self.git_filter_list, repository.git_repository, relativePath.UTF8String); + // 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. + NSString *absolutePath = relativePath.absolutePath ? relativePath : [repository.fileURL URLByAppendingPathComponent:relativePath].path; + int gitError = git_filter_list_apply_to_file(&output, self.git_filter_list, repository.git_repository, absolutePath.UTF8String); if (gitError != GIT_OK) { if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to apply filter list to %@", relativePath]; From 278a0fe099b63ef1448fe2f0c3896cc43680b42b Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 6 Mar 2015 14:56:27 -0500 Subject: [PATCH 9/9] Use the NSData category. --- ObjectiveGit/GTConfiguration.m | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ObjectiveGit/GTConfiguration.m b/ObjectiveGit/GTConfiguration.m index a0e2349c4..ff31fb82a 100644 --- a/ObjectiveGit/GTConfiguration.m +++ b/ObjectiveGit/GTConfiguration.m @@ -10,8 +10,9 @@ #import "GTConfiguration+Private.h" #import "GTRepository.h" #import "GTRemote.h" -#import "NSError+Git.h" #import "GTSignature.h" +#import "NSData+Git.h" +#import "NSError+Git.h" #import "git2/config.h" #import "git2/errors.h" @@ -62,10 +63,7 @@ - (NSString *)stringForKey:(NSString *)key { git_buf buffer = {}; if (git_config_get_string_buf(&buffer, self.git_config, key.UTF8String) != 0) return nil; - NSString *string = [[NSString alloc] initWithBytes:buffer.ptr length:buffer.size encoding:NSUTF8StringEncoding]; - git_buf_free(&buffer); - - return string; + return [[NSString alloc] initWithData:[NSData git_dataWithBuffer:&buffer] encoding:NSUTF8StringEncoding]; } - (void)setBool:(BOOL)b forKey:(NSString *)key {