From 6f83a7defdd4e0b2bf0a8692046070f80a948fb6 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 6 Jul 2013 10:50:40 +0200 Subject: [PATCH 01/16] Add methods to enumerate a GTTree. Also adds `-contents` for quick access. --- Classes/GTTree.h | 19 +++++++++++++++++++ Classes/GTTree.m | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/Classes/GTTree.h b/Classes/GTTree.h index 1ae19ddf6..11cfa3ca9 100644 --- a/Classes/GTTree.h +++ b/Classes/GTTree.h @@ -33,6 +33,11 @@ @class GTTreeEntry; @class GTIndex; +typedef enum GTTreeEnumerationOptions { + GTTreeEnumerationOptionPre = GIT_TREEWALK_PRE, + GTTreeEnumerationOptionPost = GIT_TREEWALK_POST, +} GTTreeEnumerationOptions; + @interface GTTree : GTObject // The number of entries in the tree. @@ -55,6 +60,20 @@ // returns a GTTreeEntry or nil if there is nothing with the specified name - (GTTreeEntry *)entryWithName:(NSString *)name; +// Enumerates the contents of the tree +// +// options - One of `GTTreeEnumerationOptionPre` (for pre-order walks) or +// `GTTreeEnumerationOptionPost` (for post-order walks). +// error - The error if one occurred. +// block - A block that will be called back with a path to the root of the tree +// and the current entry. +// +// returns an error code if one occurred, 0 otherwise +- (int)enumerateContentsWithOptions:(GTTreeEnumerationOptions)options error:(NSError **)error block:(int(^)(NSString *root, GTTreeEntry *entry))block; + +// Returns the contents of the tree, as an array of GTTreeEntries +- (NSArray *)contents; + // Merges the given tree into the receiver in memory and produces the result as // an index. // diff --git a/Classes/GTTree.m b/Classes/GTTree.m index ba495e700..f7d671540 100644 --- a/Classes/GTTree.m +++ b/Classes/GTTree.m @@ -33,6 +33,13 @@ #import "GTIndex.h" #import "NSError+Git.h" +typedef int(^GTTreeEnumerationBlock)(NSString *root, GTTreeEntry *entry); + +typedef struct GTTreeEnumerationStruct { + __unsafe_unretained GTTree *myself; + __unsafe_unretained GTTreeEnumerationBlock block; +} GTTreeEnumerationStruct; + @implementation GTTree - (NSString *)description { @@ -61,6 +68,40 @@ - (git_tree *)git_tree { return (git_tree *)self.git_object; } +#pragma mark Contents + +static int treewalk_cb(const char *root, const git_tree_entry *git_entry, void *payload) { + GTTreeEnumerationStruct *enumStruct = (GTTreeEnumerationStruct *)payload; + NSString *rootString = @(root); + GTTreeEntry *entry = [[GTTreeEntry alloc] initWithEntry:git_entry parentTree:enumStruct->myself]; + return enumStruct->block(rootString, entry); +} + + +- (int)enumerateContentsWithOptions:(GTTreeEnumerationOptions)option error:(NSError **)error block:(GTTreeEnumerationBlock)block { + NSParameterAssert(block != nil); + + GTTreeEnumerationStruct enumStruct = { + .myself = self, + .block = block, + }; + + int gitError = git_tree_walk(self.git_tree, (git_treewalk_mode)option, treewalk_cb, &enumStruct); + if (gitError != GIT_OK) { + if (*error != NULL) *error = [NSError git_errorFor:gitError withAdditionalDescription:@"Failed to enumerate tree"]; + } + return gitError; +} + +- (NSArray *)contents { + __block NSMutableArray *_contents = [NSMutableArray array]; + int gitError = [self enumerateContentsWithOptions:GTTreeEnumerationOptionPre error:NULL block:^int(NSString *root, GTTreeEntry *entry) { + [_contents addObject:entry]; + return 0; + }]; + return _contents; +} + #pragma mark Merging - (GTIndex *)merge:(GTTree *)otherTree ancestor:(GTTree *)ancestorTree error:(NSError **)error { From c9298d9c2d16befa07320927440b72fcdbe3db28 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sat, 6 Jul 2013 14:13:43 +0200 Subject: [PATCH 02/16] Log the error if the enumeration fails. --- Classes/GTTree.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Classes/GTTree.m b/Classes/GTTree.m index f7d671540..965581ebc 100644 --- a/Classes/GTTree.m +++ b/Classes/GTTree.m @@ -94,11 +94,16 @@ - (int)enumerateContentsWithOptions:(GTTreeEnumerationOptions)option error:(NSEr } - (NSArray *)contents { + NSError *error = nil; __block NSMutableArray *_contents = [NSMutableArray array]; - int gitError = [self enumerateContentsWithOptions:GTTreeEnumerationOptionPre error:NULL block:^int(NSString *root, GTTreeEntry *entry) { + int gitError = [self enumerateContentsWithOptions:GTTreeEnumerationOptionPre error:&error block:^int(NSString *root, GTTreeEntry *entry) { [_contents addObject:entry]; return 0; }]; + if (gitError != GIT_OK) { + NSLog(@"%@", error); + return nil; + } return _contents; } From 496c36b4fcde5b755b6e7aab326f3f80fcee89b9 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sun, 7 Jul 2013 12:29:00 +0200 Subject: [PATCH 03/16] Add private methods to get a GTTreeEntry underlying object type Also use that in `-description`. --- Classes/GTTreeEntry.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Classes/GTTreeEntry.m b/Classes/GTTreeEntry.m index 1af0be721..e8a5d0620 100644 --- a/Classes/GTTreeEntry.m +++ b/Classes/GTTreeEntry.m @@ -41,7 +41,7 @@ @interface GTTreeEntry () @implementation GTTreeEntry - (NSString *)description { - return [NSString stringWithFormat:@"<%@: %p> name: %@, sha: %@ attributes: %lu", NSStringFromClass([self class]), self, [self name], [self sha], (unsigned long)[self attributes]]; + return [NSString stringWithFormat:@"<%@: %p> name: %@, type: %@, sha: %@, attributes: %lu", NSStringFromClass([self class]), self, [self name], [self typeString], [self sha], (unsigned long)[self attributes]]; } #pragma mark API @@ -70,6 +70,15 @@ - (NSString *)sha { return [NSString git_stringWithOid:git_tree_entry_id(self.git_tree_entry)]; } + +- (GTObjectType)_type { + return (GTObjectType)git_tree_entry_type(self.git_tree_entry); +} + +- (NSString *)typeString { + return @(git_object_type2string(git_tree_entry_type(self.git_tree_entry))); +} + - (GTRepository *)repository { return self.tree.repository; } From 9a2f2933de6a33fd54c0e957edbafc944bcd2f75 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sun, 7 Jul 2013 12:29:52 +0200 Subject: [PATCH 04/16] Implement GTTreeEntry equality. --- Classes/GTTreeEntry.m | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Classes/GTTreeEntry.m b/Classes/GTTreeEntry.m index e8a5d0620..940da9534 100644 --- a/Classes/GTTreeEntry.m +++ b/Classes/GTTreeEntry.m @@ -40,10 +40,27 @@ @interface GTTreeEntry () @implementation GTTreeEntry +#pragma mark NSObject + - (NSString *)description { return [NSString stringWithFormat:@"<%@: %p> name: %@, type: %@, sha: %@, attributes: %lu", NSStringFromClass([self class]), self, [self name], [self typeString], [self sha], (unsigned long)[self attributes]]; } +- (NSUInteger)hash { + return [self.sha hash]; +} + +- (BOOL)isEqual:(id)object { + if ([object isKindOfClass:[self class]]) { + return [self isEqualToEntry:object]; + } + return [super isEqual:object]; +} + +- (BOOL)isEqualToEntry:(GTTreeEntry *)treeEntry { + return git_tree_entry_cmp(self.git_tree_entry, treeEntry.git_tree_entry) == 0 ? YES : NO; +} + #pragma mark API - (id)initWithEntry:(const git_tree_entry *)theEntry parentTree:(GTTree *)parent { From 2f3906b5b6822d685f7121932fa832a589330a72 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sun, 7 Jul 2013 12:32:45 +0200 Subject: [PATCH 05/16] Make `-contents` not recursive. --- Classes/GTTree.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/GTTree.m b/Classes/GTTree.m index 965581ebc..2b7b90242 100644 --- a/Classes/GTTree.m +++ b/Classes/GTTree.m @@ -98,9 +98,9 @@ - (NSArray *)contents { __block NSMutableArray *_contents = [NSMutableArray array]; int gitError = [self enumerateContentsWithOptions:GTTreeEnumerationOptionPre error:&error block:^int(NSString *root, GTTreeEntry *entry) { [_contents addObject:entry]; - return 0; + return [entry _type] == GTObjectTypeTree ? 1 : 0; }]; - if (gitError != GIT_OK) { + if (gitError < GIT_OK) { NSLog(@"%@", error); return nil; } From 14f1549a7f0dd84a23d7d754da50133cb0315114 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sun, 7 Jul 2013 12:34:43 +0200 Subject: [PATCH 06/16] Provide the correct parent to GTTreeEntry initializer. --- Classes/GTTree.m | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Classes/GTTree.m b/Classes/GTTree.m index 2b7b90242..5806f1add 100644 --- a/Classes/GTTree.m +++ b/Classes/GTTree.m @@ -38,8 +38,13 @@ typedef struct GTTreeEnumerationStruct { __unsafe_unretained GTTree *myself; __unsafe_unretained GTTreeEnumerationBlock block; + __unsafe_unretained NSMutableDictionary *directoryStructure; } GTTreeEnumerationStruct; +@interface GTTreeEntry (GTPrivate) +- (GTObjectType)_type; +@end + @implementation GTTree - (NSString *)description { @@ -73,7 +78,15 @@ - (git_tree *)git_tree { static int treewalk_cb(const char *root, const git_tree_entry *git_entry, void *payload) { GTTreeEnumerationStruct *enumStruct = (GTTreeEnumerationStruct *)payload; NSString *rootString = @(root); - GTTreeEntry *entry = [[GTTreeEntry alloc] initWithEntry:git_entry parentTree:enumStruct->myself]; + GTTreeEntry *parentEntry = [enumStruct->directoryStructure objectForKey:rootString]; + GTTree *parentTree = parentEntry ? parentEntry.tree : enumStruct->myself; + + GTTreeEntry *entry = [[GTTreeEntry alloc] initWithEntry:git_entry parentTree:parentTree]; + if ([entry _type] == GTObjectTypeTree) { + NSString *path = [entry.name stringByAppendingString:@"/"]; + path = [rootString stringByAppendingString:path]; + [enumStruct->directoryStructure setObject:entry forKey:path]; + } return enumStruct->block(rootString, entry); } @@ -81,9 +94,12 @@ static int treewalk_cb(const char *root, const git_tree_entry *git_entry, void * - (int)enumerateContentsWithOptions:(GTTreeEnumerationOptions)option error:(NSError **)error block:(GTTreeEnumerationBlock)block { NSParameterAssert(block != nil); + NSMutableDictionary *structure = [[NSMutableDictionary alloc] initWithCapacity:[self entryCount]]; + GTTreeEnumerationStruct enumStruct = { .myself = self, .block = block, + .directoryStructure = structure, }; int gitError = git_tree_walk(self.git_tree, (git_treewalk_mode)option, treewalk_cb, &enumStruct); From 49119364037eeaaea89f15c04b0102bc4e5cbbc8 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sun, 7 Jul 2013 12:48:41 +0200 Subject: [PATCH 07/16] Tests for `-contents`. --- ObjectiveGitTests/GTTreeSpec.m | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ObjectiveGitTests/GTTreeSpec.m b/ObjectiveGitTests/GTTreeSpec.m index 1c95a370f..7aac3f4c4 100644 --- a/ObjectiveGitTests/GTTreeSpec.m +++ b/ObjectiveGitTests/GTTreeSpec.m @@ -35,4 +35,19 @@ expect(entry.sha).to.equal(@"1385f264afb75a56a5bec74243be9b367ba4ca08"); }); +it(@"should give quick access to its contents", ^{ + NSArray *treeContents = tree.contents; + expect(treeContents).notTo.beNil(); + expect(treeContents.count).to.equal(3); + GTTreeEntry *readme = [tree entryWithName:@"README"]; + GTTreeEntry *newTxt = [tree entryWithName:@"new.txt"]; + GTTreeEntry *subdir = [tree entryWithName:@"subdir"]; + expect(readme).notTo.beNil(); + expect(newTxt).notTo.beNil(); + expect(subdir).notTo.beNil(); + expect(treeContents).to.contain(readme); + expect(treeContents).to.contain(newTxt); + expect(treeContents).to.contain(subdir); +}); + SpecEnd From d522e75b56781e6cd9bb70184011532e03081478 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Wed, 10 Jul 2013 17:07:22 +0200 Subject: [PATCH 08/16] Document those. --- Classes/GTTree.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/GTTree.h b/Classes/GTTree.h index 11cfa3ca9..acd29be96 100644 --- a/Classes/GTTree.h +++ b/Classes/GTTree.h @@ -34,8 +34,8 @@ @class GTIndex; typedef enum GTTreeEnumerationOptions { - GTTreeEnumerationOptionPre = GIT_TREEWALK_PRE, - GTTreeEnumerationOptionPost = GIT_TREEWALK_POST, + GTTreeEnumerationOptionPre = GIT_TREEWALK_PRE, // Walk the tree in pre-order (subdirectories come first) + GTTreeEnumerationOptionPost = GIT_TREEWALK_POST, // Walk the tree in post-order (subdirectories come last) } GTTreeEnumerationOptions; @interface GTTree : GTObject From afcbc519a0cb1b76c93fbecd8346637004b9c5d5 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Wed, 10 Jul 2013 17:07:41 +0200 Subject: [PATCH 09/16] Return a BOOL instead of the libgit2 error code. --- Classes/GTTree.h | 4 ++-- Classes/GTTree.m | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Classes/GTTree.h b/Classes/GTTree.h index acd29be96..a6591af87 100644 --- a/Classes/GTTree.h +++ b/Classes/GTTree.h @@ -68,8 +68,8 @@ typedef enum GTTreeEnumerationOptions { // block - A block that will be called back with a path to the root of the tree // and the current entry. // -// returns an error code if one occurred, 0 otherwise -- (int)enumerateContentsWithOptions:(GTTreeEnumerationOptions)options error:(NSError **)error block:(int(^)(NSString *root, GTTreeEntry *entry))block; +// returns YES if the enumeration completed successfully, NO otherwise +- (BOOL)enumerateContentsWithOptions:(GTTreeEnumerationOptions)options error:(NSError **)error block:(int(^)(NSString *root, GTTreeEntry *entry))block; // Returns the contents of the tree, as an array of GTTreeEntries - (NSArray *)contents; diff --git a/Classes/GTTree.m b/Classes/GTTree.m index 5806f1add..704a1918e 100644 --- a/Classes/GTTree.m +++ b/Classes/GTTree.m @@ -91,7 +91,7 @@ static int treewalk_cb(const char *root, const git_tree_entry *git_entry, void * } -- (int)enumerateContentsWithOptions:(GTTreeEnumerationOptions)option error:(NSError **)error block:(GTTreeEnumerationBlock)block { +- (BOOL)enumerateContentsWithOptions:(GTTreeEnumerationOptions)option error:(NSError **)error block:(GTTreeEnumerationBlock)block { NSParameterAssert(block != nil); NSMutableDictionary *structure = [[NSMutableDictionary alloc] initWithCapacity:[self entryCount]]; @@ -106,7 +106,7 @@ - (int)enumerateContentsWithOptions:(GTTreeEnumerationOptions)option error:(NSEr if (gitError != GIT_OK) { if (*error != NULL) *error = [NSError git_errorFor:gitError withAdditionalDescription:@"Failed to enumerate tree"]; } - return gitError; + return gitError != GIT_OK; } - (NSArray *)contents { From e40b9bc16c330ec170f47a4256d925a9ef03ba4d Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Wed, 10 Jul 2013 17:08:28 +0200 Subject: [PATCH 10/16] Document the enumeration block return type. --- Classes/GTTree.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Classes/GTTree.h b/Classes/GTTree.h index a6591af87..0f02a7619 100644 --- a/Classes/GTTree.h +++ b/Classes/GTTree.h @@ -67,6 +67,8 @@ typedef enum GTTreeEnumerationOptions { // error - The error if one occurred. // block - A block that will be called back with a path to the root of the tree // and the current entry. +// Return a negative value to stop the walk, a positive one to skip the +// descendents of the entry, or 0 to continue the enumeration. // // returns YES if the enumeration completed successfully, NO otherwise - (BOOL)enumerateContentsWithOptions:(GTTreeEnumerationOptions)options error:(NSError **)error block:(int(^)(NSString *root, GTTreeEntry *entry))block; From 68627ce156f27882b7ff590078d8db3383bf5f68 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Wed, 10 Jul 2013 17:10:53 +0200 Subject: [PATCH 11/16] Use `-stringByAppendingPathComponent:` here --- Classes/GTTree.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Classes/GTTree.m b/Classes/GTTree.m index 704a1918e..baff1778f 100644 --- a/Classes/GTTree.m +++ b/Classes/GTTree.m @@ -83,8 +83,7 @@ static int treewalk_cb(const char *root, const git_tree_entry *git_entry, void * GTTreeEntry *entry = [[GTTreeEntry alloc] initWithEntry:git_entry parentTree:parentTree]; if ([entry _type] == GTObjectTypeTree) { - NSString *path = [entry.name stringByAppendingString:@"/"]; - path = [rootString stringByAppendingString:path]; + NSString *path = [rootString stringByAppendingPathComponent:entry.name]; [enumStruct->directoryStructure setObject:entry forKey:path]; } return enumStruct->block(rootString, entry); From 91324391fe36172a96522035b54edf99d481d542 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Wed, 10 Jul 2013 17:11:35 +0200 Subject: [PATCH 12/16] Use object subscripting. --- Classes/GTTree.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/GTTree.m b/Classes/GTTree.m index baff1778f..8d540f371 100644 --- a/Classes/GTTree.m +++ b/Classes/GTTree.m @@ -78,13 +78,13 @@ - (git_tree *)git_tree { static int treewalk_cb(const char *root, const git_tree_entry *git_entry, void *payload) { GTTreeEnumerationStruct *enumStruct = (GTTreeEnumerationStruct *)payload; NSString *rootString = @(root); - GTTreeEntry *parentEntry = [enumStruct->directoryStructure objectForKey:rootString]; + GTTreeEntry *parentEntry = enumStruct->directoryStructure[rootString]; GTTree *parentTree = parentEntry ? parentEntry.tree : enumStruct->myself; GTTreeEntry *entry = [[GTTreeEntry alloc] initWithEntry:git_entry parentTree:parentTree]; if ([entry _type] == GTObjectTypeTree) { NSString *path = [rootString stringByAppendingPathComponent:entry.name]; - [enumStruct->directoryStructure setObject:entry forKey:path]; + enumStruct->directoryStructure[path] = entry; } return enumStruct->block(rootString, entry); } From 81a9d586ab272e351a6b80893ecb7044b32cc614 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Wed, 10 Jul 2013 17:11:48 +0200 Subject: [PATCH 13/16] NULL pointer dereference. --- Classes/GTTree.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/GTTree.m b/Classes/GTTree.m index 8d540f371..f4c3d1500 100644 --- a/Classes/GTTree.m +++ b/Classes/GTTree.m @@ -103,7 +103,7 @@ - (BOOL)enumerateContentsWithOptions:(GTTreeEnumerationOptions)option error:(NSE int gitError = git_tree_walk(self.git_tree, (git_treewalk_mode)option, treewalk_cb, &enumStruct); if (gitError != GIT_OK) { - if (*error != NULL) *error = [NSError git_errorFor:gitError withAdditionalDescription:@"Failed to enumerate tree"]; + if (error != NULL) *error = [NSError git_errorFor:gitError withAdditionalDescription:@"Failed to enumerate tree"]; } return gitError != GIT_OK; } From ae0d9d2fdafe50f4339fbccb96e49bfeabe13ffb Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Wed, 10 Jul 2013 17:12:01 +0200 Subject: [PATCH 14/16] Use dot-syntax. --- Classes/GTTreeEntry.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/GTTreeEntry.m b/Classes/GTTreeEntry.m index 940da9534..f6ac4f5c0 100644 --- a/Classes/GTTreeEntry.m +++ b/Classes/GTTreeEntry.m @@ -43,7 +43,7 @@ @implementation GTTreeEntry #pragma mark NSObject - (NSString *)description { - return [NSString stringWithFormat:@"<%@: %p> name: %@, type: %@, sha: %@, attributes: %lu", NSStringFromClass([self class]), self, [self name], [self typeString], [self sha], (unsigned long)[self attributes]]; + return [NSString stringWithFormat:@"<%@: %p> name: %@, type: %@, sha: %@, attributes: %lu", NSStringFromClass(self.class), self, self.name, self.typeString, self.sha, (unsigned long)self.attributes]; } - (NSUInteger)hash { From f4d75196a6ea6f89a127205034f2c2e6185f48b7 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Wed, 10 Jul 2013 17:15:13 +0200 Subject: [PATCH 15/16] Move private API in a separate file. --- Classes/GTTree.m | 9 +++------ Classes/GTTreeEntry+Private.h | 13 +++++++++++++ Classes/GTTreeEntry.m | 3 +-- ObjectiveGitFramework.xcodeproj/project.pbxproj | 5 +++++ 4 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 Classes/GTTreeEntry+Private.h diff --git a/Classes/GTTree.m b/Classes/GTTree.m index f4c3d1500..d7f5d5d08 100644 --- a/Classes/GTTree.m +++ b/Classes/GTTree.m @@ -32,6 +32,7 @@ #import "GTRepository.h" #import "GTIndex.h" #import "NSError+Git.h" +#import "GTTreeEntry+Private.h" typedef int(^GTTreeEnumerationBlock)(NSString *root, GTTreeEntry *entry); @@ -41,10 +42,6 @@ __unsafe_unretained NSMutableDictionary *directoryStructure; } GTTreeEnumerationStruct; -@interface GTTreeEntry (GTPrivate) -- (GTObjectType)_type; -@end - @implementation GTTree - (NSString *)description { @@ -82,7 +79,7 @@ static int treewalk_cb(const char *root, const git_tree_entry *git_entry, void * GTTree *parentTree = parentEntry ? parentEntry.tree : enumStruct->myself; GTTreeEntry *entry = [[GTTreeEntry alloc] initWithEntry:git_entry parentTree:parentTree]; - if ([entry _type] == GTObjectTypeTree) { + if ([entry type] == GTObjectTypeTree) { NSString *path = [rootString stringByAppendingPathComponent:entry.name]; enumStruct->directoryStructure[path] = entry; } @@ -113,7 +110,7 @@ - (NSArray *)contents { __block NSMutableArray *_contents = [NSMutableArray array]; int gitError = [self enumerateContentsWithOptions:GTTreeEnumerationOptionPre error:&error block:^int(NSString *root, GTTreeEntry *entry) { [_contents addObject:entry]; - return [entry _type] == GTObjectTypeTree ? 1 : 0; + return [entry type] == GTObjectTypeTree ? 1 : 0; }]; if (gitError < GIT_OK) { NSLog(@"%@", error); diff --git a/Classes/GTTreeEntry+Private.h b/Classes/GTTreeEntry+Private.h new file mode 100644 index 000000000..578dfa554 --- /dev/null +++ b/Classes/GTTreeEntry+Private.h @@ -0,0 +1,13 @@ +// +// GTTreeEntry+Private.h +// ObjectiveGitFramework +// +// Created by Etienne on 10/07/13. +// Copyright (c) 2013 GitHub, Inc. All rights reserved. +// + +#import + +@interface GTTreeEntry () +- (GTObjectType)type; +@end diff --git a/Classes/GTTreeEntry.m b/Classes/GTTreeEntry.m index f6ac4f5c0..cb01a9230 100644 --- a/Classes/GTTreeEntry.m +++ b/Classes/GTTreeEntry.m @@ -87,8 +87,7 @@ - (NSString *)sha { return [NSString git_stringWithOid:git_tree_entry_id(self.git_tree_entry)]; } - -- (GTObjectType)_type { +- (GTObjectType)type { return (GTObjectType)git_tree_entry_type(self.git_tree_entry); } diff --git a/ObjectiveGitFramework.xcodeproj/project.pbxproj b/ObjectiveGitFramework.xcodeproj/project.pbxproj index 7bda5de99..58bcb0c78 100644 --- a/ObjectiveGitFramework.xcodeproj/project.pbxproj +++ b/ObjectiveGitFramework.xcodeproj/project.pbxproj @@ -89,6 +89,7 @@ 30FDC08116835A8100654BF0 /* GTDiffLine.m in Sources */ = {isa = PBXBuildFile; fileRef = 30FDC07E16835A8100654BF0 /* GTDiffLine.m */; }; 30FDC08216835A8100654BF0 /* GTDiffLine.m in Sources */ = {isa = PBXBuildFile; fileRef = 30FDC07E16835A8100654BF0 /* GTDiffLine.m */; }; 3E0A23E5159E0FDB00A6068F /* GTObjectDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 55C8054C13861F34004DCB0F /* GTObjectDatabase.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4D26799F178DAF31002A2795 /* GTTreeEntry+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D26799D178DAF31002A2795 /* GTTreeEntry+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; 55C8054F13861FE7004DCB0F /* GTObjectDatabase.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C8054D13861F34004DCB0F /* GTObjectDatabase.m */; }; 55C8055013861FE7004DCB0F /* GTObjectDatabase.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C8054D13861F34004DCB0F /* GTObjectDatabase.m */; }; 55C8057A13875578004DCB0F /* NSString+Git.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C8057313874CDF004DCB0F /* NSString+Git.m */; }; @@ -332,6 +333,7 @@ 30FDC07D16835A8100654BF0 /* GTDiffLine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTDiffLine.h; sourceTree = ""; }; 30FDC07E16835A8100654BF0 /* GTDiffLine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTDiffLine.m; sourceTree = ""; }; 32DBCF5E0370ADEE00C91783 /* ObjectiveGitFramework_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectiveGitFramework_Prefix.pch; sourceTree = ""; }; + 4D26799D178DAF31002A2795 /* GTTreeEntry+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GTTreeEntry+Private.h"; sourceTree = ""; }; 55C8054C13861F34004DCB0F /* GTObjectDatabase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTObjectDatabase.h; sourceTree = ""; }; 55C8054D13861F34004DCB0F /* GTObjectDatabase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = GTObjectDatabase.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; 55C8057213874CDF004DCB0F /* NSString+Git.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Git.h"; sourceTree = ""; }; @@ -675,6 +677,7 @@ BD6B040F131496B8001909D0 /* GTTree.h */, BD6B0410131496B8001909D0 /* GTTree.m */, BD6B0415131496CC001909D0 /* GTTreeEntry.h */, + 4D26799D178DAF31002A2795 /* GTTreeEntry+Private.h */, BD6B0416131496CC001909D0 /* GTTreeEntry.m */, 5BE612861745EE3300266D8C /* GTTreeBuilder.h */, 5BE612871745EE3300266D8C /* GTTreeBuilder.m */, @@ -839,6 +842,7 @@ 6A74CA3616A942C000E1A3C5 /* GTConfiguration+Private.h in Headers */, 30B1E7EF1703522100D0814D /* NSDate+GTTimeAdditions.h in Headers */, D09C2E371755F16200065E36 /* GTSubmodule.h in Headers */, + 4D2679A0178DAF31002A2795 /* GTTreeEntry+Private.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -879,6 +883,7 @@ 8821547617147A5200D76B76 /* GTReflogEntry.h in Headers */, 30B1E7EE1703522100D0814D /* NSDate+GTTimeAdditions.h in Headers */, D09C2E361755F16200065E36 /* GTSubmodule.h in Headers */, + 4D26799F178DAF31002A2795 /* GTTreeEntry+Private.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; From d4a592a0bd96fb5c26023a8f46293d3bbb3b7024 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Wed, 10 Jul 2013 17:17:30 +0200 Subject: [PATCH 16/16] The enumeration block can't be nil. --- Classes/GTTree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/GTTree.h b/Classes/GTTree.h index 0f02a7619..3dd872322 100644 --- a/Classes/GTTree.h +++ b/Classes/GTTree.h @@ -66,7 +66,7 @@ typedef enum GTTreeEnumerationOptions { // `GTTreeEnumerationOptionPost` (for post-order walks). // error - The error if one occurred. // block - A block that will be called back with a path to the root of the tree -// and the current entry. +// and the current entry. Cannot be nil. // Return a negative value to stop the walk, a positive one to skip the // descendents of the entry, or 0 to continue the enumeration. //