Permalink
Browse files

some vain attempts to make this more stable as i learn obj-c memory m…

…anagement, and some small bug fixes
  • Loading branch information...
1 parent 45abfbb commit 679496b498a115871147d510c581ebe6f1726968 @schacon committed Oct 1, 2008
Showing with 36 additions and 27 deletions.
  1. +0 −1 ObjGit.h
  2. +5 −10 ObjGit.m
  3. +9 −8 ObjGitCommit.h
  4. +6 −0 ObjGitCommit.m
  5. +12 −2 ObjGitServerHandler.m
  6. +1 −1 ObjGitTree.h
  7. +3 −5 ObjGitTree.m
View
@@ -22,7 +22,6 @@
- (BOOL) ensureGitPath;
- (void) initGitRepo;
- (NSArray *) getAllRefs;
-- (NSString *) getName;
- (NSString *) writeObject:(NSData *)objectData withType:(NSString *)type withSize:(int)size;
- (void) updateRef:(NSString *)refName toSha:(NSString *)toSha;
View
@@ -26,13 +26,6 @@ - (void) dealloc
[super dealloc];
}
-- (NSString *) getName
-{
- NSLog(@"GIT NAME TEST");
- NSLog(@"GIT NAME:%@", self.gitName);
- return self.gitName;
-}
-
- (BOOL) ensureGitPath {
BOOL isDir;
NSFileManager *fm = [NSFileManager defaultManager];
@@ -155,16 +148,18 @@ - (NSMutableArray *) getCommitsFromSha:(NSString *)shaValue withLimit:(int)commi
}
// NSLog(@"s: %@", commitArray);
-
+ //[toDoArray release];
return commitArray;
}
- (ObjGitObject *) getObjectFromSha:(NSString *)sha1
{
NSString *objectPath = [self getLooseObjectPathBySha:sha1];
- NSLog(@"READ FROM FILE: %@", objectPath);
+ //NSLog(@"READ FROM FILE: %@", objectPath);
NSFileHandle *fm = [NSFileHandle fileHandleForReadingAtPath:objectPath];
- return [[ObjGitObject alloc] initFromRaw:[fm availableData] withSha:sha1];
+ ObjGitObject *obj = [[ObjGitObject alloc] initFromRaw:[fm availableData] withSha:sha1];
@sebnow

sebnow Dec 9, 2008

This should be autoreleased before returning. If it is only allocated, it must be released somewhere else. In Objective-C only objects that “own” something should retain, others should autorelease.

+ [fm closeFile];
+ return obj;
}
- (BOOL) hasObject: (NSString *)sha1
View
@@ -20,14 +20,14 @@
ObjGitObject *git_object;
}
-@property(assign, readwrite) NSString *sha;
-@property(assign, readwrite) NSArray *parentShas;
-@property(assign, readwrite) NSString *treeSha;
-@property(assign, readwrite) NSString *author;
-@property(assign, readwrite) NSString *author_email;
-@property(copy , readwrite) NSDate *authored_date;
-@property(assign, readwrite) NSString *committer;
-@property(assign, readwrite) NSString *committer_email;
+@property(copy, readwrite) NSString *sha;
+@property(copy, readwrite) NSArray *parentShas;
+@property(copy, readwrite) NSString *treeSha;
+@property(copy, readwrite) NSString *author;
+@property(copy, readwrite) NSString *author_email;
+@property(copy, readwrite) NSDate *authored_date;
+@property(copy, readwrite) NSString *committer;
+@property(copy, readwrite) NSString *committer_email;
@property(retain, readwrite) NSDate *committed_date;
@property(assign, readwrite) NSString *message;
@property(assign, readwrite) ObjGitObject *git_object;
@@ -36,6 +36,7 @@
- (id) initFromRaw:(NSData *)rawData withSha:(NSString *)shaValue;
- (void) parseContent;
- (void) logObject;
+- (NSArray *) authorArray;
- (NSArray *) parseAuthorString:(NSString *)authorString withType:(NSString *)typeString;
@end
View
@@ -47,6 +47,11 @@ - (void) logObject
NSLog(@"message : %@", message);
}
+- (NSArray *) authorArray
+{
+ return [NSArray arrayWithObjects:self.author, self.author_email, self.authored_date, nil];
+}
+
- (void) parseContent
{
// extract parent shas, tree sha, author/committer info, message
@@ -88,6 +93,7 @@ - (void) parseContent
}
} else {
[buildMessage appendString: line];
+ [buildMessage appendString: @"\n"];
}
}
self.message = buildMessage;
View
@@ -54,6 +54,7 @@ - (void) initWithGit:(ObjGit *)git gitPath:(NSString *)gitRepoPath input:(NSInpu
* either upload-pack for fetches or receive-pack for pushes
*/
- (void) handleRequest {
+ NSLog(@"HANDLE REQUEST");
NSString *header, *command, *repository, *repo, *hostpath;
header = [self packetReadLine];
@@ -84,6 +85,9 @@ - (void) uploadPack:(NSString *)repositoryName {
[self sendRefs];
[self receiveNeeds];
[self uploadPackFile];
+ //NSLog(@"out:%@", outStream);
+ //NSLog(@"out avail:%d", [outStream hasSpaceAvailable]);
+ //NSLog(@" in avail:%d", [inStream hasBytesAvailable]);
}
- (void) receiveNeeds
@@ -247,9 +251,11 @@ - (void) gatherObjectShasFromCommit:(NSString *)shaValue
- (void) gatherObjectShasFromTree:(NSString *)shaValue
{
- ObjGitTree *tree = [[ObjGitTree alloc] initFromGitObject:[gitRepo getObjectFromSha:shaValue]];
+ ObjGitTree *tree = [ObjGitTree alloc];
@sebnow

sebnow Dec 9, 2008

tree should be released at the end of the method. Releasing it where [tree release]; is commented might not be a good place since treeEntries is still being used.

+ [tree initFromGitObject:[gitRepo getObjectFromSha:shaValue]];
[refDict setObject:@"/" forKey:shaValue];
NSEnumerator *e = [[tree treeEntries] objectEnumerator];
+ //[tree release];
NSArray *entries;
NSString *name, *sha, *mode;
while ( (entries = [e nextObject]) ) {
@@ -419,6 +425,7 @@ - (void) unpackDeltified:(int)type size:(int)size {
contents = [self patchDelta:objectData withObject:object];
//NSLog(@"unpacked delta: %@ : %@", contents, [object type]);
[gitRepo writeObject:contents withType:[object type] withSize:[contents length]];
+ //[object release];
} else {
// TODO : OBJECT ISN'T HERE YET, SAVE THIS DELTA FOR LATER //
/*
@@ -510,10 +517,13 @@ - (NSData *) patchDelta:(NSData *)deltaData withObject:(ObjGitObject *)gitObject
[destination appendBytes:[buffer bytes] length:cp_size];
//NSLog(@"dest: %@", destination);
} else if(c[0] != 0) {
+ if(c[0] > destSize)
+ break;
//NSLog(@"thingy: %d, %d", position, c[0]);
- [source getBytes:[buffer mutableBytes] range:NSMakeRange(position, c[0])];
+ [deltaData getBytes:[buffer mutableBytes] range:NSMakeRange(position, c[0])];
[destination appendBytes:[buffer bytes] length:c[0]];
position += c[0];
+ destSize -= c[0];
} else {
NSLog(@"invalid delta data");
}
View
@@ -11,7 +11,7 @@
ObjGitObject *gitObject;
}
-@property(assign, readwrite) NSArray *treeEntries;
+@property(copy, readwrite) NSArray *treeEntries;
@property(assign, readwrite) ObjGitObject *gitObject;
- (id) initFromGitObject:(ObjGitObject *)object;
View
@@ -13,10 +13,8 @@ @implementation ObjGitTree
@synthesize gitObject;
- (id) initFromGitObject:(ObjGitObject *)object {
- NSLog(@"Tree init1");
self = [super init];
- NSLog(@"Tree init");
- gitObject = object;
+ self.gitObject = object;
[self parseContent];
return self;
}
@@ -29,7 +27,7 @@ - (void) logObject
// 100644 testfile\0[20 char sha]
- (void) parseContent
{
- char *contents = [gitObject rawContents];
+ char *contents = [self.gitObject rawContents];
char mode[9];
int modePtr = 0;
@@ -46,7 +44,7 @@ - (void) parseContent
int i, j, state;
state = 1;
- for(i = 0; i < [gitObject rawContentLen] - 1; i++) {
+ for(i = 0; i < [self.gitObject rawContentLen] - 1; i++) {
if(contents[i] == 0) {
state = 1;
for(j = 0; j < 20; j++)

3 comments on commit 679496b

@sebnow: I might have fixed several of these issues already in my fork. I also urge you to take a look at geoffgarside/cocoagit. Don’t be confused by the name, cocoagit only depends on Foundation, not cocoa. That codebase currently has pretty decent read-support for loose and packed objects. We just need to add some of the methods for writing loose objects and it should do what objective-git does (minus a few parts of the serverhandler) without any memory issues or GPL code.

Owner

schacon replied Dec 9, 2008

amazing – how did I not know about cocoagit? i could have sworn i searched for stuff before I started this. we should merge these projects – i can’t imagine it would be too hard…

@schacon: you sent me a message about it a months back, we discussed integration but didn’t get very far with it :-P
Shouldn’t be too difficult to merge the code provided the GPL isn’t an issue. I’d personally prefer to keep the MIT licence rather than move to GPL.

Please sign in to comment.