Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 173 lines (138 sloc) 4.089 kb
e3af731 @pieter Use a PBGitRevSpecifier to specify possible branches
pieter authored
1 //
2 // PBGitRevSpecifier.m
3 // GitX
4 //
5 // Created by Pieter de Bie on 12-09-08.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "PBGitRevSpecifier.h"
10
11
12 @implementation PBGitRevSpecifier
13
95a9cc8 @pieter RevSpecifier: Add support for a working directory
pieter authored
14 @synthesize parameters, description, workingDirectory;
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
15 @synthesize isSimpleRef;
e3af731 @pieter Use a PBGitRevSpecifier to specify possible branches
pieter authored
16
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
17
18 // internal designated init
19 - (id) initWithParameters:(NSArray *)params description:(NSString *)descrip
e3af731 @pieter Use a PBGitRevSpecifier to specify possible branches
pieter authored
20 {
21 parameters = params;
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
22 description = descrip;
23
24 if (([parameters count] > 1) || ([parameters count] == 0))
25 isSimpleRef = NO;
26 else {
27 NSString *param = [parameters objectAtIndex:0];
28 if ([param hasPrefix:@"-"] ||
29 [param rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"^@{}~:"]].location != NSNotFound ||
30 [param rangeOfString:@".."].location != NSNotFound)
31 isSimpleRef = NO;
32 else
33 isSimpleRef = YES;
34 }
35
e3af731 @pieter Use a PBGitRevSpecifier to specify possible branches
pieter authored
36 return self;
37 }
38
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
39 - (id) initWithParameters:(NSArray *)params
e3af731 @pieter Use a PBGitRevSpecifier to specify possible branches
pieter authored
40 {
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
41 [self initWithParameters:params description:nil];
e3af731 @pieter Use a PBGitRevSpecifier to specify possible branches
pieter authored
42 return self;
43 }
44
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
45 - (id) initWithRef:(PBGitRef *)ref
afcd0b4 @pieter GitRevSpecifier: Add NSCoder protocol
pieter authored
46 {
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
47 [self initWithParameters:[NSArray arrayWithObject:ref.ref] description:ref.shortName];
afcd0b4 @pieter GitRevSpecifier: Add NSCoder protocol
pieter authored
48 return self;
49 }
50
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
51 - (id) initWithCoder:(NSCoder *)coder
ffae6a8 @pieter GitRepository: Add an "all branches" option in branches list
pieter authored
52 {
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
53 [self initWithParameters:[coder decodeObjectForKey:@"Parameters"] description:[coder decodeObjectForKey:@"Description"]];
54 return self;
ffae6a8 @pieter GitRepository: Add an "all branches" option in branches list
pieter authored
55 }
6038c20 @pieter HistoryView: Add a "Local Branches" option
pieter authored
56
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
57 + (PBGitRevSpecifier *)allBranchesRevSpec
6038c20 @pieter HistoryView: Add a "Local Branches" option
pieter authored
58 {
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
59 return [[PBGitRevSpecifier alloc] initWithParameters:[NSArray arrayWithObject:@"--all"] description:@"All branches"];
6038c20 @pieter HistoryView: Add a "Local Branches" option
pieter authored
60 }
d05deb9 @pieter PBGitRevSpecifier: tweak "isSimpleRef" a bit
pieter authored
61
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
62 + (PBGitRevSpecifier *)localBranchesRevSpec
e3af731 @pieter Use a PBGitRevSpecifier to specify possible branches
pieter authored
63 {
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
64 return [[PBGitRevSpecifier alloc] initWithParameters:[NSArray arrayWithObject:@"--branches"] description:@"Local branches"];
e3af731 @pieter Use a PBGitRevSpecifier to specify possible branches
pieter authored
65 }
66
67 - (NSString*) simpleRef
68 {
69 if (![self isSimpleRef])
70 return nil;
71 return [parameters objectAtIndex:0];
72 }
73
b61028a @brotherbard Add support methods needed for future commits.
authored
74 - (PBGitRef *) ref
75 {
76 if (![self isSimpleRef])
77 return nil;
78
79 return [PBGitRef refFromString:[self simpleRef]];
80 }
81
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
82 - (NSString *) description
fc88117 @pieter Extend PBGitRevSPecifier
pieter authored
83 {
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
84 if (!description)
85 description = [parameters componentsJoinedByString:@" "];
86
87 return description;
fc88117 @pieter Extend PBGitRevSPecifier
pieter authored
88 }
89
c36726b @brotherbard Update the GUI to be more iApp like
authored
90 - (NSString *) title
91 {
92 NSString *title = nil;
93
94 if ([self.description isEqualToString:@"HEAD"])
95 title = @"detached HEAD";
96 else if ([self isSimpleRef])
97 title = [[self ref] shortName];
98 else if ([self.description hasPrefix:@"-S"])
99 title = [self.description substringFromIndex:[@"-S" length]];
100 else if ([self.description hasPrefix:@"HEAD -- "])
101 title = [self.description substringFromIndex:[@"HEAD -- " length]];
102 else if ([self.description hasPrefix:@"-- "])
103 title = [self.description substringFromIndex:[@"-- " length]];
104 else if ([self.description hasPrefix:@"--left-right "])
105 title = [self.description substringFromIndex:[@"--left-right " length]];
106 else
107 title = self.description;
108
109 return [NSString stringWithFormat:@"\"%@\"", title];
110 }
111
fc88117 @pieter Extend PBGitRevSPecifier
pieter authored
112 - (BOOL) hasPathLimiter;
113 {
114 for (NSString* param in parameters)
115 if ([param isEqualToString:@"--"])
116 return YES;
117 return NO;
118 }
0617f11 @pieter Select existing ref if it exists
pieter authored
119
78e45bd @pieter Add support for --left-right
pieter authored
120 - (BOOL) hasLeftRight
121 {
122 for (NSString* param in parameters)
123 if ([param isEqualToString:@"--left-right"])
124 return YES;
125 return NO;
126 }
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
127
128 - (BOOL) isEqual:(PBGitRevSpecifier *)other
0617f11 @pieter Select existing ref if it exists
pieter authored
129 {
130 if ([self isSimpleRef] ^ [other isSimpleRef])
131 return NO;
132
133 if ([self isSimpleRef])
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
134 return [[[self parameters] objectAtIndex:0] isEqualToString:[other.parameters objectAtIndex:0]];
0617f11 @pieter Select existing ref if it exists
pieter authored
135
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
136 return [self.description isEqualToString:other.description];
137 }
138
139 - (NSUInteger) hash
140 {
141 if ([self isSimpleRef])
142 return [[[self parameters] objectAtIndex:0] hash];
143
144 return [self.description hash];
0617f11 @pieter Select existing ref if it exists
pieter authored
145 }
afcd0b4 @pieter GitRevSpecifier: Add NSCoder protocol
pieter authored
146
b61028a @brotherbard Add support methods needed for future commits.
authored
147 - (BOOL) isAllBranchesRev
148 {
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
149 return [self isEqual:[PBGitRevSpecifier allBranchesRevSpec]];
b61028a @brotherbard Add support methods needed for future commits.
authored
150 }
151
152 - (BOOL) isLocalBranchesRev
153 {
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
154 return [self isEqual:[PBGitRevSpecifier localBranchesRevSpec]];
b61028a @brotherbard Add support methods needed for future commits.
authored
155 }
156
afcd0b4 @pieter GitRevSpecifier: Add NSCoder protocol
pieter authored
157 - (void) encodeWithCoder:(NSCoder *)coder
158 {
159 [coder encodeObject:description forKey:@"Description"];
160 [coder encodeObject:parameters forKey:@"Parameters"];
161 }
1323638 @brotherbard Add/modify convenience methods in PBRevSpecifier
authored
162
163 - (id)copyWithZone:(NSZone *)zone
164 {
165 PBGitRevSpecifier *copy = [[[self class] allocWithZone:zone] initWithParameters:[self.parameters copy]];
166 copy.description = [self.description copy];
167 copy.workingDirectory = [self.workingDirectory copy];
168
169 return copy;
170 }
171
e3af731 @pieter Use a PBGitRevSpecifier to specify possible branches
pieter authored
172 @end
Something went wrong with that request. Please try again.