From: Nathan Kinsinger <[email protected]>
These add functionality and improve readability.
---
PBGitRef.h | 19 ++++++++++++-
PBGitRef.m | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 103 insertions(+), 5 deletions(-)
diff --git a/PBGitRef.h b/PBGitRef.h
index 578b56e..5a8662a 100644
--- a/PBGitRef.h
+++ b/PBGitRef.h
@@ -9,12 +9,29 @@
#import <Cocoa/Cocoa.h>
+extern NSString * const kGitXTagRefPrefix;
+extern NSString * const kGitXBranchRefPrefix;
+extern NSString * const kGitXRemoteRefPrefix;
+
+
@interface PBGitRef : NSObject {
NSString* ref;
}
- (NSString*) shortName;
-- (NSString*) type;
+- (NSString *)tagName;
+- (NSString *)branchName;
+- (NSString *)remoteName;
+- (NSString *)remoteBranchName;
+
+- (NSString *)type;
+- (BOOL)isBranch;
+- (BOOL)isTag;
+- (BOOL)isRemote;
+- (BOOL)isRemoteBranch;
+
+- (PBGitRef *)remoteRef;
+
+ (PBGitRef*) refFromString: (NSString*) s;
- (PBGitRef*) initWithString: (NSString*) s;
@property(readonly) NSString* ref;
diff --git a/PBGitRef.m b/PBGitRef.m
index f345a0a..2291c02 100644
--- a/PBGitRef.m
+++ b/PBGitRef.m
@@ -9,6 +9,11 @@
#import "PBGitRef.h"
+NSString * const kGitXTagRefPrefix = @"refs/tags/";
+NSString * const kGitXBranchRefPrefix = @"refs/heads/";
+NSString * const kGitXRemoteRefPrefix = @"refs/remotes/";
+
+
@implementation PBGitRef
@synthesize ref;
@@ -19,17 +24,93 @@ - (NSString*) shortName
return ref;
}
-- (NSString*) type
+- (NSString *)tagName
+{
+ if (![self isTag])
+ return nil;
+
+ return [self shortName];
+}
+
+- (NSString *)branchName
{
- if ([ref hasPrefix:@"refs/heads"])
+ if (![self isBranch])
+ return nil;
+
+ return [self shortName];
+}
+
+- (NSString *)remoteName
+{
+ if (![self isRemote])
+ return nil;
+
+ return (NSString *)[[ref componentsSeparatedByString:@"/"]
objectAtIndex:2];
+}
+
+- (NSString *)remoteBranchName
+{
+ if (![self isRemoteBranch])
+ return nil;
+
+ return [[self shortName] substringFromIndex:[[self remoteName] length]
+ 1];
+}
+
+- (NSString *)type
+{
+ if ([self isBranch])
return @"head";
- if ([ref hasPrefix:@"refs/tags"])
+ if ([self isTag])
return @"tag";
- if ([ref hasPrefix:@"refs/remotes"])
+ if ([self isRemote])
return @"remote";
return nil;
}
+- (BOOL)isBranch
+{
+ return [ref hasPrefix:kGitXBranchRefPrefix];
+}
+
+- (BOOL)isTag
+{
+ return [ref hasPrefix:kGitXTagRefPrefix];
+}
+
+- (BOOL)isRemote
+{
+ return [ref hasPrefix:kGitXRemoteRefPrefix];
+}
+
+- (BOOL)isRemoteBranch
+{
+ if (![self isRemote])
+ return NO;
+
+ return ([[ref componentsSeparatedByString:@"/"] count] > 3);
+}
+
+- (BOOL)isEqual:(id)otherRef
+{
+ if (![otherRef isMemberOfClass:[PBGitRef class]])
+ return NO;
+
+ return [ref isEqualToString:[otherRef ref]];
+}
+
+- (NSUInteger)hash
+{
+ return [ref hash];
+}
+
+- (PBGitRef *)remoteRef
+{
+ if (![self isRemote])
+ return nil;
+
+ return [PBGitRef refFromString:[kGitXRemoteRefPrefix
stringByAppendingString:[self remoteName]]];
+}
+
+ (PBGitRef*) refFromString: (NSString*) s
{
return [[PBGitRef alloc] initWithString:s];
--
1.7.0.3
To unsubscribe from this group, send email to gitx+unsubscribegooglegroups.com
or reply to this email with the words "REMOVE ME" as the subject.