Skip to content

Commit

Permalink
properly writing the refs to file after a push
Browse files Browse the repository at this point in the history
  • Loading branch information
schacon committed Sep 23, 2008
1 parent 1ed1fca commit 6f2c0ed
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,3 @@
build/* build/*
iGitHub.xcodeproj/schacon* iGitHub.xcodeproj/schacon.*


1 change: 1 addition & 0 deletions Git/Git.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- (void) initGitRepo; - (void) initGitRepo;


- (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;


- (NSMutableArray *) getCommitsFromSha:(NSString *)shaValue withLimit:(int)commitSize; - (NSMutableArray *) getCommitsFromSha:(NSString *)shaValue withLimit:(int)commitSize;
- (NSString *) getLooseObjectPathBySha:(NSString *)shaValue; - (NSString *) getLooseObjectPathBySha:(NSString *)shaValue;
Expand Down
16 changes: 15 additions & 1 deletion Git/Git.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,12 +36,26 @@ - (BOOL) ensureGitPath {
return YES; return YES;
} }


- (void) updateRef:(NSString *)refName toSha:(NSString *)toSha
{
NSFileManager *fm = [NSFileManager defaultManager];
NSString *refPath = [gitDirectory stringByAppendingPathComponent:refName];
[fm createFileAtPath:refPath contents:[NSData dataWithBytes:[toSha UTF8String] length:[toSha length]] attributes:nil];
}

- (void) initGitRepo { - (void) initGitRepo {
NSFileManager *fm = [NSFileManager defaultManager]; NSFileManager *fm = [NSFileManager defaultManager];
[fm createDirectoryAtPath:gitDirectory attributes:nil]; [fm createDirectoryAtPath:gitDirectory attributes:nil];


//NSLog(@"Dir Created: %@ %d", gitDirectory, [gitDirectory length]); //NSLog(@"Dir Created: %@ %d", gitDirectory, [gitDirectory length]);

NSString *config = @"[core]\n\trepositoryformatversion = 0\n\tfilemode = true\n\tbare = true\n\tlogallrefupdates = true\n";
NSString *configFile = [gitDirectory stringByAppendingPathComponent:@"config"];
[fm createFileAtPath:configFile contents:[NSData dataWithBytes:[config UTF8String] length:[config length]] attributes:nil];

NSString *head = @"ref: refs/heads/master\n";
NSString *headFile = [gitDirectory stringByAppendingPathComponent:@"HEAD"];
[fm createFileAtPath:headFile contents:[NSData dataWithBytes:[head UTF8String] length:[head length]] attributes:nil];

[fm createDirectoryAtPath:[gitDirectory stringByAppendingPathComponent:@"refs"] attributes:nil]; [fm createDirectoryAtPath:[gitDirectory stringByAppendingPathComponent:@"refs"] attributes:nil];
[fm createDirectoryAtPath:[gitDirectory stringByAppendingPathComponent:@"refs/heads"] attributes:nil]; [fm createDirectoryAtPath:[gitDirectory stringByAppendingPathComponent:@"refs/heads"] attributes:nil];
[fm createDirectoryAtPath:[gitDirectory stringByAppendingPathComponent:@"refs/tags"] attributes:nil]; [fm createDirectoryAtPath:[gitDirectory stringByAppendingPathComponent:@"refs/tags"] attributes:nil];
Expand Down
18 changes: 15 additions & 3 deletions Git/GitServerHandler.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ - (void) receivePack:(NSString *)repositoryName {
- (void) sendRefs { - (void) sendRefs {
NSLog(@"send refs"); NSLog(@"send refs");


// get refs from gitRepo // // TODO : get refs from gitRepo //
// foreach ref, send to client // // foreach ref, send to client //
/* /*
refs.each do |ref| refs.each do |ref|
send_ref(ref[1], ref[0]) send_ref(ref[1], ref[0])
Expand All @@ -122,16 +122,18 @@ - (void) readRefs {
NSString *data; NSString *data;
NSLog(@"read refs"); NSLog(@"read refs");
data = [self packetReadLine]; data = [self packetReadLine];
NSMutableArray *refs = [[NSMutableArray alloc] init];
while([data length] > 0) { while([data length] > 0) {
NSArray *values = [data componentsSeparatedByString:@" "]; NSArray *values = [data componentsSeparatedByString:@" "];
[refsRead addObject: values]; // save the refs for writing later [refs addObject: values]; // save the refs for writing later


/* DEBUGGING */ /* DEBUGGING */
NSLog(@"ref: [%@ : %@ : %@]", [values objectAtIndex: 0], \ NSLog(@"ref: [%@ : %@ : %@]", [values objectAtIndex: 0], \
[values objectAtIndex: 1], [values objectAtIndex: 2]); [values objectAtIndex: 1], [values objectAtIndex: 2]);


data = [self packetReadLine]; data = [self packetReadLine];
} }
refsRead = [NSArray arrayWithArray:refs];
} }


/* /*
Expand Down Expand Up @@ -398,6 +400,16 @@ - (int) readPackHeader {
*/ */
- (void) writeRefs { - (void) writeRefs {
NSLog(@"write refs"); NSLog(@"write refs");
NSEnumerator *e = [refsRead objectEnumerator];
NSArray *thisRef;
NSString *toSha, *refName;

while ( (thisRef = [e nextObject]) ) {
NSLog(@"ref: %@", thisRef);
toSha = [thisRef objectAtIndex:1];
refName = [thisRef objectAtIndex:2];
[gitRepo updateRef:refName toSha:toSha];
}
} }




Expand Down

0 comments on commit 6f2c0ed

Please sign in to comment.