Skip to content

Commit

Permalink
some vain attempts to make this more stable as i learn obj-c memory m…
Browse files Browse the repository at this point in the history
…anagement, and some small bug fixes
  • Loading branch information
schacon committed Oct 1, 2008
1 parent 45abfbb commit 679496b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 27 deletions.
1 change: 0 additions & 1 deletion ObjGit.h
Expand Up @@ -22,7 +22,6 @@
- (BOOL) ensureGitPath; - (BOOL) ensureGitPath;
- (void) initGitRepo; - (void) initGitRepo;
- (NSArray *) getAllRefs; - (NSArray *) getAllRefs;
- (NSString *) getName;


- (NSString *) writeObject:(NSData *)objectData withType:(NSString *)type withSize:(int)size; - (NSString *) writeObject:(NSData *)objectData withType:(NSString *)type withSize:(int)size;
- (void) updateRef:(NSString *)refName toSha:(NSString *)toSha; - (void) updateRef:(NSString *)refName toSha:(NSString *)toSha;
Expand Down
15 changes: 5 additions & 10 deletions ObjGit.m
Expand Up @@ -26,13 +26,6 @@ - (void) dealloc
[super dealloc]; [super dealloc];
} }


- (NSString *) getName
{
NSLog(@"GIT NAME TEST");
NSLog(@"GIT NAME:%@", self.gitName);
return self.gitName;
}

- (BOOL) ensureGitPath { - (BOOL) ensureGitPath {
BOOL isDir; BOOL isDir;
NSFileManager *fm = [NSFileManager defaultManager]; NSFileManager *fm = [NSFileManager defaultManager];
Expand Down Expand Up @@ -155,16 +148,18 @@ - (NSMutableArray *) getCommitsFromSha:(NSString *)shaValue withLimit:(int)commi
} }


// NSLog(@"s: %@", commitArray); // NSLog(@"s: %@", commitArray);

//[toDoArray release];
return commitArray; return commitArray;
} }


- (ObjGitObject *) getObjectFromSha:(NSString *)sha1 - (ObjGitObject *) getObjectFromSha:(NSString *)sha1
{ {
NSString *objectPath = [self getLooseObjectPathBySha:sha1]; NSString *objectPath = [self getLooseObjectPathBySha:sha1];
NSLog(@"READ FROM FILE: %@", objectPath); //NSLog(@"READ FROM FILE: %@", objectPath);
NSFileHandle *fm = [NSFileHandle fileHandleForReadingAtPath:objectPath]; NSFileHandle *fm = [NSFileHandle fileHandleForReadingAtPath:objectPath];
return [[ObjGitObject alloc] initFromRaw:[fm availableData] withSha:sha1]; ObjGitObject *obj = [[ObjGitObject alloc] initFromRaw:[fm availableData] withSha:sha1];

This comment has been minimized.

Copy link
@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 - (BOOL) hasObject: (NSString *)sha1
Expand Down
17 changes: 9 additions & 8 deletions ObjGitCommit.h
Expand Up @@ -20,14 +20,14 @@
ObjGitObject *git_object; ObjGitObject *git_object;
} }


@property(assign, readwrite) NSString *sha; @property(copy, readwrite) NSString *sha;
@property(assign, readwrite) NSArray *parentShas; @property(copy, readwrite) NSArray *parentShas;
@property(assign, readwrite) NSString *treeSha; @property(copy, readwrite) NSString *treeSha;
@property(assign, readwrite) NSString *author; @property(copy, readwrite) NSString *author;
@property(assign, readwrite) NSString *author_email; @property(copy, readwrite) NSString *author_email;
@property(copy , readwrite) NSDate *authored_date; @property(copy, readwrite) NSDate *authored_date;
@property(assign, readwrite) NSString *committer; @property(copy, readwrite) NSString *committer;
@property(assign, readwrite) NSString *committer_email; @property(copy, readwrite) NSString *committer_email;
@property(retain, readwrite) NSDate *committed_date; @property(retain, readwrite) NSDate *committed_date;
@property(assign, readwrite) NSString *message; @property(assign, readwrite) NSString *message;
@property(assign, readwrite) ObjGitObject *git_object; @property(assign, readwrite) ObjGitObject *git_object;
Expand All @@ -36,6 +36,7 @@
- (id) initFromRaw:(NSData *)rawData withSha:(NSString *)shaValue; - (id) initFromRaw:(NSData *)rawData withSha:(NSString *)shaValue;
- (void) parseContent; - (void) parseContent;
- (void) logObject; - (void) logObject;
- (NSArray *) authorArray;
- (NSArray *) parseAuthorString:(NSString *)authorString withType:(NSString *)typeString; - (NSArray *) parseAuthorString:(NSString *)authorString withType:(NSString *)typeString;


@end @end
6 changes: 6 additions & 0 deletions ObjGitCommit.m
Expand Up @@ -47,6 +47,11 @@ - (void) logObject
NSLog(@"message : %@", message); NSLog(@"message : %@", message);
} }


- (NSArray *) authorArray
{
return [NSArray arrayWithObjects:self.author, self.author_email, self.authored_date, nil];
}

