Reload refs on refresh

This commit is contained in:
Pieter de Bie
2008-09-19 19:17:07 +02:00
parent 86a34b64ae
commit 1f783c91c4
7 changed files with 64 additions and 35 deletions
+2 -2
View File
@@ -273,6 +273,8 @@
F56174540E05887E001DCD79 /* Git */ = {
isa = PBXGroup;
children = (
F5C007730E731B48007B84B2 /* PBGitRef.h */,
F5C007740E731B48007B84B2 /* PBGitRef.m */,
F5C6F6750E65FE2B00478D97 /* Graphing */,
F5FF4E780E082E440006317A /* PBGitGrapher.h */,
F5FF4E790E082E440006317A /* PBGitGrapher.m */,
@@ -342,8 +344,6 @@
F5C6F6750E65FE2B00478D97 /* Graphing */ = {
isa = PBXGroup;
children = (
F5C007730E731B48007B84B2 /* PBGitRef.h */,
F5C007740E731B48007B84B2 /* PBGitRef.m */,
F50FE0E10E07BE9600854FCD /* PBGitRevisionCell.h */,
F50FE0E20E07BE9600854FCD /* PBGitRevisionCell.m */,
F56CC7270E65E0AD004307B4 /* PBGitGraphLine.h */,
+2 -1
View File
@@ -149,7 +149,8 @@
- (IBAction) refresh: sender
{
repository.currentBranch = repository.currentBranch;
[repository reloadRefs];
[repository.revisionList reload];
}
- (void) selectCommit: (NSString*) commit
+5 -3
View File
@@ -16,7 +16,7 @@ extern NSString* PBGitRepositoryErrorDomain;
PBGitRevList* revisionList;
NSMutableArray* branches;
NSIndexSet* currentBranch;
NSDictionary* refs;
NSMutableDictionary* refs;
}
- (NSFileHandle*) handleForCommand:(NSString*) cmd;
@@ -24,7 +24,8 @@ extern NSString* PBGitRepositoryErrorDomain;
- (NSString*) outputForCommand:(NSString*) cmd;
- (NSString*) outputForArguments:(NSArray*) args;
- (void) readRefs;
- (BOOL) reloadRefs;
- (void) addRef:(PBGitRef *)ref fromParameters:(NSArray *)params;
- (void) readCurrentBranch;
- (PBGitRevSpecifier*) addBranch: (PBGitRevSpecifier*) rev;
- (void) selectBranch: (PBGitRevSpecifier*) rev;
@@ -36,9 +37,10 @@ extern NSString* PBGitRepositoryErrorDomain;
+ (NSURL*)baseDirForURL:(NSURL*)repositoryURL;
- (id) initWithURL: (NSURL*) path andRevSpecifier:(PBGitRevSpecifier*) rev;
- (void) setup;
@property (retain) PBGitRevList* revisionList;
@property (assign) NSMutableArray* branches;
@property (assign) NSIndexSet* currentBranch;
@property (assign) NSDictionary* refs;
@property (assign) NSMutableDictionary* refs;
@end
+44 -24
View File
@@ -121,8 +121,7 @@ static NSString* gitPath;
}
if (success) {
[self readRefs];
revisionList = [[PBGitRevList alloc] initWithRepository:self];
[self setup];
[self readCurrentBranch];
}
}
@@ -130,15 +129,20 @@ static NSString* gitPath;
return success;
}
- (void) setup
{
self.branches = [NSMutableArray array];
[self reloadRefs];
revisionList = [[PBGitRevList alloc] initWithRepository:self];
}
- (id) initWithURL: (NSURL*) path andRevSpecifier:(PBGitRevSpecifier*) rev
{
self = [self init];
NSURL* gitDirURL = [PBGitRepository gitDirForURL:path];
[self setFileURL: gitDirURL];
[self readRefs];
revisionList = [[PBGitRevList alloc] initWithRepository:self];
[self setup];
[self selectBranch: [self addBranch: rev]];
return self;
@@ -161,33 +165,49 @@ static NSString* gitPath;
[controller release];
}
- (void) readRefs
- (void) addRef: (PBGitRef *) ref fromParameters: (NSArray *) components
{
NSString* type = [components objectAtIndex:1];
NSString* sha;
if ([type isEqualToString:@"tag"] && [components count] == 4)
sha = [components objectAtIndex:3];
else
sha = [components objectAtIndex:2];
NSMutableArray* curRefs;
if (curRefs = [refs objectForKey:sha])
[curRefs addObject:ref];
else
[refs setObject:[NSMutableArray arrayWithObject:ref] forKey:sha];
}
// reloadRefs: reload all refs in the repository, like in readRefs
// To stay compatible, this does not remove a ref from the branches list
// even after it has been deleted.
// returns YES when a ref was changed
- (BOOL) reloadRefs
{
BOOL ret = NO;
NSString* output = [PBEasyPipe outputForCommand:gitPath withArgs:[NSArray arrayWithObjects:@"for-each-ref", @"--format=%(refname) %(objecttype) %(objectname) %(*objectname)", @"refs", nil] inDir: self.fileURL.path];
NSArray* lines = [output componentsSeparatedByString:@"\n"];
NSMutableDictionary* newRefs = [NSMutableDictionary dictionary];
NSMutableArray* newBranches = [NSMutableArray array];
refs = [NSMutableDictionary dictionary];
for (NSString* line in lines) {
NSArray* components = [line componentsSeparatedByString:@" "];
PBGitRef* ref = [PBGitRef refFromString:[components objectAtIndex:0]];
NSString* type = [components objectAtIndex:1];
NSString* sha;
if ([type isEqualToString:@"tag"] && [components count] == 4)
sha = [components objectAtIndex:3];
else
sha = [components objectAtIndex:2];
if ([[ref type] isEqualToString:@"head"] || [[ref type] isEqualToString:@"remote"])
[newBranches addObject: [[PBGitRevSpecifier alloc] initWithRef:ref]];
// First do the ref matching. If this ref is new, add it to our ref list
PBGitRef *newRef = [PBGitRef refFromString:[components objectAtIndex:0]];
PBGitRevSpecifier* revSpec = [[PBGitRevSpecifier alloc] initWithRef:newRef];
if ([self addBranch:revSpec] == revSpec)
ret = YES;
// Also add this ref to the branches list
[self addRef:newRef fromParameters:components];
NSMutableArray* curRefs;
if (curRefs = [newRefs objectForKey:sha])
[curRefs addObject:ref];
else
[newRefs setObject:[NSMutableArray arrayWithObject:ref] forKey:sha];
}
self.refs = newRefs;
self.branches = newBranches;
self.refs = refs;
return ret;
}
- (PBGitRevSpecifier*) headRef
+2 -1
View File
@@ -17,7 +17,8 @@
}
- initWithRepository:(id)repo;
- (void) readCommits;
- (void) readCommitsForce: (BOOL) force;
- (void) reload;
@property(retain) NSArray* commits;
@property(retain) id grapher;
+8 -3
View File
@@ -23,7 +23,12 @@
return self;
}
- (void) readCommits
- (void) reload
{
[self readCommitsForce: YES];
}
- (void) readCommitsForce: (BOOL) force
{
// We use refparse to get the commit sha that we will parse. That way,
// we can check if the current branch is the same as the previous one
@@ -42,7 +47,7 @@
PBGitRevSpecifier* newRev = [selectedBranches objectAtIndex:0];
NSString* newSha = nil;
if (newRev && [newRev isSimpleRef]) {
if (!force && newRev && [newRev isSimpleRef]) {
newSha = [repository parseReference:[newRev simpleRef]];
if ([newSha isEqualToString:lastSha])
return;
@@ -57,7 +62,7 @@
change:(NSDictionary *)change context:(void *)context
{
if (object == repository)
[self readCommits];
[self readCommitsForce: NO];
}
- (void) walkRevisionListWithSpecifier: (PBGitRevSpecifier*) rev
+1 -1
View File
@@ -69,7 +69,7 @@
return NO;
if ([self isSimpleRef])
return [[self description] isEqualToString: [other description]];
return [[[self parameters] objectAtIndex: 0] isEqualToString: [other.parameters objectAtIndex: 0]];
return ([[parameters componentsJoinedByString:@" "] isEqualToString: [other.parameters componentsJoinedByString:@" "]] &&
(!description || [description isEqualToString:other.description]));