Skip to content

Commit 87896b2

Browse files
committed
Fix most nullability issues
1 parent 3a0b7da commit 87896b2

19 files changed

+68
-38
lines changed

ObjectiveGit/GTBlob.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ NS_ASSUME_NONNULL_BEGIN
104104
- (git_blob *)git_blob __attribute__((objc_returns_inner_pointer));
105105

106106
- (git_off_t)size;
107-
- (NSString *)content;
108-
- (NSData * _Nullable)data;
107+
- (NSString * _Nullable)content;
108+
- (NSData *)data;
109109

110110
/// Attempts to apply the filter list for `path` to the blob.
111111
///

ObjectiveGit/GTBranch.m

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,21 @@ - (BOOL)rename:(NSString *)name force:(BOOL)force error:(NSError **)error {
179179
return NO;
180180
}
181181

182-
_reference = [[GTReference alloc] initWithGitReference:git_ref repository:self.repository];
182+
GTReference *renamedRef = [[GTReference alloc] initWithGitReference:git_ref repository:self.repository];
183+
NSAssert(renamedRef, @"Unable to allocate renamed ref");
184+
_reference = renamedRef;
183185

184186
return YES;
185187
}
186188

187189
- (GTBranch *)trackingBranchWithError:(NSError **)error success:(BOOL *)success {
190+
BOOL underSuccess = NO;
191+
if (success == NULL) {
192+
success = &underSuccess;
193+
}
194+
188195
if (self.branchType == GTBranchTypeRemote) {
189-
if (success != NULL) *success = YES;
196+
*success = YES;
190197
return self;
191198
}
192199

@@ -195,25 +202,32 @@ - (GTBranch *)trackingBranchWithError:(NSError **)error success:(BOOL *)success
195202

196203
// GIT_ENOTFOUND means no tracking branch found.
197204
if (gitError == GIT_ENOTFOUND) {
198-
if (success != NULL) *success = YES;
205+
*success = YES;
199206
return nil;
200207
}
201208

202209
if (gitError != GIT_OK) {
203-
if (success != NULL) *success = NO;
210+
*success = NO;
204211
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to create reference to tracking branch from %@", self];
205212
return nil;
206213
}
207214

208215
if (trackingRef == NULL) {
209-
if (success != NULL) *success = NO;
216+
*success = NO;
210217
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Got a NULL remote ref for %@", self];
211218
return nil;
212219
}
213220

214-
if (success != NULL) *success = YES;
221+
GTReference *upsteamRef = [[GTReference alloc] initWithGitReference:trackingRef repository:self.repository];
222+
if (upsteamRef == nil) {
223+
*success = NO;
224+
if (error != NULL) *error = [NSError git_errorFor:GIT_ERROR description:@"Failed to allocate upstream ref"];
225+
return nil;
226+
}
227+
228+
*success = YES;
215229

216-
return [[self class] branchWithReference:[[GTReference alloc] initWithGitReference:trackingRef repository:self.repository]];
230+
return [[self class] branchWithReference:upsteamRef];
217231
}
218232

