Permalink
Browse files

properly writing the refs to file after a push

  • Loading branch information...
1 parent 1ed1fca commit 6f2c0edcefeef085fce5d1fb965a776d0dc6890e @schacon committed Sep 23, 2008
Showing with 32 additions and 5 deletions.
  1. +1 −1 .gitignore
  2. +1 −0 Git/Git.h
  3. +15 −1 Git/Git.m
  4. +15 −3 Git/GitServerHandler.m
View
@@ -1,3 +1,3 @@
build/*
-iGitHub.xcodeproj/schacon*
+iGitHub.xcodeproj/schacon.*
View
@@ -21,6 +21,7 @@
- (void) initGitRepo;
- (NSString *) writeObject:(NSData *)objectData withType:(NSString *)type withSize:(int)size;
+- (void) updateRef:(NSString *)refName toSha:(NSString *)toSha;
- (NSMutableArray *) getCommitsFromSha:(NSString *)shaValue withLimit:(int)commitSize;
- (NSString *) getLooseObjectPathBySha:(NSString *)shaValue;
View
@@ -36,12 +36,26 @@ - (BOOL) ensureGitPath {
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 {
NSFileManager *fm = [NSFileManager defaultManager];
[fm createDirectoryAtPath:gitDirectory attributes:nil];
//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/heads"] attributes:nil];
[fm createDirectoryAtPath:[gitDirectory stringByAppendingPathComponent:@"refs/tags"] attributes:nil];
View
@@ -94,8 +94,8 @@ - (void) receivePack:(NSString *)repositoryName {
- (void) sendRefs {
NSLog(@"send refs");
- // get refs from gitRepo //
- // foreach ref, send to client //
+ // TODO : get refs from gitRepo //
+ // foreach ref, send to client //
/*
refs.each do |ref|
send_ref(ref[1], ref[0])
@@ -122,16 +122,18 @@ - (void) readRefs {
NSString *data;
NSLog(@"read refs");
data = [self packetReadLine];
+ NSMutableArray *refs = [[NSMutableArray alloc] init];
while([data length] > 0) {
NSArray *values = [data componentsSeparatedByString:@" "];
- [refsRead addObject: values]; // save the refs for writing later
+ [refs addObject: values]; // save the refs for writing later
/* DEBUGGING */
NSLog(@"ref: [%@ : %@ : %@]", [values objectAtIndex: 0], \
[values objectAtIndex: 1], [values objectAtIndex: 2]);
data = [self packetReadLine];
}
+ refsRead = [NSArray arrayWithArray:refs];
}
/*
@@ -398,6 +400,16 @@ - (int) readPackHeader {
*/
- (void) writeRefs {
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];
+ }
}

0 comments on commit 6f2c0ed

Please sign in to comment.