- (void) parseContent - (void) parseContent
{ {
// extract parent shas, tree sha, author/committer info, message // extract parent shas, tree sha, author/committer info, message
Expand Down Expand Up @@ -88,6 +93,7 @@ - (void) parseContent
} }
} else { } else {
[buildMessage appendString: line]; [buildMessage appendString: line];
[buildMessage appendString: @"\n"];
} }
} }
self.message = buildMessage; self.message = buildMessage;
Expand Down
14 changes: 12 additions & 2 deletions ObjGitServerHandler.m
Expand Up @@ -54,6 +54,7 @@ - (void) initWithGit:(ObjGit *)git gitPath:(NSString *)gitRepoPath input:(NSInpu
* either upload-pack for fetches or receive-pack for pushes * either upload-pack for fetches or receive-pack for pushes
*/ */
- (void) handleRequest { - (void) handleRequest {
NSLog(@"HANDLE REQUEST");
NSString *header, *command, *repository, *repo, *hostpath; NSString *header, *command, *repository, *repo, *hostpath;
header = [self packetReadLine]; header = [self packetReadLine];


Expand Down Expand Up @@ -84,6 +85,9 @@ - (void) uploadPack:(NSString *)repositoryName {
[self sendRefs]; [self sendRefs];
[self receiveNeeds]; [self receiveNeeds];
[self uploadPackFile]; [self uploadPackFile];
//NSLog(@"out:%@", outStream);
//NSLog(@"out avail:%d", [outStream hasSpaceAvailable]);
//NSLog(@" in avail:%d", [inStream hasBytesAvailable]);
} }


- (void) receiveNeeds - (void) receiveNeeds
Expand Down Expand Up @@ -247,9 +251,11 @@ - (void) gatherObjectShasFromCommit:(NSString *)shaValue


- (void) gatherObjectShasFromTree:(NSString *)shaValue - (void) gatherObjectShasFromTree:(NSString *)shaValue
{ {
ObjGitTree *tree = [[ObjGitTree alloc] initFromGitObject:[gitRepo getObjectFromSha:shaValue]]; ObjGitTree *tree = [ObjGitTree alloc];

This comment has been minimized.

Copy link
@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]; [refDict setObject:@"/" forKey:shaValue];
NSEnumerator *e = [[tree treeEntries] objectEnumerator]; NSEnumerator *e = [[tree treeEntries] objectEnumerator];
//[tree release];
NSArray *entries; NSArray *entries;
NSString *name, *sha, *mode; NSString *name, *sha, *mode;
while ( (entries = [e nextObject]) ) { while ( (entries = [e nextObject]) ) {
Expand Down Expand Up @@ -419,6 +425,7 @@ - (void) unpackDeltified:(int)type size:(int)size {
contents = [self patchDelta:objectData withObject:object]; contents = [self patchDelta:objectData withObject:object];
//NSLog(@"unpacked delta: %@ : %@", contents, [object type]); //NSLog(@"unpacked delta: %@ : %@", contents, [object type]);
[gitRepo writeObject:contents withType:[object type] withSize:[contents length]]; [gitRepo writeObject:contents withType:[object type] withSize:[contents length]];
//[object release];
} else { } else {
// TODO : OBJECT ISN'T HERE YET, SAVE THIS DELTA FOR LATER // // TODO : OBJECT ISN'T HERE YET, SAVE THIS DELTA FOR LATER //
/* /*
Expand Down Expand Up @@ -510,10 +517,13 @@ - (NSData *) patchDelta:(NSData *)deltaData withObject:(ObjGitObject *)gitObject
[destination appendBytes:[buffer bytes] length:cp_size]; [destination appendBytes:[buffer bytes] length:cp_size];
//NSLog(@"dest: %@", destination); //NSLog(@"dest: %@", destination);
} else if(c[0] != 0) { } else if(c[0] != 0) {
if(c[0] > destSize)
break;
//NSLog(@"thingy: %d, %d", position, c[0]); //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]]; [destination appendBytes:[buffer bytes] length:c[0]];
position += c[0]; position += c[0];
destSize -= c[0];
} else { } else {
NSLog(@"invalid delta data"); NSLog(@"invalid delta data");
} }
Expand Down
2 changes: 1 addition & 1 deletion ObjGitTree.h
Expand Up @@ -11,7 +11,7 @@
ObjGitObject *gitObject; ObjGitObject *gitObject;
} }


@property(assign, readwrite) NSArray *treeEntries; @property(copy, readwrite) NSArray *treeEntries;
@property(assign, readwrite) ObjGitObject *gitObject; @property(assign, readwrite) ObjGitObject *gitObject;


- (id) initFromGitObject:(ObjGitObject *)object; - (id) initFromGitObject:(ObjGitObject *)object;
Expand Down
8 changes: 3 additions & 5 deletions ObjGitTree.m
Expand Up @@ -13,10 +13,8 @@ @implementation ObjGitTree
@synthesize gitObject; @synthesize gitObject;


- (id) initFromGitObject:(ObjGitObject *)object { - (id) initFromGitObject:(ObjGitObject *)object {
NSLog(@"Tree init1");
self = [super init]; self = [super init];
NSLog(@"Tree init"); self.gitObject = object;
gitObject = object;
[self parseContent]; [self parseContent];
return self; return self;
} }
Expand All @@ -29,7 +27,7 @@ - (void) logObject
// 100644 testfile\0[20 char sha] // 100644 testfile\0[20 char sha]
- (void) parseContent - (void) parseContent
{ {
char *contents = [gitObject rawContents]; char *contents = [self.gitObject rawContents];


char mode[9]; char mode[9];
int modePtr = 0; int modePtr = 0;
Expand All @@ -46,7 +44,7 @@ - (void) parseContent
int i, j, state; int i, j, state;
state = 1; state = 1;


for(i = 0; i < [gitObject rawContentLen] - 1; i++) { for(i = 0; i < [self.gitObject rawContentLen] - 1; i++) {
if(contents[i] == 0) { if(contents[i] == 0) {
state = 1; state = 1;
for(j = 0; j < 20; j++) for(j = 0; j < 20; j++)
Expand Down

3 comments on commit 679496b

@chapados
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

@schacon
Copy link
Owner Author

@schacon schacon commented on 679496b Dec 9, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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…

@geoffgarside
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.