Skip to content

Commit 3b5e04d

Browse files
committed
Replace SHAs with OIDs in GTBranch and GTReference
1 parent 13c32cb commit 3b5e04d

File tree

10 files changed

+38
-36
lines changed

10 files changed

+38
-36
lines changed

ObjectiveGit/GTBranch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef NS_ENUM(NSInteger, GTBranchType) {
4343

4444
@property (nonatomic, readonly) NSString *name;
4545
@property (nonatomic, readonly) NSString *shortName;
46-
@property (nonatomic, readonly) NSString *SHA;
46+
@property (nonatomic, copy, readonly) GTOID *OID;
4747
@property (nonatomic, readonly) NSString *remoteName;
4848
@property (nonatomic, readonly) GTBranchType branchType;
4949
@property (nonatomic, readonly, strong) GTRepository *repository;

ObjectiveGit/GTBranch.m

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
//
2525

2626
#import "GTBranch.h"
27-
#import "GTReference.h"
28-
#import "GTEnumerator.h"
29-
#import "GTRepository.h"
27+
3028
#import "GTCommit.h"
29+
#import "GTEnumerator.h"
30+
#import "GTOID.h"
31+
#import "GTReference.h"
3132
#import "GTRemote.h"
33+
#import "GTRepository.h"
3234
#import "NSError+Git.h"
3335

3436
#import "git2/branch.h"
@@ -38,18 +40,18 @@
3840
@implementation GTBranch
3941

4042
- (NSString *)description {
41-
return [NSString stringWithFormat:@"<%@: %p> name: %@, shortName: %@, sha: %@, remoteName: %@, repository: %@", NSStringFromClass([self class]), self, self.name, self.shortName, self.SHA, self.remoteName, self.repository];
43+
return [NSString stringWithFormat:@"<%@: %p> name: %@, shortName: %@, sha: %@, remoteName: %@, repository: %@", NSStringFromClass([self class]), self, self.name, self.shortName, self.OID, self.remoteName, self.repository];
4244
}
4345

4446
- (BOOL)isEqual:(GTBranch *)otherBranch {
4547
if (otherBranch == self) return YES;
4648
if (![otherBranch isKindOfClass:self.class]) return NO;
4749

48-
return [self.name isEqual:otherBranch.name] && [self.SHA isEqual:otherBranch.SHA];
50+
return [self.name isEqual:otherBranch.name] && [self.OID isEqual:otherBranch.OID];
4951
}
5052

5153
- (NSUInteger)hash {
52-
return self.name.hash ^ self.SHA.hash;
54+
return self.name.hash ^ self.OID.hash;
5355
}
5456

5557

@@ -100,8 +102,8 @@ - (NSString *)shortName {
100102
return @(name);
101103
}
102104

103-
- (NSString *)SHA {
104-
return self.reference.targetSHA;
105+
- (GTOID *)OID {
106+
return self.reference.targetOID;
105107
}
106108

107109
- (NSString *)remoteName {
@@ -119,19 +121,19 @@ - (NSString *)remoteName {
119121
}
120122

121123
- (GTCommit *)targetCommitAndReturnError:(NSError **)error {
122-
if (self.SHA == nil) {
124+
if (self.OID == nil) {
123125
if (error != NULL) *error = GTReference.invalidReferenceError;
124126
return nil;
125127
}
126128

127-
return [self.repository lookUpObjectBySHA:self.SHA objectType:GTObjectTypeCommit error:error];
129+
return [self.repository lookUpObjectByOID:self.OID objectType:GTObjectTypeCommit error:error];
128130
}
129131

130132
- (NSUInteger)numberOfCommitsWithError:(NSError **)error {
131133
GTEnumerator *enumerator = [[GTEnumerator alloc] initWithRepository:self.repository error:error];
132134
if (enumerator == nil) return NSNotFound;
133135

134-
if (![enumerator pushSHA:self.SHA error:error]) return NSNotFound;
136+
if (![enumerator pushSHA:self.OID.SHA error:error]) return NSNotFound;
135137
return [enumerator countRemainingObjects:error];
136138
}
137139

@@ -154,10 +156,10 @@ - (NSArray *)uniqueCommitsRelativeToBranch:(GTBranch *)otherBranch error:(NSErro
154156

155157
[enumerator resetWithOptions:GTEnumeratorOptionsTimeSort];
156158

157-
BOOL success = [enumerator pushSHA:self.SHA error:error];
159+
BOOL success = [enumerator pushSHA:self.OID.SHA error:error];
158160
if (!success) return nil;
159161

160-
success = [enumerator hideSHA:mergeBase.SHA error:error];
162+
success = [enumerator hideSHA:mergeBase.OID.SHA error:error];
161163
if (!success) return nil;
162164

163165
return [enumerator allObjectsWithError:error];

ObjectiveGit/GTReference.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ typedef NS_OPTIONS(NSInteger, GTReferenceType) {
7979
/// The last direct reference in a chain
8080
@property (nonatomic, readonly, copy) GTReference *resolvedReference;
8181

82-
/// The SHA of the target object
83-
@property (nonatomic, readonly, copy) NSString *targetSHA;
82+
/// The OID of the target object.
83+
@property (nonatomic, readonly, copy) GTOID *targetOID;
8484

8585
/// Updates the on-disk reference to point to the target and returns the updated
8686
/// reference.

ObjectiveGit/GTReference.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ - (GTReference *)resolvedReference {
169169
return [self.class referenceByResolvingSymbolicReference:self error:NULL];
170170
}
171171

172-
- (NSString *)targetSHA {
173-
return [self.resolvedTarget SHA];
172+
- (GTOID *)targetOID {
173+
return [self.resolvedTarget OID];
174174
}
175175

176176
- (GTReference *)referenceByUpdatingTarget:(NSString *)newTarget message:(NSString *)message error:(NSError **)error {

ObjectiveGitTests/GTEnumeratorSpec.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
GTReference *HEADRef = [repo headReferenceWithError:NULL];
3232
expect(HEADRef).notTo(beNil());
3333

34-
[enumerator pushSHA:HEADRef.targetSHA error:NULL];
34+
[enumerator pushSHA:HEADRef.targetOID.SHA error:NULL];
3535
NSUInteger count = [enumerator allObjects].count;
3636
expect(@(count)).to(equal(@3));
3737
expect(error).to(beNil());

ObjectiveGitTests/GTReferenceSpec.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
reference = [repository createReferenceNamed:testRefName fromOID:testRefOID message:nil error:&error];
6666
expect(reference).notTo(beNil());
6767
expect(reference.name).to(equal(testRefName));
68-
expect(reference.targetSHA).to(equal(testRefOID.SHA));
68+
expect(reference.targetOID).to(equal(testRefOID.SHA));
6969
});
7070

7171
it(@"should be able to be renamed", ^{
@@ -74,7 +74,7 @@
7474
GTReference *renamedRef = [reference referenceByRenaming:newRefName error:NULL];
7575
expect(renamedRef).notTo(beNil());
7676
expect(renamedRef.name).to(equal(newRefName));
77-
expect(renamedRef.targetSHA).to(equal(testRefOID.SHA));
77+
expect(renamedRef.targetOID).to(equal(testRefOID.SHA));
7878
});
7979

8080
it(@"should be able to change the target", ^{
@@ -83,7 +83,7 @@
8383
GTReference *updatedRef = [reference referenceByUpdatingTarget:newRefTarget message:nil error:NULL];
8484
expect(updatedRef).notTo(beNil());
8585
expect(updatedRef.name).to(equal(testRefName));
86-
expect(updatedRef.targetSHA).to(equal(newRefTarget));
86+
expect(updatedRef.targetOID).to(equal(newRefTarget));
8787
});
8888
});
8989

@@ -119,7 +119,7 @@
119119

120120
void (^expectValidReference)(GTReference *ref, NSString *SHA, GTReferenceType type, NSString *name) = ^(GTReference *ref, NSString *SHA, GTReferenceType type, NSString *name) {
121121
expect(ref).notTo(beNil());
122-
expect(ref.targetSHA).to(equal(SHA));
122+
expect(ref.targetOID).to(equal(SHA));
123123
expect(@(ref.referenceType)).to(equal(@(type)));
124124
expect(ref.name).to(equal(name));
125125
};

ObjectiveGitTests/GTRemotePushSpec.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
GTReference *headReference = [repo headReferenceWithError:nil];
2424

2525
GTEnumerator *commitEnum = [[GTEnumerator alloc] initWithRepository:repo error:nil];
26-
[commitEnum pushSHA:[headReference targetSHA] error:nil];
26+
[commitEnum pushSHA:[headReference targetOID].SHA error:nil];
2727
GTCommit *parent = [commitEnum nextObject];
2828

2929
GTCommit *testCommit = [repo createCommitWithTree:testTree message:message parents:@[ parent ] updatingReferenceNamed:headReference.name error:nil];

ObjectiveGitTests/GTRemoteSpec.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
GTReference *headReference = [repo headReferenceWithError:nil];
145145

146146
GTEnumerator *commitEnum = [[GTEnumerator alloc] initWithRepository:repo error:nil];
147-
[commitEnum pushSHA:[headReference targetSHA] error:nil];
147+
[commitEnum pushSHA:headReference.targetOID.SHA error:nil];
148148
GTCommit *parent = [commitEnum nextObject];
149149

150150
GTCommit *testCommit = [repo createCommitWithTree:testTree message:message parents:@[parent] updatingReferenceNamed:headReference.name error:nil];

ObjectiveGitTests/GTRepositoryResetSpec.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
GTCommit *commit = [repository lookUpObjectBySHA:resetTargetSHA error:NULL];
7070
expect(commit).notTo(beNil());
71-
GTCommit *originalHeadCommit = [repository lookUpObjectBySHA:originalHead.targetSHA error:NULL];
71+
GTCommit *originalHeadCommit = [repository lookUpObjectByOID:originalHead.targetOID error:NULL];
7272
expect(originalHeadCommit).notTo(beNil());
7373

7474
BOOL success = [repository resetToCommit:commit resetType:GTRepositoryResetTypeSoft error:&error];
@@ -77,14 +77,14 @@
7777

7878
GTReference *head = [repository headReferenceWithError:&error];
7979
expect(head).notTo(beNil());
80-
expect(head.targetSHA).to(equal(resetTargetSHA));
80+
expect(head.targetOID).to(equal(resetTargetSHA));
8181

8282
success = [repository resetToCommit:originalHeadCommit resetType:GTRepositoryResetTypeSoft error:&error];
8383
expect(@(success)).to(beTruthy());
8484
expect(error).to(beNil());
8585

8686
head = [repository headReferenceWithError:&error];
87-
expect(head.targetSHA).to(equal(originalHead.targetSHA));
87+
expect(head.targetOID).to(equal(originalHead.targetOID));
8888
});
8989
});
9090

