Skip to content

Commit 6005a6c

Browse files
committed
🚨 Extract local vars to work around OID nullability warnings
1 parent 87896b2 commit 6005a6c

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

‎ObjectiveGit/GTBranch.m

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,23 @@ - (NSString *)remoteName {
124124
}
125125

126126
- (GTCommit *)targetCommitWithError:(NSError **)error {
127-
if (self.OID == nil) {
127+
GTOID *oid = self.OID;
128+
if (oid == nil) {
128129
if (error != NULL) *error = GTReference.invalidReferenceError;
129130
return nil;
130131
}
131132

132-
return [self.repository lookUpObjectByOID:self.OID objectType:GTObjectTypeCommit error:error];
133+
return [self.repository lookUpObjectByOID:oid objectType:GTObjectTypeCommit error:error];
133134
}
134135

135136
- (NSUInteger)numberOfCommitsWithError:(NSError **)error {
136137
GTEnumerator *enumerator = [[GTEnumerator alloc] initWithRepository:self.repository error:error];
137138
if (enumerator == nil) return NSNotFound;
138139

139-
if (![enumerator pushSHA:self.OID.SHA error:error]) return NSNotFound;
140+
GTOID *oid = self.OID;
141+
if (oid == nil) return NSNotFound;
142+
143+
if (![enumerator pushSHA:oid.SHA error:error]) return NSNotFound;
140144
return [enumerator countRemainingObjects:error];
141145
}
142146

@@ -157,7 +161,9 @@ - (BOOL)isHEAD {
157161
}
158162

159163
- (NSArray *)uniqueCommitsRelativeToBranch:(GTBranch *)otherBranch error:(NSError **)error {
160-
GTEnumerator *enumerator = [self.repository enumeratorForUniqueCommitsFromOID:self.OID relativeToOID:otherBranch.OID error:error];
164+
GTOID *oid = self.OID;
165+
GTOID *otherOID = otherBranch.OID;
166+
GTEnumerator *enumerator = [self.repository enumeratorForUniqueCommitsFromOID:oid relativeToOID:otherOID error:error];
161167
return [enumerator allObjectsWithError:error];
162168
}
163169

@@ -253,7 +259,9 @@ - (GTBranch *)reloadedBranchWithError:(NSError **)error {
253259
}
254260

255261
- (BOOL)calculateAhead:(size_t *)ahead behind:(size_t *)behind relativeTo:(GTBranch *)branch error:(NSError **)error {
256-
return [self.repository calculateAhead:ahead behind:behind ofOID:self.OID relativeToOID:branch.OID error:error];
262+
GTOID *oid = self.OID;
263+
GTOID *branchOID = branch.OID;
264+
return [self.repository calculateAhead:ahead behind:behind ofOID:oid relativeToOID:branchOID error:error];
257265
}
258266

259267
@end

‎ObjectiveGit/GTReference.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ NS_ASSUME_NONNULL_BEGIN
9696
@property (nonatomic, readonly, copy) GTReference *resolvedReference;
9797

9898
/// The OID of the target object.
99-
@property (nonatomic, readonly, copy) GTOID *targetOID;
99+
@property (nonatomic, readonly, copy, nullable) GTOID *targetOID;
100100

101101
/// Updates the on-disk reference to point to the target and returns the updated
102102
/// reference.

0 commit comments

Comments
 (0)