Skip to content

Commit

Permalink
Merge pull request #429 from libgit2/bump-libgit2
Browse files Browse the repository at this point in the history
Bump libgit2 to hf/master_patch
  • Loading branch information
joshaber committed Dec 17, 2014
2 parents 5b7e15c + fd484fe commit b4ae265
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 53 deletions.
2 changes: 1 addition & 1 deletion External/libgit2
Submodule libgit2 updated 189 files
6 changes: 0 additions & 6 deletions ObjectiveGit/GTRepository+RemoteOperations.m
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,6 @@ - (BOOL)pushRefspecs:(NSArray *)refspecs toRemote:(GTRemote *)remote withOptions
return NO;
}

int unpackSuccessful = git_push_unpack_ok(push);
if (unpackSuccessful == 0) {
if (error != NULL) *error = [NSError errorWithDomain:GTGitErrorDomain code:GIT_ERROR userInfo:@{ NSLocalizedDescriptionKey: @"Unpacking failed" }];
return NO;
}

gitError = git_push_update_tips(push, self.userSignatureForNow.git_signature, NULL);
if (gitError != GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Update tips failed"];
Expand Down
12 changes: 6 additions & 6 deletions ObjectiveGit/GTTreeBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ typedef NS_ENUM(NSInteger, GTFileMode) {

/// Initializes the receiver, optionally from an existing tree.
///
/// treeOrNil - Source tree (or nil)
/// error - The error if one occurred.
/// treeOrNil - Source tree (or nil)
/// repository - The repository in which to build the tree. Must not be nil.
/// error - The error if one occurred.
///
/// Returns the initialized object, or nil if an error occurred.
- (id)initWithTree:(GTTree *)treeOrNil error:(NSError **)error;
- (id)initWithTree:(GTTree *)treeOrNil repository:(GTRepository *)repository error:(NSError **)error;

/// The underlying `git_treebuilder` object.
- (git_treebuilder *)git_treebuilder __attribute__((objc_returns_inner_pointer));
Expand Down Expand Up @@ -118,10 +119,9 @@ typedef NS_ENUM(NSInteger, GTFileMode) {

/// Write the contents of the tree builder as a tree object.
///
/// repository - Repository in which to write the tree.
/// error - The error if one occurred.
/// error - The error if one occurred.
///
/// Returns the written tree, or nil if an error occurred.
- (GTTree *)writeTreeToRepository:(GTRepository *)repository error:(NSError **)error;
- (GTTree *)writeTree:(NSError **)error;

@end
36 changes: 20 additions & 16 deletions ObjectiveGit/GTTreeBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
@interface GTTreeBuilder ()

@property (nonatomic, assign, readonly) git_treebuilder *git_treebuilder;
@property (nonatomic, strong, readonly) GTRepository *repository;

// Data to be written with the tree, keyed by the file name. This should only be
// accessed while synchronized on self.
Expand All @@ -61,16 +62,19 @@ - (NSUInteger)entryCount {

#pragma mark Lifecycle

- (id)initWithTree:(GTTree *)treeOrNil error:(NSError **)error {
- (id)initWithTree:(GTTree *)treeOrNil repository:(GTRepository *)repository error:(NSError **)error {
NSParameterAssert(repository != nil);

self = [super init];
if (self == nil) return nil;

int status = git_treebuilder_create(&_git_treebuilder, treeOrNil.git_tree);
int status = git_treebuilder_create(&_git_treebuilder, repository.git_repository, treeOrNil.git_tree);
if (status != GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:status description:@"Failed to create tree builder with tree %@.", treeOrNil.SHA];
return nil;
}

_repository = repository;
_fileNameToPendingData = [NSMutableDictionary dictionary];

return self;
Expand All @@ -86,7 +90,7 @@ - (void)dealloc {
#pragma mark Modification

- (void)clear {
git_treebuilder_clear(self.git_treebuilder);
git_treebuilder_clear(self.git_treebuilder);
}

static int filter_callback(const git_tree_entry *entry, void *payload) {
Expand All @@ -105,7 +109,7 @@ - (GTTreeEntry *)entryWithFileName:(NSString *)fileName {

const git_tree_entry *entry = git_treebuilder_get(self.git_treebuilder, fileName.UTF8String);
if (entry == NULL) return nil;

return [GTTreeEntry entryWithEntry:entry parentTree:nil];
}

Expand All @@ -129,12 +133,12 @@ - (GTTreeEntry *)addEntryWithOID:(GTOID *)oid fileName:(NSString *)fileName file

const git_tree_entry *entry = NULL;
int status = git_treebuilder_insert(&entry, self.git_treebuilder, fileName.UTF8String, oid.git_oid, (git_filemode_t)fileMode);

if (status != GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:status description:@"Failed to add entry %@ to tree builder.", oid.SHA];
return nil;
}

return [GTTreeEntry entryWithEntry:entry parentTree:nil];
}

Expand All @@ -147,19 +151,19 @@ - (BOOL)removeEntryWithFileName:(NSString *)fileName error:(NSError **)error {
@synchronized (self) {
[self.fileNameToPendingData removeObjectForKey:fileName];
}

return status == GIT_OK;
}

- (BOOL)writePendingDataToRepository:(GTRepository *)repository error:(NSError **)error {
- (BOOL)writePendingData:(NSError **)error {
NSDictionary *copied;
@synchronized (self) {
copied = [self.fileNameToPendingData copy];
[self.fileNameToPendingData removeAllObjects];
}

if (copied.count != 0) {
GTObjectDatabase *odb = [repository objectDatabaseWithError:error];
GTObjectDatabase *odb = [self.repository objectDatabaseWithError:error];
if (odb == nil) return NO;

for (NSString *fileName in copied) {
Expand All @@ -172,25 +176,25 @@ - (BOOL)writePendingDataToRepository:(GTRepository *)repository error:(NSError *
return YES;
}

- (GTTree *)writeTreeToRepository:(GTRepository *)repository error:(NSError **)error {
BOOL success = [self writePendingDataToRepository:repository error:error];
- (GTTree *)writeTree:(NSError **)error {
BOOL success = [self writePendingData:error];
if (!success) return nil;

git_oid treeOid;
int status = git_treebuilder_write(&treeOid, repository.git_repository, self.git_treebuilder);
int status = git_treebuilder_write(&treeOid, self.git_treebuilder);
if (status != GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:status description:@"Failed to write tree in repository."];
return nil;
}

git_object *object = NULL;
status = git_object_lookup(&object, repository.git_repository, &treeOid, GIT_OBJ_TREE);
status = git_object_lookup(&object, self.repository.git_repository, &treeOid, GIT_OBJ_TREE);
if (status != GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:status description:@"Failed to lookup tree in repository."];
return nil;
}
return [GTObject objectWithObj:object inRepository:repository];

return [GTObject objectWithObj:object inRepository:self.repository];
}

@end
4 changes: 2 additions & 2 deletions ObjectiveGitTests/GTRemotePushSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

// Helper to quickly create commits
GTCommit *(^createCommitInRepository)(NSString *, NSData *, NSString *, GTRepository *) = ^ GTCommit * (NSString *message, NSData *fileData, NSString *fileName, GTRepository *repo) {
GTTreeBuilder *treeBuilder = [[GTTreeBuilder alloc] initWithTree:nil error:nil];
GTTreeBuilder *treeBuilder = [[GTTreeBuilder alloc] initWithTree:nil repository:repo error:nil];
[treeBuilder addEntryWithData:fileData fileName:fileName fileMode:GTFileModeBlob error:nil];

GTTree *testTree = [treeBuilder writeTreeToRepository:repo error:nil];
GTTree *testTree = [treeBuilder writeTree:nil];

// We need the parent commit to make the new one
GTReference *headReference = [repo headReferenceWithError:nil];
Expand Down
4 changes: 2 additions & 2 deletions ObjectiveGitTests/GTRemoteSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@

// Helper to quickly create commits
GTCommit *(^createCommitInRepository)(NSString *, NSData *, NSString *, GTRepository *) = ^(NSString *message, NSData *fileData, NSString *fileName, GTRepository *repo) {
GTTreeBuilder *treeBuilder = [[GTTreeBuilder alloc] initWithTree:nil error:nil];
GTTreeBuilder *treeBuilder = [[GTTreeBuilder alloc] initWithTree:nil repository:repo error:nil];
[treeBuilder addEntryWithData:fileData fileName:fileName fileMode:GTFileModeBlob error:nil];

GTTree *testTree = [treeBuilder writeTreeToRepository:repo error:nil];
GTTree *testTree = [treeBuilder writeTree:nil];

// We need the parent commit to make the new one
GTReference *headReference = [repo headReferenceWithError:nil];
Expand Down
6 changes: 3 additions & 3 deletions ObjectiveGitTests/GTRepositoryCommittingSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
});

it(@"can create commits", ^{
GTTreeBuilder *builder = [[GTTreeBuilder alloc] initWithTree:nil error:NULL];
GTTreeBuilder *builder = [[GTTreeBuilder alloc] initWithTree:nil repository:repository error:NULL];
expect(builder).notTo(beNil());

GTTreeEntry *entry = [builder addEntryWithData:[@"Another file contents" dataUsingEncoding:NSUTF8StringEncoding] fileName:@"Test file 2.txt" fileMode:GTFileModeBlob error:NULL];
expect(entry).notTo(beNil());

GTTree *subtree = [builder writeTreeToRepository:repository error:NULL];
GTTree *subtree = [builder writeTree:NULL];
expect(subtree).notTo(beNil());

[builder clear];
Expand All @@ -44,7 +44,7 @@
entry = [builder addEntryWithOID:subtree.OID fileName:@"subdir" fileMode:GTFileModeTree error:NULL];
expect(entry).notTo(beNil());

GTTree *tree = [builder writeTreeToRepository:repository error:NULL];
GTTree *tree = [builder writeTree:NULL];
expect(tree).notTo(beNil());

GTCommit *initialCommit = [repository createCommitWithTree:tree message:@"Initial commit" parents:nil updatingReferenceNamed:@"refs/heads/master" error:NULL];
Expand Down
29 changes: 12 additions & 17 deletions ObjectiveGitTests/GTTreeBuilderSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@

QuickSpecBegin(GTTreeBuilderSpec)

__block GTRepository *repo;

beforeEach(^{
repo = self.bareFixtureRepository;
expect(repo).notTo(beNil());
});

it(@"should be possible to make a new tree builder without a tree", ^{
NSError *error = nil;
GTTreeBuilder *builder = [[GTTreeBuilder alloc] initWithTree:nil error:&error];
GTTreeBuilder *builder = [[GTTreeBuilder alloc] initWithTree:nil repository:repo error:&error];
expect(error).to(beNil());
expect(builder).notTo(beNil());
});

it(@"should be possible to make a new tree builder from an existing tree", ^{
NSError *error = nil;

GTRepository *repo = self.bareFixtureRepository;
expect(repo).notTo(beNil());

GTTree *tree = (GTTree *)[repo lookUpObjectBySHA:testTreeSHA error:NULL];
expect(tree).notTo(beNil());

GTTreeBuilder *builder = [[GTTreeBuilder alloc] initWithTree:tree error:&error];
GTTreeBuilder *builder = [[GTTreeBuilder alloc] initWithTree:tree repository:repo error:&error];
expect(error).to(beNil());
expect(builder).notTo(beNil());
});
Expand All @@ -43,7 +47,7 @@
__block GTOID *OID;

beforeEach(^{
builder = [[GTTreeBuilder alloc] initWithTree:nil error:&error];
builder = [[GTTreeBuilder alloc] initWithTree:nil repository:repo error:&error];
expect(builder).notTo(beNil());
expect(error).to(beNil());

Expand Down Expand Up @@ -74,9 +78,6 @@
});

it(@"should be possible to filter a builder", ^{
GTRepository *repo = self.bareFixtureRepository;
expect(repo).notTo(beNil());

GTBlob *blob = [GTBlob blobWithString:@"Hi, how are you?" inRepository:repo error:&error];
expect(blob).notTo(beNil());
expect(error).to(beNil());
Expand All @@ -103,9 +104,6 @@
});

it(@"should write new blobs when the tree is written", ^{
GTRepository *repo = self.bareFixtureRepository;
expect(repo).notTo(beNil());

GTTreeEntry *entry = [builder addEntryWithData:[@"Hello, World!" dataUsingEncoding:NSUTF8StringEncoding] fileName:@"test.txt" fileMode:GTFileModeBlob error:NULL];
expect(entry).notTo(beNil());

Expand All @@ -114,23 +112,20 @@

expect(@([database containsObjectWithOID:entry.OID])).to(beFalsy());

GTTree *tree = [builder writeTreeToRepository:repo error:NULL];
GTTree *tree = [builder writeTree:NULL];
expect(tree).notTo(beNil());

expect(@([database containsObjectWithOID:entry.OID])).to(beTruthy());
});

it(@"should be possible to write a builder to a repository", ^{
GTRepository *repo = self.bareFixtureRepository;
expect(repo).notTo(beNil());

GTBlob *blob = [GTBlob blobWithString:@"Hi, how are you?" inRepository:repo error:&error];
expect(blob).notTo(beNil());
expect(error).to(beNil());

[builder addEntryWithOID:blob.OID fileName:@"hi.txt" fileMode:GTFileModeBlob error:&error];

GTTree *writtenTree = [builder writeTreeToRepository:repo error:&error];
GTTree *writtenTree = [builder writeTree:&error];
expect(writtenTree).notTo(beNil());
expect(error).to(beNil());

Expand Down

0 comments on commit b4ae265

Please sign in to comment.