ObjectiveGitTests/GTRepositorySpec.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
GTReference *head = [repository headReferenceWithError:&error];
103103
expect(head).notTo(beNil());
104104
expect(error).to(beNil());
105-
expect(head.targetSHA).to(equal(@"36060c58702ed4c2a40832c51758d5344201d89a"));
105+
expect(head.targetOID).to(equal(@"36060c58702ed4c2a40832c51758d5344201d89a"));
106106
expect(@(head.referenceType)).to(equal(@(GTReferenceTypeOid)));
107107
});
108108

@@ -120,7 +120,7 @@
120120
GTReference *head = [repository headReferenceWithError:&error];
121121
expect(head).notTo(beNil());
122122
expect(error).to(beNil());
123-
expect(head.targetSHA).to(equal(@"36060c58702ed4c2a40832c51758d5344201d89a"));
123+
expect(head.targetOID).to(equal(@"36060c58702ed4c2a40832c51758d5344201d89a"));
124124
expect(@(head.referenceType)).to(equal(@(GTReferenceTypeOid)));
125125
});
126126

@@ -183,7 +183,7 @@
183183
GTReference *head = [self.bareFixtureRepository headReferenceWithError:&error];
184184
expect(head).notTo(beNil());
185185
expect(error).to(beNil());
186-
expect(head.targetSHA).to(equal(@"36060c58702ed4c2a40832c51758d5344201d89a"));
186+
expect(head.targetOID).to(equal(@"36060c58702ed4c2a40832c51758d5344201d89a"));
187187
expect(@(head.referenceType)).to(equal(@(GTReferenceTypeOid)));
188188
});
189189

