Skip to content

Commit 9a796bb

Browse files
committed
Modernize PBGitRef
1 parent 41d72a9 commit 9a796bb

File tree

2 files changed

+49
-52
lines changed

2 files changed

+49
-52
lines changed

Classes/git/PBGitRef.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#import <Cocoa/Cocoa.h>
1010
#import "PBGitRefish.h"
1111

12+
NS_ASSUME_NONNULL_BEGIN
13+
1214
extern NSString * const kGitXTagType;
1315
extern NSString * const kGitXBranchType;
1416
extern NSString * const kGitXRemoteType;
@@ -20,33 +22,31 @@ extern NSString * const kGitXBranchRefPrefix;
2022
extern NSString * const kGitXRemoteRefPrefix;
2123
extern NSString * const kGitXStashRefPrefix;
2224

23-
2425
@interface PBGitRef : NSObject <PBGitRefish>
2526

26-
// <PBGitRefish>
27-
- (NSString *) refishName;
28-
- (NSString *) shortName;
29-
- (NSString *) refishType;
27+
+ (instancetype)refFromString:(NSString *)s;
28+
- (instancetype)initWithString:(NSString *)s;
3029

31-
- (NSString *) tagName;
32-
- (NSString *) branchName;
33-
- (NSString *) remoteName;
34-
- (NSString *) remoteBranchName;
3530

36-
- (NSString *) type;
37-
- (BOOL) isBranch;
38-
- (BOOL) isTag;
39-
- (BOOL) isRemote;
40-
- (BOOL) isRemoteBranch;
41-
- (BOOL) isStash;
31+
@property (nullable, readonly) NSString *tagName;
32+
@property (nullable, readonly) NSString *branchName;
33+
@property (nullable, readonly) NSString *remoteName;
34+
@property (nullable, readonly) NSString *remoteBranchName;
4235

43-
- (PBGitRef *) remoteRef;
36+
@property (nullable, readonly) NSString *type;
4437

45-
- (BOOL) isEqualToRef:(PBGitRef *)otherRef;
38+
@property (readonly, getter=isBranch) BOOL branch;
39+
@property (readonly, getter=isTag) BOOL tag;
40+
@property (readonly, getter=isRemote) BOOL remote;
41+
@property (readonly, getter=isRemoteBranch) BOOL remoteBranch;
42+
@property (readonly, getter=isStash) BOOL stash;
4643

47-
+ (PBGitRef*) refFromString: (NSString*) s;
48-
- (PBGitRef*) initWithString: (NSString*) s;
44+
- (nullable PBGitRef *)remoteRef;
4945

50-
@property(nonatomic, strong, readonly) NSString* ref;
46+
- (BOOL)isEqualToRef:(PBGitRef *)otherRef;
47+
48+
@property(nonatomic, strong, readonly) NSString *ref;
5149

5250
@end
51+
52+
NS_ASSUME_NONNULL_END

Classes/git/PBGitRef.m

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,29 @@
2222

2323
@interface PBGitRef ()
2424

25-
@property(nonatomic, strong) NSString* ref;
25+
@property (nonatomic, strong) NSString *ref;
2626

2727
@end
2828

2929
@implementation PBGitRef
3030

31-
@synthesize ref;
31+
+ (instancetype)refFromString:(NSString *)s
32+
{
33+
return [[PBGitRef alloc] initWithString:s];
34+
}
35+
36+
- (instancetype)initWithString:(NSString *)s
37+
{
38+
self = [super init];
39+
if (!self) return nil;
40+
41+
_ref = s;
42+
return self;
43+
}
44+
45+
- (NSString *)debugDescription {
46+
return [NSString stringWithFormat:@"<%@: %p ref: %@", NSStringFromClass([self class]), self, self.ref];
47+
}
3248

3349
- (NSString *) tagName
3450
{
@@ -51,7 +67,7 @@ - (NSString *) remoteName
5167
if (![self isRemote])
5268
return nil;
5369

54-
return (NSString *)[[ref componentsSeparatedByString:@"/"] objectAtIndex:2];
70+
return (NSString *)[[self.ref componentsSeparatedByString:@"/"] objectAtIndex:2];
5571
}
5672

5773
- (NSString *) remoteBranchName
@@ -77,35 +93,35 @@ - (NSString *) type
7793

7894
- (BOOL) isBranch
7995
{
80-
return [ref hasPrefix:kGitXBranchRefPrefix];
96+
return [self.ref hasPrefix:kGitXBranchRefPrefix];
8197
}
8298

8399
- (BOOL) isTag
84100
{
85-
return [ref hasPrefix:kGitXTagRefPrefix];
101+
return [self.ref hasPrefix:kGitXTagRefPrefix];
86102
}
87103

88104
- (BOOL) isRemote
89105
{
90-
return [ref hasPrefix:kGitXRemoteRefPrefix];
106+
return [self.ref hasPrefix:kGitXRemoteRefPrefix];
91107
}
92108

93109
- (BOOL) isRemoteBranch
94110
{
95111
if (![self isRemote])
96112
return NO;
97113

98-
return ([[ref componentsSeparatedByString:@"/"] count] > 3);
114+
return ([[self.ref componentsSeparatedByString:@"/"] count] > 3);
99115
}
100116

101117
- (BOOL) isStash
102118
{
103-
return [ref hasPrefix:kGitXStashRefPrefix];
119+
return [self.ref hasPrefix:kGitXStashRefPrefix];
104120
}
105121

106122
- (BOOL) isEqualToRef:(PBGitRef *)otherRef
107123
{
108-
return [ref isEqualToString:[otherRef ref]];
124+
return [self.ref isEqualToString:[otherRef ref]];
109125
}
110126

111127
- (PBGitRef *) remoteRef
@@ -116,25 +132,6 @@ - (PBGitRef *) remoteRef
116132
return [PBGitRef refFromString:[kGitXRemoteRefPrefix stringByAppendingString:[self remoteName]]];
117133
}
118134

119-
+ (PBGitRef*) refFromString: (NSString*) s
120-
{
121-
return [[PBGitRef alloc] initWithString:s];
122-
}
123-
124-
- (PBGitRef*) initWithString: (NSString*) s
125-
{
126-
self = [super init];
127-
if (!self) {
128-
return nil;
129-
}
130-
ref = s;
131-
return self;
132-
}
133-
134-
- (NSString *)debugDescription {
135-
return [NSString stringWithFormat:@"<%@: %p ref: %@", NSStringFromClass([self class]), self, ref];
136-
}
137-
138135
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
139136
{
140137
return NO;
@@ -149,16 +146,16 @@ + (BOOL)isKeyExcludedFromWebScript:(const char *)name {
149146

150147
- (NSString *) refishName
151148
{
152-
return ref;
149+
return self.ref;
153150
}
154151

155152
- (NSString *) shortName
156153
{
157154
if ([self isStash])
158-
return [ref substringFromIndex:5];
155+
return [self.ref substringFromIndex:5];
159156
if ([self type])
160-
return [ref substringFromIndex:[[self type] length] + 7];
161-
return ref;
157+
return [self.ref substringFromIndex:[[self type] length] + 7];
158+
return self.ref;
162159
}
163160

164161
- (NSString *) refishType

0 commit comments

Comments
 (0)