5 // Created by Pieter de Bie on 12-09-08.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
9 #import "PBGitRevSpecifier.h"
12 @implementation PBGitRevSpecifier
14 @synthesize parameters, description;
16 - (id) initWithParameters:(NSArray*) params
23 - (id) initWithRef: (PBGitRef*) ref
25 parameters = [NSArray arrayWithObject: ref.ref];
26 description = ref.shortName;
30 - (id) initWithCoder:(NSCoder *)coder
32 parameters = [coder decodeObjectForKey:@"Parameters"];
33 description = [coder decodeObjectForKey:@"Description"];
37 + (PBGitRevSpecifier *)allBranchesRevSpec
39 id revspec = [[PBGitRevSpecifier alloc] initWithParameters:[NSArray arrayWithObject:@"--all"]];
40 [revspec setDescription:@"All branches"];
44 + (PBGitRevSpecifier *)localBranchesRevSpec
46 id revspec = [[PBGitRevSpecifier alloc] initWithParameters:[NSArray arrayWithObject:@"--branches"]];
47 [revspec setDescription:@"Local branches"];
52 return ([parameters count] == 1 && ![[parameters objectAtIndex:0] hasPrefix:@"-"]);
55 - (NSString*) simpleRef
57 if (![self isSimpleRef])
59 return [parameters objectAtIndex:0];
62 - (NSString*) description
67 return [parameters componentsJoinedByString:@" "];
70 - (BOOL) hasPathLimiter;
72 for (NSString* param in parameters)
73 if ([param isEqualToString:@"--"])
80 for (NSString* param in parameters)
81 if ([param isEqualToString:@"--left-right"])
86 - (BOOL) isEqualTo: (PBGitRevSpecifier*) other
88 if ([self isSimpleRef] ^ [other isSimpleRef])
91 if ([self isSimpleRef])
92 return [[[self parameters] objectAtIndex: 0] isEqualToString: [other.parameters objectAtIndex: 0]];
94 return ([[parameters componentsJoinedByString:@" "] isEqualToString: [other.parameters componentsJoinedByString:@" "]] &&
95 (!description || [description isEqualToString:other.description]));
98 - (void) encodeWithCoder:(NSCoder *)coder
100 [coder encodeObject:description forKey:@"Description"];
101 [coder encodeObject:parameters forKey:@"Parameters"];