219233
- (BOOL)updateTrackingBranch:(GTBranch *)trackingBranch error:(NSError **)error {

ObjectiveGit/GTCheckoutOptions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ typedef NS_OPTIONS(NSInteger, GTCheckoutNotifyFlags) {
8787
@property (assign) GTCheckoutStrategyType strategy;
8888

8989
/// The checkout progress block that was passed in.
90-
@property (copy) void (^progressBlock)(NSString *path, NSUInteger completedSteps, NSUInteger totalSteps);
90+
@property (copy, nullable) void (^progressBlock)(NSString *path, NSUInteger completedSteps, NSUInteger totalSteps);
9191

9292
/// The notification flags currently enabled.
9393
@property (assign) GTCheckoutNotifyFlags notifyFlags;
9494

9595
/// The checkout notification block that was passed in.
96-
@property (copy) int (^notifyBlock)(GTCheckoutNotifyFlags why, NSString *path, GTDiffFile *baseline, GTDiffFile *target, GTDiffFile *workdir);
96+
@property (copy, nullable) int (^notifyBlock)(GTCheckoutNotifyFlags why, NSString *path, GTDiffFile *baseline, GTDiffFile *target, GTDiffFile *workdir);
9797

9898
/// An array of strings used to restrict what will be checked out.
9999
@property (copy) NSArray <NSString *> *pathSpecs;

ObjectiveGit/GTConfiguration.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,12 @@ - (NSArray *)remotes {
134134
NSMutableArray *remotes = [NSMutableArray arrayWithCapacity:names.count];
135135
for (size_t i = 0; i < names.count; i++) {
136136
const char *name = names.strings[i];
137-
git_remote *remote = NULL;
137+
git_remote *git_remote = NULL;
138138

139-
if (git_remote_lookup(&remote, repository.git_repository, name) == 0) {
140-
[remotes addObject:[[GTRemote alloc] initWithGitRemote:remote inRepository:repository]];
139+
if (git_remote_lookup(&git_remote, repository.git_repository, name) == 0) {
140+
GTRemote *remote = [[GTRemote alloc] initWithGitRemote:git_remote inRepository:repository];
141+
if (remote)
142+
[remotes addObject:remote];
141143
}
142144
}
143145

ObjectiveGit/GTDiffDelta.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ NS_ASSUME_NONNULL_BEGIN
6363
@property (nonatomic, assign, readonly) GTDiffFileFlag flags;
6464

6565
/// The file to the "left" of the diff.
66-
@property (nonatomic, readonly, copy) GTDiffFile *oldFile;
66+
@property (nonatomic, readonly, copy) GTDiffFile * _Nullable oldFile;
6767

6868
/// The file to the "right" of the diff.
69-
@property (nonatomic, readonly, copy) GTDiffFile *newFile __attribute__((ns_returns_not_retained));
69+
@property (nonatomic, readonly, copy) GTDiffFile * _Nullable newFile __attribute__((ns_returns_not_retained));
7070

7171
/// The type of change that this delta represents.
7272
///

ObjectiveGit/GTDiffHunk.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ - (instancetype)initWithPatch:(GTDiffPatch *)patch hunkIndex:(NSUInteger)hunkInd
4747

4848
_patch = patch;
4949
_hunkIndex = hunkIndex;
50-
_header = [[[NSString alloc] initWithBytes:self.git_hunk->header length:self.git_hunk->header_len encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:NSCharacterSet.newlineCharacterSet];
50+
NSString *hunkHeader = [[[NSString alloc] initWithBytes:self.git_hunk->header length:self.git_hunk->header_len encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:NSCharacterSet.newlineCharacterSet];
51+
NSAssert(hunkHeader != nil, @"Failed to build hunk header");
52+
_header = hunkHeader;
5153

5254
return self;
5355
}

ObjectiveGit/GTEnumerator.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ - (NSUInteger)countRemainingObjects:(NSError **)error {
259259
#pragma mark NSEnumerator
260260

261261
- (NSArray *)allObjects {
262-
return [self allObjectsWithError:NULL];
262+
NSArray *objects = [self allObjectsWithError:NULL];
263+
return objects ? objects : [NSArray array];
263264
}
264265

265266
- (id)nextObject {

ObjectiveGit/GTFilter.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ static void GTFilterShutdown(git_filter *filter) {
9696

9797
static int GTFilterCheck(git_filter *filter, void **payload, const git_filter_source *src, const char **attr_values) {
9898
GTFilter *self = GTFiltersGitFilterToRegisteredFilters[[NSValue valueWithPointer:filter]];
99-
BOOL accept = self.checkBlock(payload, [[GTFilterSource alloc] initWithGitFilterSource:src], attr_values);
99+
GTFilterSource *source = [[GTFilterSource alloc] initWithGitFilterSource:src];
100+
NSCAssert(source != nil, @"Unexpected nil filter source");
101+
BOOL accept = self.checkBlock(payload, source, attr_values);
100102
return accept ? 0 : GIT_PASSTHROUGH;
101103
}
102104

ObjectiveGit/GTIndex.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ - (GTTree *)writeTreeToRepository:(GTRepository *)repository error:(NSError **)e
278278
- (NSArray *)entries {
279279
NSMutableArray *entries = [NSMutableArray arrayWithCapacity:self.entryCount];
280280
for (NSUInteger i = 0; i < self.entryCount; i++) {
281-
[entries addObject:[self entryAtIndex:i]];
281+
GTIndexEntry *entry = [self entryAtIndex:i];
282+
if (entry)
283+
[entries addObject:entry];
282284
}
283285

284286
return entries;

ObjectiveGit/GTOID.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
1616
@interface GTOID : NSObject <NSCopying>
1717

1818
/// The SHA pointed to by the OID.
19-
@property (nonatomic, readonly, copy) NSString * _Nullable SHA;
19+
@property (nonatomic, readonly, copy) NSString *SHA;
2020

2121
/// Is the OID all zero? This usually indicates that the object has not been
2222
/// inserted into the ODB yet.

0 commit comments

Comments
 (0)