Permalink
Browse files

Merge branch 'development'

  • Loading branch information...
tclem committed Mar 23, 2011
2 parents 6a51f02 + e669088 commit 35d61efdf2316447a56116e2bd29b8b3fc968d12
Showing with 914 additions and 852 deletions.
  1. +25 −0 Classes/Categories/GTOdbObject.h
  2. +63 −0 Classes/Categories/GTOdbObject.m
  3. +2 −0 Classes/Categories/NSError+Git.h
  4. +9 −0 Classes/Categories/NSError+Git.m
  5. +16 −3 Classes/GTBlob.h
  6. +54 −12 Classes/GTBlob.m
  7. +25 −9 Classes/GTCommit.h
  8. +45 −31 Classes/GTCommit.m
  9. +4 −15 Classes/GTObject.h
  10. +5 −47 Classes/GTObject.m
  11. +0 −54 Classes/GTRawObject.h
  12. +0 −106 Classes/GTRawObject.m
  13. +9 −9 Classes/GTRepository.h
  14. +34 −22 Classes/GTRepository.m
  15. +10 −6 Classes/GTTag.h
  16. +23 −34 Classes/GTTag.m
  17. +7 −5 Classes/GTTree.h
  18. +4 −13 Classes/GTTree.m
  19. +9 −8 Classes/GTTreeEntry.h
  20. +20 −25 Classes/GTTreeEntry.m
  21. +14 −18 ObjectiveGitFramework.xcodeproj/project.pbxproj
  22. +1 −1 Tests/Contants.h
  23. +28 −8 Tests/GTBlobTest.m
  24. +21 −31 Tests/GTCommitTest.m
  25. +1 −1 Tests/GTIndexTest.m
  26. +1 −1 Tests/GTObjectTest.m
  27. +0 −29 Tests/GTRawObjectTest.m
  28. +1 −1 Tests/GTRepositoryPackTest.m
  29. +18 −24 Tests/GTRepositoryTest.m
  30. +3 −5 Tests/GTTagTest.m
  31. +31 −38 libgit2/include/git2/blob.h
  32. +129 −35 libgit2/include/git2/commit.h
  33. +6 −3 libgit2/include/git2/common.h
  34. +4 −55 libgit2/include/git2/object.h
  35. +145 −44 libgit2/include/git2/odb.h
  36. +38 −8 libgit2/include/git2/odb_backend.h
  37. +6 −10 libgit2/include/git2/repository.h
  38. +1 −1 libgit2/include/git2/signature.h
  39. +71 −32 libgit2/include/git2/tag.h
  40. +0 −2 libgit2/include/git2/thread-utils.h
  41. +20 −100 libgit2/include/git2/tree.h
  42. +11 −6 libgit2/include/git2/types.h
  43. BIN libgit2/lib/libgit2.a
