Skip to content

Commit 3480278

Browse files
authored
Merge pull request #589 from Uncommon/nullables
Add some nullables to methods & properties that can return nil
2 parents 4673546 + 10420c9 commit 3480278

File tree

6 files changed

+14
-15
lines changed

6 files changed

+14
-15
lines changed

ObjectiveGit/GTCredential.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
4646
/// type - the credential types allowed by the operation.
4747
/// URL - the URL the operation is authenticating against.
4848
/// userName - the user name provided by the operation. Can be nil, and might be ignored.
49-
- (GTCredential * _Nullable)credentialForType:(GTCredentialType)type URL:(NSString *)URL userName:(nullable NSString *)userName;
49+
- (GTCredential * _Nullable)credentialForType:(GTCredentialType)type URL:(nullable NSString *)URL userName:(nullable NSString *)userName;
5050
@end
5151

5252
/// The GTCredential class is used to provide authentication data.

ObjectiveGit/GTIndex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ NS_ASSUME_NONNULL_BEGIN
6969
/// error - If not NULL, set to any error that occurs.
7070
///
7171
/// Returns the loaded index, or nil if an error occurred.
72-
+ (instancetype)indexWithFileURL:(NSURL *)fileURL repository:(GTRepository *)repository error:(NSError **)error;
72+
+ (nullable instancetype)indexWithFileURL:(NSURL *)fileURL repository:(GTRepository *)repository error:(NSError **)error;
7373

7474
- (instancetype)init NS_UNAVAILABLE;
7575

ObjectiveGit/GTOID.m

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ - (const git_oid *)git_oid {
2727
}
2828

2929
- (NSString *)SHA {
30-
char *SHA = malloc(GIT_OID_HEXSZ);
31-
if (SHA == NULL) return nil;
32-
33-
git_oid_fmt(SHA, self.git_oid);
34-
35-
NSString *str = [[NSString alloc] initWithBytesNoCopy:SHA length:GIT_OID_HEXSZ encoding:NSUTF8StringEncoding freeWhenDone:YES];
36-
if (str == nil) free(SHA);
30+
char *SHA = git_oid_tostr_s(self.git_oid);
31+
NSString *str = [[NSString alloc] initWithBytes:SHA
32+
length:GIT_OID_HEXSZ
33+
encoding:NSUTF8StringEncoding];
34+
NSAssert(str != nil, @"Failed to create SHA string");
3735
return str;
3836
}
3937

ObjectiveGit/GTReference.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ NS_ASSUME_NONNULL_BEGIN
5252
@property (nonatomic, readonly, strong) GTRepository *repository;
5353
@property (nonatomic, readonly) GTReferenceType referenceType;
5454
@property (nonatomic, readonly) const git_oid *git_oid;
55-
@property (nonatomic, strong, readonly) GTOID *OID;
55+
@property (nonatomic, strong, readonly, nullable) GTOID *OID;
5656

5757
/// Whether this is a remote-tracking branch.
5858
@property (nonatomic, readonly, getter = isRemote) BOOL remote;
@@ -78,10 +78,10 @@ NS_ASSUME_NONNULL_BEGIN
7878
- (git_reference *)git_reference __attribute__((objc_returns_inner_pointer));
7979

8080
/// The target (either GTObject or GTReference) to which the reference points.
81-
@property (nonatomic, readonly, copy) id unresolvedTarget;
81+
@property (nonatomic, readonly, copy, nullable) id unresolvedTarget;
8282

8383
/// The resolved object to which the reference points.
84-
@property (nonatomic, readonly, copy) id resolvedTarget;
84+
@property (nonatomic, readonly, copy, nullable) id resolvedTarget;
8585

8686
/// The last direct reference in a chain
8787
@property (nonatomic, readonly, copy) GTReference *resolvedReference;

ObjectiveGit/GTRepository.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ typedef NS_ENUM(NSInteger, GTRepositoryStateType) {
177177
@interface GTRepository : NSObject
178178

179179
/// The file URL for the repository's working directory.
180-
@property (nonatomic, readonly, strong) NSURL *fileURL;
180+
/// Returns nil for a bare repository.
181+
@property (nonatomic, readonly, strong, nullable) NSURL *fileURL;
181182
/// The file URL for the repository's .git directory.
182183
@property (nonatomic, readonly, strong, nullable) NSURL *gitDirectoryURL;
183184

ObjectiveGit/GTSignature.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ NS_ASSUME_NONNULL_BEGIN
4242
@property (nonatomic, readonly, copy, nullable) NSString *email;
4343

4444
/// The time when the action happened.
45-
@property (nonatomic, readonly, strong) NSDate *time;
45+
@property (nonatomic, readonly, strong, nullable) NSDate *time;
4646

4747
/// The time zone that `time` should be interpreted relative to.
48-
@property (nonatomic, readonly, copy) NSTimeZone *timeZone;
48+
@property (nonatomic, readonly, copy, nullable) NSTimeZone *timeZone;
4949

5050
/// Initializes the receiver with the given signature.
5151
///

0 commit comments

Comments
 (0)