mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Add/modify convenience methods in PBRevSpecifier
- NSCopying
- change isEqualTo: to isEqual: so that it works well with NSArray's (containsObject: and removeObject: will use isEqual: instead of pointer equality)
- add hash to go with isEqual:
- pre-calculate the isSimpleRef value. The rangeOf... methods are very slow and have a major effect on the tight loop in reloadRefs.
This commit is contained in:
+2
-2
@@ -397,7 +397,7 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
|
||||
|
||||
// First check if the branch doesn't exist already
|
||||
for (PBGitRevSpecifier *rev in branches)
|
||||
if ([branch isEqualTo: rev])
|
||||
if ([branch isEqual: rev])
|
||||
return rev;
|
||||
|
||||
NSIndexSet *newIndex = [NSIndexSet indexSetWithIndex:[branches count]];
|
||||
@@ -412,7 +412,7 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
|
||||
- (BOOL) removeBranch:(PBGitRevSpecifier *)branch
|
||||
{
|
||||
for (PBGitRevSpecifier *rev in branches) {
|
||||
if ([branch isEqualTo:rev]) {
|
||||
if ([branch isEqual:rev]) {
|
||||
NSIndexSet *oldIndex = [NSIndexSet indexSetWithIndex:[branches indexOfObject:rev]];
|
||||
[self willChange:NSKeyValueChangeRemoval valuesAtIndexes:oldIndex forKey:@"branches"];
|
||||
|
||||
|
||||
+4
-3
@@ -9,23 +9,23 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <PBGitRef.h>
|
||||
|
||||
@interface PBGitRevSpecifier : NSObject {
|
||||
@interface PBGitRevSpecifier : NSObject <NSCopying> {
|
||||
NSString *description;
|
||||
NSArray *parameters;
|
||||
NSURL *workingDirectory;
|
||||
BOOL isSimpleRef;
|
||||
}
|
||||
|
||||
- (id) initWithParameters:(NSArray*) params;
|
||||
- (id) initWithRef: (PBGitRef*) ref;
|
||||
|
||||
- (BOOL) isSimpleRef;
|
||||
- (NSString*) simpleRef;
|
||||
- (PBGitRef *) ref;
|
||||
- (BOOL) hasPathLimiter;
|
||||
- (BOOL) hasLeftRight;
|
||||
- (NSString *) title;
|
||||
|
||||
- (BOOL) isEqualTo: (PBGitRevSpecifier*) other;
|
||||
- (BOOL) isEqual: (PBGitRevSpecifier*) other;
|
||||
- (BOOL) isAllBranchesRev;
|
||||
- (BOOL) isLocalBranchesRev;
|
||||
|
||||
@@ -35,5 +35,6 @@
|
||||
@property(retain) NSString *description;
|
||||
@property(readonly) NSArray *parameters;
|
||||
@property(retain) NSURL *workingDirectory;
|
||||
@property(readonly) BOOL isSimpleRef;
|
||||
|
||||
@end
|
||||
|
||||
+58
-39
@@ -12,54 +12,56 @@
|
||||
@implementation PBGitRevSpecifier
|
||||
|
||||
@synthesize parameters, description, workingDirectory;
|
||||
@synthesize isSimpleRef;
|
||||
|
||||
- (id) initWithParameters:(NSArray*) params
|
||||
|
||||
// internal designated init
|
||||
- (id) initWithParameters:(NSArray *)params description:(NSString *)descrip
|
||||
{
|
||||
parameters = params;
|
||||
description = nil;
|
||||
description = descrip;
|
||||
|
||||
if (([parameters count] > 1) || ([parameters count] == 0))
|
||||
isSimpleRef = NO;
|
||||
else {
|
||||
NSString *param = [parameters objectAtIndex:0];
|
||||
if ([param hasPrefix:@"-"] ||
|
||||
[param rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"^@{}~:"]].location != NSNotFound ||
|
||||
[param rangeOfString:@".."].location != NSNotFound)
|
||||
isSimpleRef = NO;
|
||||
else
|
||||
isSimpleRef = YES;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithRef: (PBGitRef*) ref
|
||||
- (id) initWithParameters:(NSArray *)params
|
||||
{
|
||||
parameters = [NSArray arrayWithObject: ref.ref];
|
||||
description = ref.shortName;
|
||||
[self initWithParameters:params description:nil];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithRef:(PBGitRef *)ref
|
||||
{
|
||||
[self initWithParameters:[NSArray arrayWithObject:ref.ref] description:ref.shortName];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithCoder:(NSCoder *)coder
|
||||
{
|
||||
parameters = [coder decodeObjectForKey:@"Parameters"];
|
||||
description = [coder decodeObjectForKey:@"Description"];
|
||||
[self initWithParameters:[coder decodeObjectForKey:@"Parameters"] description:[coder decodeObjectForKey:@"Description"]];
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (PBGitRevSpecifier *)allBranchesRevSpec
|
||||
{
|
||||
id revspec = [[PBGitRevSpecifier alloc] initWithParameters:[NSArray arrayWithObject:@"--all"]];
|
||||
[revspec setDescription:@"All branches"];
|
||||
return revspec;
|
||||
return [[PBGitRevSpecifier alloc] initWithParameters:[NSArray arrayWithObject:@"--all"] description:@"All branches"];
|
||||
}
|
||||
|
||||
+ (PBGitRevSpecifier *)localBranchesRevSpec
|
||||
{
|
||||
id revspec = [[PBGitRevSpecifier alloc] initWithParameters:[NSArray arrayWithObject:@"--branches"]];
|
||||
[revspec setDescription:@"Local branches"];
|
||||
return revspec;
|
||||
}
|
||||
|
||||
- (BOOL) isSimpleRef
|
||||
{
|
||||
if ([parameters count] > 1)
|
||||
return NO;
|
||||
|
||||
NSString *param = [parameters objectAtIndex:0];
|
||||
if ([param hasPrefix:@"-"] ||
|
||||
[param rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"^@{}~:"]].location != NSNotFound ||
|
||||
[param rangeOfString:@".."].location != NSNotFound)
|
||||
return NO;
|
||||
|
||||
return YES;
|
||||
return [[PBGitRevSpecifier alloc] initWithParameters:[NSArray arrayWithObject:@"--branches"] description:@"Local branches"];
|
||||
}
|
||||
|
||||
- (NSString*) simpleRef
|
||||
@@ -77,12 +79,12 @@
|
||||
return [PBGitRef refFromString:[self simpleRef]];
|
||||
}
|
||||
|
||||
- (NSString*) description
|
||||
- (NSString *) description
|
||||
{
|
||||
if (description)
|
||||
return description;
|
||||
|
||||
return [parameters componentsJoinedByString:@" "];
|
||||
if (!description)
|
||||
description = [parameters componentsJoinedByString:@" "];
|
||||
|
||||
return description;
|
||||
}
|
||||
|
||||
- (NSString *) title
|
||||
@@ -122,27 +124,34 @@
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) isEqualTo: (PBGitRevSpecifier*) other
|
||||
|
||||
- (BOOL) isEqual:(PBGitRevSpecifier *)other
|
||||
{
|
||||
if ([self isSimpleRef] ^ [other isSimpleRef])
|
||||
return NO;
|
||||
|
||||
if ([self isSimpleRef])
|
||||
return [[[self parameters] objectAtIndex: 0] isEqualToString: [other.parameters objectAtIndex: 0]];
|
||||
return [[[self parameters] objectAtIndex:0] isEqualToString:[other.parameters objectAtIndex:0]];
|
||||
|
||||
return ([[parameters componentsJoinedByString:@" "] isEqualToString: [other.parameters componentsJoinedByString:@" "]] &&
|
||||
(!description || [description isEqualToString:other.description]));
|
||||
return [self.description isEqualToString:other.description];
|
||||
}
|
||||
|
||||
- (NSUInteger) hash
|
||||
{
|
||||
if ([self isSimpleRef])
|
||||
return [[[self parameters] objectAtIndex:0] hash];
|
||||
|
||||
return [self.description hash];
|
||||
}
|
||||
|
||||
- (BOOL) isAllBranchesRev
|
||||
{
|
||||
return [self isEqualTo:[PBGitRevSpecifier allBranchesRevSpec]];
|
||||
return [self isEqual:[PBGitRevSpecifier allBranchesRevSpec]];
|
||||
}
|
||||
|
||||
- (BOOL) isLocalBranchesRev
|
||||
{
|
||||
return [self isEqualTo:[PBGitRevSpecifier localBranchesRevSpec]];
|
||||
return [self isEqual:[PBGitRevSpecifier localBranchesRevSpec]];
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder:(NSCoder *)coder
|
||||
@@ -150,4 +159,14 @@
|
||||
[coder encodeObject:description forKey:@"Description"];
|
||||
[coder encodeObject:parameters forKey:@"Parameters"];
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(NSZone *)zone
|
||||
{
|
||||
PBGitRevSpecifier *copy = [[[self class] allocWithZone:zone] initWithParameters:[self.parameters copy]];
|
||||
copy.description = [self.description copy];
|
||||
copy.workingDirectory = [self.workingDirectory copy];
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -200,7 +200,7 @@
|
||||
|
||||
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(PBSourceViewCell *)cell forTableColumn:(NSTableColumn *)tableColumn item:(PBSourceViewItem *)item
|
||||
{
|
||||
cell.isCheckedOut = [item.revSpecifier isEqualTo:[repository headRef]];
|
||||
cell.isCheckedOut = [item.revSpecifier isEqual:[repository headRef]];
|
||||
|
||||
[cell setImage:[item icon]];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user