@@ -0,0 +1,25 @@
+//
+// GTOdbObject.h
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 3/23/11.
+// Copyright 2011 GitHub, Inc. All rights reserved.
+//
+
+#import <git2.h>
+#import "GTObject.h"
+
+@interface GTOdbObject : NSObject {}
+
+@property (nonatomic, assign, readonly) git_odb_object *odbObject;
+
+- (id)initWithObject:(git_odb_object *)object;
++ (id)objectWithObject:(git_odb_object *)object;
+
+- (NSString *)hash;
+- (GTObjectType)type;
+- (NSUInteger)length;
+- (NSData *)data;
+- (NSString *)dataAsUTF8String;
+
+@end
@@ -0,0 +1,63 @@
+//
+// GTOdbObject.m
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 3/23/11.
+// Copyright 2011 GitHub, Inc. All rights reserved.
+//
+
+#import "GTOdbObject.h"
+#import "GTLib.h"
+#import "NSString+Git.h"
+
+@interface GTOdbObject()
+@property (nonatomic, assign) git_odb_object *odbObject;
+@end
+
+@implementation GTOdbObject
+
+#pragma mark API
+@synthesize odbObject;
+
+- (id)initWithObject:(git_odb_object *)object {
+
+ if((self = [super init])) {
+ self.odbObject = object;
+ }
+ return self;
+}
+
++ (id)objectWithObject:(git_odb_object *)object {
+
+ return [[[self alloc] initWithObject:object] autorelease];
+}
+
+- (NSString *)hash {
+
+ return [GTLib convertOidToSha:git_odb_object_id(self.odbObject)];
+}
+
+- (GTObjectType)type {
+
+ return git_odb_object_type(self.odbObject);
+}
+
+- (NSUInteger)length {
+
+ return git_odb_object_size(self.odbObject);
+}
+
+- (NSData *)data {
+
+ return [NSData dataWithBytes:git_odb_object_data(self.odbObject) length:[self length]];
+}
+
+- (NSString *)dataAsUTF8String {
+
+ NSData *data = [self data];
+ if(!data) return nil;
+
+ return [NSString stringWithUTF8String:[data bytes]];
+}
+
+@end
@@ -62,4 +62,6 @@
+ (NSError *)gitErrorForListAllRefs: (int)code;
+ (NSError *)gitErrorForNoBlockProvided;
++ (NSError *)gitErrorFor:(int)code withDescription:(NSString *)desc;
+
@end
@@ -296,4 +296,13 @@ + (NSError *)gitErrorForNoBlockProvided {
forKey:NSLocalizedDescriptionKey]];
}
++ (NSError *)gitErrorFor:(int)code withDescription:(NSString *)desc {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:-1
+ userInfo:
+ [NSDictionary dictionaryWithObject:desc
+ forKey:NSLocalizedDescriptionKey]];
+}
+
@end
View
@@ -33,9 +33,22 @@
@interface GTBlob : GTObject {}
-@property (nonatomic, assign, readonly) NSInteger size;
-@property (nonatomic, assign) NSString *content;
+// Convenience initializers
+//
+// These call the associated createInRepo: methods, but then lookup the newly
+// created blob in the repo and return it
++ (GTBlob *)blobInRepo:(GTRepository *)theRepo content:(NSString *)content error:(NSError **)error;
++ (GTBlob *)blobInRepo:(GTRepository *)theRepo data:(NSData *)data error:(NSError **)error;
++ (GTBlob *)blobInRepo:(GTRepository *)theRepo file:(NSURL *)file error:(NSError **)error;
-- (id)initInRepo:(GTRepository *)theRepo error:(NSError **)error;
+// Create a blob in the specified repository
+//
+// returns the sha1 of the created blob or nil if an error occurred
++ (NSString *)createInRepo:(GTRepository *)theRepo content:(NSString *)content error:(NSError **)error;
++ (NSString *)createInRepo:(GTRepository *)theRepo data:(NSData *)data error:(NSError **)error;
++ (NSString *)createInRepo:(GTRepository *)theRepo file:(NSURL *)file error:(NSError **)error;
+
+- (NSInteger)size;
+- (NSString *)content;
@end
View
@@ -29,7 +29,9 @@
#import "GTBlob.h"
#import "NSString+Git.h"
+#import "NSError+Git.h"
#import "GTRepository.h"
+#import "GTLib.h"
@implementation GTBlob
@@ -42,17 +44,61 @@ - (git_blob *)blob {
#pragma mark -
#pragma mark API
-@synthesize size;
-@synthesize content;
++ (GTBlob *)blobInRepo:(GTRepository *)theRepo content:(NSString *)content error:(NSError **)error {
+
+ NSString *sha = [GTBlob createInRepo:theRepo content:content error:error];
+ return sha ? (GTBlob *)[theRepo lookupBySha:sha type:GTObjectTypeBlob error:error] : nil;
+}
+
++ (GTBlob *)blobInRepo:(GTRepository *)theRepo data:(NSData *)data error:(NSError **)error {
+
+ NSString *sha = [GTBlob createInRepo:theRepo data:data error:error];
+ return sha ? (GTBlob *)[theRepo lookupBySha:sha type:GTObjectTypeBlob error:error] : nil;
+}
-- (id)initInRepo:(GTRepository *)theRepo error:(NSError **)error {
++ (GTBlob *)blobInRepo:(GTRepository *)theRepo file:(NSURL *)file error:(NSError **)error {
- if((self = [super init])) {
- self.repo = theRepo;
- self.object = [GTObject getNewObjectInRepo:self.repo.repo type:GTObjectTypeBlob error:error];
- if(self.object == nil)return nil;
+ NSString *sha = [GTBlob createInRepo:theRepo file:file error:error];
+ return sha ? (GTBlob *)[theRepo lookupBySha:sha type:GTObjectTypeBlob error:error] : nil;
+}
+
++ (NSString *)createInRepo:(GTRepository *)theRepo content:(NSString *)content error:(NSError **)error {
+
+ git_oid oid;
+ int gitError = git_blob_create_frombuffer(&oid, theRepo.repo, [NSString utf8StringForString:content], content.length);
+ if(gitError != GIT_SUCCESS) {
+ if(error != NULL)
+ *error = [NSError gitErrorFor:gitError withDescription:@"Failed to create blob from NSString"];
+ return nil;
}
- return self;
+
+ return [GTLib convertOidToSha:&oid];
+}
+
++ (NSString *)createInRepo:(GTRepository *)theRepo data:(NSData *)data error:(NSError **)error {
+
+ git_oid oid;
+ int gitError = git_blob_create_frombuffer(&oid, theRepo.repo, [data bytes], data.length);
+ if(gitError != GIT_SUCCESS) {
+ if(error != NULL)
+ *error = [NSError gitErrorFor:gitError withDescription:@"Failed to create blob from NSData"];
+ return nil;
+ }
+
+ return [GTLib convertOidToSha:&oid];
+}
+
++ (NSString *)createInRepo:(GTRepository *)theRepo file:(NSURL *)file error:(NSError **)error {
+
+ git_oid oid;
+ int gitError = git_blob_create_fromfile(&oid, theRepo.repo, [NSString utf8StringForString:[file path]]);
+ if(gitError != GIT_SUCCESS) {
+ if(error != NULL)
+ *error = [NSError gitErrorFor:gitError withDescription:@"Failed to create blob from NSURL"];
+ return nil;
+ }
+
+ return [GTLib convertOidToSha:&oid];
}
- (NSInteger)size {
@@ -67,9 +113,5 @@ - (NSString *)content {
return [NSString stringForUTF8String:git_blob_rawcontent(self.blob)];
}
-- (void)setContent:(NSString *)newContent {
-
- git_blob_set_rawcontent(self.blob, [NSString utf8StringForString:newContent], [newContent length]);
-}
@end
View
@@ -36,16 +36,32 @@
@interface GTCommit : GTObject {}
-@property (nonatomic, assign, readonly) git_commit *commit;
-@property (nonatomic, copy) NSString *message;
-@property (nonatomic, copy, readonly) NSString *messageShort;
-@property (nonatomic, copy, readonly) NSString *messageDetails;
-@property (nonatomic, assign, readonly) NSDate *date;
-@property (nonatomic, assign) GTSignature *author;
-@property (nonatomic, assign) GTSignature *committer;
-@property (nonatomic, assign) GTTree *tree;
@property (nonatomic, assign, readonly) NSArray *parents;
-- (id)initInRepo:(GTRepository *)theRepo error:(NSError **)error;
++ (GTCommit *)commitInRepo:(GTRepository *)theRepo
+ updateRefNamed:(NSString *)refName
+ author:(GTSignature *)authorSig
+ committer:(GTSignature *)committerSig
+ message:(NSString *)newMessage
+ tree:(GTTree *)theTree
+ parents:(NSArray *)theParents
+ error:(NSError **)error;
+
++ (NSString *)createCommitInRepo:(GTRepository *)theRepo
+ updateRefNamed:(NSString *)refName
+ author:(GTSignature *)authorSig
+ committer:(GTSignature *)committerSig
+ message:(NSString *)newMessage
+ tree:(GTTree *)theTree
+ parents:(NSArray *)theParents
+ error:(NSError **)error;
+
+- (NSString *)message;
+- (NSString *)messageShort;
+- (NSString *)messageDetails;
+- (NSDate *)date;
+- (GTSignature *)author;
+- (GTSignature *)committer;
+- (GTTree *)tree;
@end
View
@@ -30,6 +30,7 @@
#import "GTCommit.h"
#import "GTSignature.h"
#import "GTTree.h"
+#import "GTLib.h"
#import "NSString+Git.h"
#import "NSError+Git.h"
#import "GTRepository.h"
@@ -45,35 +46,60 @@ - (git_commit *)commit {
#pragma mark -
#pragma mark API
-@synthesize commit;
-@synthesize message;
-@synthesize messageShort;
-@synthesize messageDetails;
-@synthesize date;
-@synthesize author;
-@synthesize committer;
-@synthesize tree;
@synthesize parents;
-- (id)initInRepo:(GTRepository *)theRepo error:(NSError **)error {
-
- if((self = [super init])) {
- self.repo = theRepo;
- self.object = [GTObject getNewObjectInRepo:self.repo.repo type:GTObjectTypeCommit error:error];
- if(self.object == nil) return nil;
++ (GTCommit *)commitInRepo:(GTRepository *)theRepo
+ updateRefNamed:(NSString *)refName
+ author:(GTSignature *)authorSig
+ committer:(GTSignature *)committerSig
+ message:(NSString *)newMessage
+ tree:(GTTree *)theTree
+ parents:(NSArray *)theParents
+ error:(NSError **)error {
+
+ NSString *sha = [GTCommit createCommitInRepo:theRepo updateRefNamed:refName author:authorSig committer:committerSig message:newMessage tree:theTree parents:theParents error:error];
+ return sha ? (GTCommit *)[theRepo lookupBySha:sha type:GTObjectTypeCommit error:error] : nil;
+}
+
++ (NSString *)createCommitInRepo:(GTRepository *)theRepo
+ updateRefNamed:(NSString *)refName
+ author:(GTSignature *)authorSig
+ committer:(GTSignature *)committerSig
+ message:(NSString *)newMessage
+ tree:(GTTree *)theTree
+ parents:(NSArray *)theParents
+ error:(NSError **)error {
+
+ int count = theParents ? theParents.count : 0;
+ git_commit const *parentCommits[count];
+ for(int i = 0; i < count; i++){
+ parentCommits[i] = ((GTCommit *)[theParents objectAtIndex:i]).commit;
+ }
+
+ git_oid oid;
+ int gitError = git_commit_create_o(
+ &oid,
+ theRepo.repo,
+ refName ? [NSString utf8StringForString:refName] : NULL,
+ authorSig.signature,
+ committerSig.signature,
+ [NSString utf8StringForString:newMessage],
+ theTree.tree,
+ count,
+ parentCommits);
+ if(gitError != GIT_SUCCESS) {
+ if(error != NULL)
+ *error = [NSError gitErrorFor:gitError withDescription:@"Failed to create commit in repository"];
+ return nil;
}
- return self;
+ return [GTLib convertOidToSha:&oid];
}
- (NSString *)message {
const char *s = git_commit_message(self.commit);
return [NSString stringForUTF8String:s];
}
-- (void)setMessage:(NSString *)m {
-
- git_commit_set_message(self.commit, [NSString utf8StringForString:m]);
-}
- (NSString *)messageShort {
@@ -109,20 +135,12 @@ - (GTSignature *)author {
const git_signature *s = git_commit_author(self.commit);
return [GTSignature signatureWithSignature:(git_signature *)s];
}
-- (void)setAuthor:(GTSignature *)a {
-
- git_commit_set_author(self.commit, a.signature);
-}
- (GTSignature *)committer {
const git_signature *s = git_commit_committer(self.commit);
return [GTSignature signatureWithSignature:(git_signature *)s];
}
-- (void)setCommitter:(GTSignature *)c {
-
- git_commit_set_committer(self.commit, c.signature);
-}
- (GTTree *)tree {
@@ -136,10 +154,6 @@ - (GTTree *)tree {
}
return (GTTree *)[GTObject objectInRepo:self.repo withObject:(git_object *)t];
}
-- (void)setTree:(GTTree *)t {
-
- git_commit_set_tree(self.commit, t.tree);
-}
- (NSArray *)parents {
Oops, something went wrong.

0 comments on commit 35d61ef

Please sign in to comment.