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"
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
@@ -144,22 +146,7 @@ - (GTBranchType)branchType {
144146}
145147
146148- (NSArray *)uniqueCommitsRelativeToBranch : (GTBranch *)otherBranch error : (NSError **)error {
147- NSParameterAssert (otherBranch != nil );
148-
149- GTCommit *mergeBase = [self .repository mergeBaseBetweenFirstOID: self .reference.OID secondOID: otherBranch.reference.OID error: error];
150- if (mergeBase == nil ) return nil ;
151-
152- GTEnumerator *enumerator = [[GTEnumerator alloc ] initWithRepository: self .repository error: error];
153- if (enumerator == nil ) return nil ;
154-
155- [enumerator resetWithOptions: GTEnumeratorOptionsTimeSort];
156-
157- BOOL success = [enumerator pushSHA: self .SHA error: error];
158- if (!success) return nil ;
159-
160- success = [enumerator hideSHA: mergeBase.SHA error: error];
161- if (!success) return nil ;
162-
149+ GTEnumerator *enumerator = [self .repository enumerateUniqueCommitsUpToOID: self .OID relativeToOID: otherBranch.OID error: error];
163150 return [enumerator allObjectsWithError: error];
164151}
165152
@@ -223,19 +210,7 @@ - (GTBranch *)reloadedBranchWithError:(NSError **)error {
223210}
224211
225212- (BOOL )calculateAhead : (size_t *)ahead behind : (size_t *)behind relativeTo : (GTBranch *)branch error : (NSError **)error {
226- if (branch == nil ) {
227- *ahead = 0 ;
228- *behind = 0 ;
229- return YES ;
230- }
231-
232- int errorCode = git_graph_ahead_behind (ahead, behind, self.repository .git_repository , self.reference .git_oid , branch.reference .git_oid );
233- if (errorCode != GIT_OK && error != NULL ) {
234- *error = [NSError git_errorFor: errorCode description: @" Failed to calculate ahead/behind count of %@ relative to %@ " , self , branch];
235- return NO ;
236- }
237-
238- return YES ;
213+ return [self .repository calculateAhead: ahead behind: behind ofOID: self .OID relativeToOID: branch.OID error: error];
239214}
240215
241216@end
0 commit comments