Skip to content

Commit

Permalink
Merge pull request #446 from libgit2/bump-libgit2-to-fix-status-item-…
Browse files Browse the repository at this point in the history
…crash

Bump libgit2.
  • Loading branch information
jspahrsummers committed Mar 6, 2015
2 parents 3f617c5 + 278a0fe commit 13c32cb
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 48 deletions.
2 changes: 1 addition & 1 deletion External/libgit2
Submodule libgit2 updated 283 files
11 changes: 6 additions & 5 deletions ObjectiveGit/GTConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
#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"
#import "git2/buffer.h"

@interface GTConfiguration ()
@property (nonatomic, readonly, assign) git_config *git_config;
Expand Down Expand Up @@ -58,11 +60,10 @@ - (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];
return [[NSString alloc] initWithData:[NSData git_dataWithBuffer:&buffer] encoding:NSUTF8StringEncoding];
}

- (void)setBool:(BOOL)b forKey:(NSString *)key {
Expand Down
4 changes: 2 additions & 2 deletions ObjectiveGit/GTFilterList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion ObjectiveGit/GTFilterList.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
5 changes: 1 addition & 4 deletions ObjectiveGit/GTReference.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

@class GTOID;
@class GTReflog;
@class GTSignature;

typedef NS_ENUM(NSInteger, GTReferenceErrorCode) {
GTReferenceErrorCodeInvalidReference = -4,
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions ObjectiveGit/GTReference.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions ObjectiveGit/GTRepository+RemoteOperations.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ObjectiveGit/GTRepository+Reset.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
13 changes: 3 additions & 10 deletions ObjectiveGit/GTRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -279,41 +278,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.
///
Expand Down
18 changes: 9 additions & 9 deletions ObjectiveGit/GTRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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];
Expand Down Expand Up @@ -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];
}
Expand All @@ -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];
}
Expand Down
4 changes: 2 additions & 2 deletions ObjectiveGitTests/GTBranchSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());

Expand Down
10 changes: 5 additions & 5 deletions ObjectiveGitTests/GTReferenceSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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());

Expand All @@ -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());

Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion ObjectiveGitTests/GTRemotePushSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion ObjectiveGitTests/GTRepositorySpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit 13c32cb

Please sign in to comment.