@@ -276,13 +276,13 @@
276276
NSString *branchName = @"new-test-branch";
277277

278278
NSError *error = nil;
279-
GTBranch *newBranch = [repository createBranchNamed:branchName fromOID:[[GTOID alloc] initWithSHA:currentBranch.SHA] message:nil error:&error];
279+
GTBranch *newBranch = [repository createBranchNamed:branchName fromOID:currentBranch.OID message:nil error:&error];
280280
expect(newBranch).notTo(beNil());
281281
expect(error).to(beNil());
282282

283283
expect(newBranch.shortName).to(equal(branchName));
284284
expect(@(newBranch.branchType)).to(equal(@(GTBranchTypeLocal)));
285-
expect(newBranch.SHA).to(equal(currentBranch.SHA));
285+
expect(newBranch.OID).to(equal(currentBranch.OID));
286286
});
287287
});
288288

@@ -409,7 +409,7 @@
409409

410410
GTCommit *commit = [repository lookUpObjectBySHA:resetTargetSHA error:NULL];
411411
expect(commit).notTo(beNil());
412-
GTCommit *originalHeadCommit = [repository lookUpObjectBySHA:originalHead.targetSHA error:NULL];
412+
GTCommit *originalHeadCommit = [repository lookUpObjectByOID:originalHead.targetOID error:NULL];
413413
expect(originalHeadCommit).notTo(beNil());
414414

415415
BOOL success = [repository resetToCommit:commit resetType:GTRepositoryResetTypeSoft error:&error];
@@ -418,14 +418,14 @@
418418

419419
GTReference *head = [repository headReferenceWithError:&error];
420420
expect(head).notTo(beNil());
421-
expect(head.targetSHA).to(equal(resetTargetSHA));
421+
expect(head.targetOID).to(equal(resetTargetSHA));
422422

423423
success = [repository resetToCommit:originalHeadCommit resetType:GTRepositoryResetTypeSoft error:&error];
424424
expect(@(success)).to(beTruthy());
425425
expect(error).to(beNil());
426426

427427
head = [repository headReferenceWithError:&error];
428-
expect(head.targetSHA).to(equal(originalHead.targetSHA));
428+
expect(head.targetOID).to(equal(originalHead.targetOID));
429429
});
430430
});
431431

0 commit comments

Comments
 (0)