forked from pieter/gitx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPBGitSHA.m
139 lines (93 loc) · 1.83 KB
/
PBGitSHA.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
// PBGitSHA.m
// GitX
//
// Created by BrotherBard on 3/28/10.
// Copyright 2010 BrotherBard. All rights reserved.
//
#import "PBGitSHA.h"
@interface PBGitSHA ()
- (id)initWithOID:(git_oid)g_oid;
@end
@implementation PBGitSHA
@synthesize oid;
@synthesize string;
+ (PBGitSHA *)shaWithOID:(git_oid)oid
{
return [[PBGitSHA alloc] initWithOID:oid];
}
+ (PBGitSHA *)shaWithString:(NSString *)shaString
{
git_oid oid;
int err = git_oid_mkstr(&oid, [shaString UTF8String]);
if (err == GIT_ENOTOID)
return nil;
return [self shaWithOID:oid];
}
+ (PBGitSHA *)shaWithCString:(const char *)shaCString
{
git_oid oid;
int err = git_oid_mkstr(&oid, shaCString);
if (err == GIT_ENOTOID)
return nil;
return [self shaWithOID:oid];
}
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
{
return NO;
}
+ (BOOL)isKeyExcludedFromWebScript:(const char *)name
{
return NO;
}
#pragma mark -
#pragma mark PBGitSHA
- (id)initWithOID:(git_oid)g_oid
{
self = [super init];
if (!self)
return nil;
oid = g_oid;
return self;
}
- (NSString *)string
{
if (!string) {
char *hex = git_oid_mkhex(&oid);
if (hex == NULL)
return nil;
string = [NSString stringWithUTF8String:hex];
free(hex);
}
return string;
}
- (BOOL)isEqual:(id)otherSHA
{
if (self == otherSHA)
return YES;
git_oid other_oid = [(PBGitSHA *)otherSHA oid];
return git_oid_cmp(&oid, &other_oid) == 0;
}
- (BOOL)isEqualToOID:(git_oid)other_oid
{
return git_oid_cmp(&oid, &other_oid) == 0;
}
- (NSUInteger)hash
{
NSUInteger hash;
memcpy(&hash, &(oid.id), sizeof(NSUInteger));
return hash;
}
- (NSString *)description
{
return [self string];
}
#pragma mark <NSCopying>
- (id)copyWithZone:(NSZone *)zone
{
git_oid oidCopy;
git_oid_cpy(&oidCopy, &oid);
PBGitSHA *copy = [[[self class] allocWithZone:zone] initWithOID:oidCopy];
return copy;
}
@end