forked from pieter/gitx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PBGitRevSpecifier.m
103 lines (85 loc) · 2.25 KB
/
PBGitRevSpecifier.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// PBGitRevSpecifier.m
// GitX
//
// Created by Pieter de Bie on 12-09-08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "PBGitRevSpecifier.h"
@implementation PBGitRevSpecifier
@synthesize parameters, description, workingDirectory;
- (id) initWithParameters:(NSArray*) params
{
parameters = params;
description = nil;
return self;
}
- (id) initWithRef: (PBGitRef*) ref
{
parameters = [NSArray arrayWithObject: ref.ref];
description = ref.shortName;
return self;
}
- (id) initWithCoder:(NSCoder *)coder
{
parameters = [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;
}
+ (PBGitRevSpecifier *)localBranchesRevSpec
{
id revspec = [[PBGitRevSpecifier alloc] initWithParameters:[NSArray arrayWithObject:@"--branches"]];
[revspec setDescription:@"Local branches"];
return revspec;
}
- (BOOL) isSimpleRef
{
return ([parameters count] == 1 && ![[parameters objectAtIndex:0] hasPrefix:@"-"]);
}
- (NSString*) simpleRef
{
if (![self isSimpleRef])
return nil;
return [parameters objectAtIndex:0];
}
- (NSString*) description
{
if (description)
return description;
return [parameters componentsJoinedByString:@" "];
}
- (BOOL) hasPathLimiter;
{
for (NSString* param in parameters)
if ([param isEqualToString:@"--"])
return YES;
return NO;
}
- (BOOL) hasLeftRight
{
for (NSString* param in parameters)
if ([param isEqualToString:@"--left-right"])
return YES;
return NO;
}
- (BOOL) isEqualTo: (PBGitRevSpecifier*) other
{
if ([self isSimpleRef] ^ [other isSimpleRef])
return NO;
if ([self isSimpleRef])
return [[[self parameters] objectAtIndex: 0] isEqualToString: [other.parameters objectAtIndex: 0]];
return ([[parameters componentsJoinedByString:@" "] isEqualToString: [other.parameters componentsJoinedByString:@" "]] &&
(!description || [description isEqualToString:other.description]));
}
- (void) encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject:description forKey:@"Description"];
[coder encodeObject:parameters forKey:@"Parameters"];
}
@end