Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reload refs on refresh

  • Loading branch information...
commit 1f783c91c40d7d457926189faa0c52fa4f958cdb 1 parent 86a34b6
@pieter authored
View
4 GitX.xcodeproj/project.pbxproj
@@ -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 */,
View
3  PBDetailController.m
@@ -149,7 +149,8 @@ - (void) updateQuicklookForce: (BOOL) force
- (IBAction) refresh: sender
{
- repository.currentBranch = repository.currentBranch;
+ [repository reloadRefs];
+ [repository.revisionList reload];
}
- (void) selectCommit: (NSString*) commit
View
8 PBGitRepository.h
@@ -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
View
72 PBGitRepository.m
@@ -121,8 +121,7 @@ - (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)type
}
if (success) {
- [self readRefs];
- revisionList = [[PBGitRevList alloc] initWithRepository:self];
+ [self setup];
[self readCurrentBranch];
}
}
@@ -130,15 +129,20 @@ - (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)type
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 @@ - (void)makeWindowControllers
[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]];
-
- NSMutableArray* curRefs;
- if (curRefs = [newRefs objectForKey:sha])
- [curRefs addObject:ref];
- else
- [newRefs setObject:[NSMutableArray arrayWithObject:ref] forKey:sha];
+
+ // 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];
+
}
- self.refs = newRefs;
- self.branches = newBranches;
+ self.refs = refs;
+ return ret;
}
- (PBGitRevSpecifier*) headRef
View
3  PBGitRevList.h
@@ -17,7 +17,8 @@
}
- initWithRepository:(id)repo;
-- (void) readCommits;
+- (void) readCommitsForce: (BOOL) force;
+- (void) reload;
@property(retain) NSArray* commits;
@property(retain) id grapher;
View
11 PBGitRevList.m
@@ -23,7 +23,12 @@ @implementation PBGitRevList
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 @@ - (void) readCommits
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 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context
{
if (object == repository)
- [self readCommits];
+ [self readCommitsForce: NO];
}
- (void) walkRevisionListWithSpecifier: (PBGitRevSpecifier*) rev
View
2  PBGitRevSpecifier.m
@@ -69,7 +69,7 @@ - (BOOL) isEqualTo: (PBGitRevSpecifier*) other
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]));
Please sign in to comment.
Something went wrong with that request. Please try again.