Permalink
Browse files

Delete branches when the refs are deleted

In reloadRefs:
    - check for any branches that are no longer in the repo and delete them
        - except the detached HEAD and the "other" revs
    - send KVO notice for the refs ivar changing
    - get rid of the BOOL return value as it's not being used
    - get rid of the outdated comments
    - clean things up a bit
  • Loading branch information...
1 parent 1b75af3 commit c83f77801ed93d770ef355c95ba32cabaa7d4581 @brotherbard brotherbard committed Mar 14, 2010
Showing with 18 additions and 21 deletions.
  1. +1 −1 PBGitRepository.h
  2. +17 −20 PBGitRepository.m
View
@@ -65,7 +65,7 @@ extern NSString* PBGitRepositoryErrorDomain;
- (NSString *)gitIgnoreFilename;
- (BOOL)isBareRepository;
-- (BOOL) reloadRefs;
+- (void) reloadRefs;
- (void) addRef:(PBGitRef *)ref fromParameters:(NSArray *)params;
- (void) lazyReload;
- (PBGitRevSpecifier*) headRef;
View
@@ -223,47 +223,44 @@ - (void) addRef: (PBGitRef *) ref fromParameters: (NSArray *) components
[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
+- (void) reloadRefs
{
_headRef = nil;
- BOOL ret = NO;
refs = [NSMutableDictionary dictionary];
+ NSMutableArray *oldBranches = [branches mutableCopy];
- NSString* output = [PBEasyPipe outputForCommand:[PBGitBinary path]
- withArgs:[NSArray arrayWithObjects:@"for-each-ref", @"--format=%(refname) %(objecttype) %(objectname)"
- " %(*objectname)", @"refs", nil]
- inDir: self.fileURL.path];
- NSArray* lines = [output componentsSeparatedByString:@"\n"];
+ NSArray *arguments = [NSArray arrayWithObjects:@"for-each-ref", @"--format=%(refname) %(objecttype) %(objectname) %(*objectname)", @"refs", nil];
+ NSString *output = [self outputForArguments:arguments];
+ NSArray *lines = [output componentsSeparatedByString:@"\n"];
- for (NSString* line in lines) {
+ for (NSString *line in lines) {
// If its an empty line, skip it (e.g. with empty repositories)
if ([line length] == 0)
continue;
- NSArray* components = [line componentsSeparatedByString:@" "];
+ NSArray *components = [line componentsSeparatedByString:@" "];
- // 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;
+ PBGitRevSpecifier *revSpec = [[PBGitRevSpecifier alloc] initWithRef:newRef];
- // Also add this ref to the refs list
+ [self addBranch:revSpec];
[self addRef:newRef fromParameters:components];
+ [oldBranches removeObject:revSpec];
}
+ for (PBGitRevSpecifier *branch in oldBranches)
+ if ([branch isSimpleRef] && ![branch isEqual:[self headRef]])
+ [self removeBranch:branch];
+
// Add an "All branches" option in the branches list
[self addBranch:[PBGitRevSpecifier allBranchesRevSpec]];
[self addBranch:[PBGitRevSpecifier localBranchesRevSpec]];
- [[[self windowController] window] setTitle:[self displayName]];
+ [self willChangeValueForKey:@"refs"];
+ [self didChangeValueForKey:@"refs"];
- return ret;
+ [[[self windowController] window] setTitle:[self displayName]];
}
- (void) lazyReload

0 comments on commit c83f778

Please sign in to comment.