Skip to content

Commit 67da0fd

Browse files
committed
Merge branch 'master' into new_nullable_annotation
2 parents d5049ab + 968396a commit 67da0fd

23 files changed

+504
-32
lines changed

External/libgit2

Submodule libgit2 updated 536 files

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:(NSString * _Nullable)userName;
49+
- (GTCredential * _Nullable)credentialForType:(GTCredentialType)type URL:(NSString * _Nullable)URL userName:(NSString * _Nullable)userName;
5050
@end
5151

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

ObjectiveGit/GTCredential.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ int GTCredentialAcquireCallback(git_cred **git_cred, const char *url, const char
109109
return GIT_ERROR;
110110
}
111111

112-
NSString *URL = (url != NULL ? @(url) : nil);
112+
NSString *URL = (url != NULL ? @(url) : @"");
113113
NSString *userName = (username_from_url != NULL ? @(username_from_url) : nil);
114114

115115
GTCredential *cred = [provider credentialForType:(GTCredentialType)allowed_types URL:URL userName:userName];

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/GTIndexEntry.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ NS_ASSUME_NONNULL_BEGIN
6161
- (const git_index_entry *)git_index_entry __attribute__((objc_returns_inner_pointer));
6262

6363
/// The entry's index. This may be nil if nil is passed in to -initWithGitIndexEntry:
64-
@property (nonatomic, strong, readonly) GTIndex *index;
64+
@property (nonatomic, strong, readonly, nullable) GTIndex *index;
6565

6666
/// The repository-relative path for the entry.
6767
@property (nonatomic, readonly, copy) NSString *path;
@@ -86,8 +86,8 @@ NS_ASSUME_NONNULL_BEGIN
8686

8787
@interface GTObject (GTIndexEntry)
8888

89-
+ (instancetype)objectWithIndexEntry:(GTIndexEntry *)treeEntry error:(NSError **)error;
90-
- (instancetype)initWithIndexEntry:(GTIndexEntry *)treeEntry error:(NSError **)error;
89+
+ (nullable instancetype)objectWithIndexEntry:(GTIndexEntry *)indexEntry error:(NSError **)error;
90+
- (nullable instancetype)initWithIndexEntry:(GTIndexEntry *)indexEntry error:(NSError **)error;
9191

9292
@end
9393

ObjectiveGit/GTNote.h

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//
2+
// GTNote.h
3+
// ObjectiveGitFramework
4+
//
5+
// Created by Slava Karpenko on 5/16/2016.
6+
//
7+
// The MIT License
8+
//
9+
// Copyright (c) 2016 Wildbit LLC
10+
//
11+
// Permission is hereby granted, free of charge, to any person obtaining a copy
12+
// of this software and associated documentation files (the "Software"), to deal
13+
// in the Software without restriction, including without limitation the rights
14+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
// copies of the Software, and to permit persons to whom the Software is
16+
// furnished to do so, subject to the following conditions:
17+
//
18+
// The above copyright notice and this permission notice shall be included in
19+
// all copies or substantial portions of the Software.
20+
//
21+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27+
// THE SOFTWARE.
28+
//
29+
30+
#import <Foundation/Foundation.h>
31+
#import "git2/oid.h"
32+
33+
@class GTSignature;
34+
@class GTRepository;
35+
@class GTOID;
36+
@class GTObject;
37+
38+
NS_ASSUME_NONNULL_BEGIN
39+
40+
@interface GTNote : NSObject {}
41+
42+
/// The author of the note.
43+
@property (nonatomic, readonly, strong, nullable) GTSignature *author;
44+
45+
/// The committer of the note.
46+
@property (nonatomic, readonly, strong, nullable) GTSignature *committer;
47+
48+
/// Content of the note.
49+
@property (nonatomic, readonly, strong) NSString *note;
50+
51+
@property (nonatomic, readonly, strong) GTObject *target;
52+
53+
/// The underlying `git_note` object.
54+
- (git_note *)git_note __attribute__((objc_returns_inner_pointer));
55+
56+
/// Create a note with target OID in the given repository.
57+
///
58+
/// oid - OID of the target to attach to
59+
/// repository - Repository containing the target OID refers to
60+
/// referenceName - Name for the notes reference in the repo, or nil for default ("refs/notes/commits")
61+
/// error - Will be filled with a NSError object in case of error.
62+
/// May be NULL.
63+
///
64+
/// Returns initialized GTNote instance or nil on failure (error will be populated, if passed).
65+
- (nullable instancetype)initWithTargetOID:(GTOID *)oid repository:(GTRepository *)repository referenceName:(nullable NSString *)referenceName error:(NSError **)error;
66+
67+
/// Create a note with target libgit2 oid in the given repository.
68+
///
69+
/// oid - git_oid of the target to attach to
70+
/// repository - Repository containing the target OID refers to
71+
/// referenceName - Name for the notes reference in the repo, or NULL for default ("refs/notes/commits")
72+
///
73+
/// Returns initialized GTNote instance or nil on failure.
74+
- (nullable instancetype)initWithTargetGitOID:(git_oid *)oid repository:(git_repository *)repository referenceName:(const char * _Nullable)referenceName error:(NSError **)error NS_DESIGNATED_INITIALIZER;
75+
76+
- (instancetype)init NS_UNAVAILABLE;
77+
78+
79+
/// Return a default reference name (that is used if you pass nil to any referenceName parameter)
80+
///
81+
/// repository - Repository for which to get the default notes reference name.
82+
/// error - Will be filled with a git error code in case of error.
83+
/// May be NULL.
84+
///
85+
/// Returns default reference name (usually "refs/notes/commits").
86+
+ (nullable NSString *)defaultReferenceNameForRepository:(GTRepository *)repository error:(NSError **)error;
87+
88+
@end
89+
90+
NS_ASSUME_NONNULL_END
91+

ObjectiveGit/GTNote.m

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//
2+
// GTNote.m
3+
// ObjectiveGitFramework
4+
//
5+
// Created by Slava Karpenko on 16.05.16.
6+
// Copyright © 2016 Wildbit LLC. All rights reserved.
7+
//
8+
9+
#import "GTNote.h"
10+
#import "NSError+Git.h"
11+
#import "GTSignature.h"
12+
#import "GTReference.h"
13+
#import "GTRepository.h"
14+
#import "NSString+Git.h"
15+
#import "GTOID.h"
16+
17+
#import "git2/errors.h"
18+
#import "git2/notes.h"
19+
20+
@interface GTNote ()
21+
{
22+
git_note *_note;
23+
}
24+
25+
@end
26+
@implementation GTNote
27+
28+
- (NSString *)description {
29+
return [NSString stringWithFormat:@"<%@: %p>", NSStringFromClass([self class]), self];
30+
}
31+
32+
#pragma mark API
33+
34+
- (void)dealloc {
35+
if (_note != NULL) {
36+
git_note_free(_note);
37+
}
38+
}
39+
40+
- (git_note *)git_note {
41+
return _note;
42+
}
43+
44+
- (NSString *)note {
45+
return @(git_note_message(self.git_note));
46+
}
47+
48+
- (GTSignature *)author {
49+
return [[GTSignature alloc] initWithGitSignature:git_note_author(self.git_note)];
50+
}
51+
52+
- (GTSignature *)committer {
53+
return [[GTSignature alloc] initWithGitSignature:git_note_committer(self.git_note)];
54+
}
55+
56+
- (GTOID *)targetOID {
57+
return [GTOID oidWithGitOid:git_note_id(self.git_note)];
58+
}
59+
60+
- (instancetype)initWithTargetOID:(GTOID *)oid repository:(GTRepository *)repository referenceName:(NSString *)referenceName error:(NSError **)error {
61+
return [self initWithTargetGitOID:(git_oid *)oid.git_oid repository:repository.git_repository referenceName:referenceName.UTF8String error:error];
62+
}
63+
64+
- (instancetype)initWithTargetGitOID:(git_oid *)oid repository:(git_repository *)repository referenceName:(const char *)referenceName error:(NSError **)error {
65+
self = [super init];
66+
if (self == nil) return nil;
67+
68+
int gitErr = git_note_read(&_note, repository, referenceName, oid);
69+
70+
if (gitErr != GIT_OK) {
71+
if (error != NULL) *error = [NSError git_errorFor:gitErr description:@"Unable to read note"];
72+
return nil;
73+
}
74+
75+
return self;
76+
}
77+
78+
- (instancetype)init {
79+
NSAssert(NO, @"Call to an unavailable initializer.");
80+
return nil;
81+
}
82+
83+
+ (NSString *)defaultReferenceNameForRepository:(GTRepository *)repository error:(NSError **)error {
84+
NSString *noteRef = nil;
85+
86+
git_buf default_ref_name = { 0 };
87+
int gitErr = git_note_default_ref(&default_ref_name, repository.git_repository);
88+
if (gitErr != GIT_OK) {
89+
if (error != NULL) *error = [NSError git_errorFor:gitErr description:@"Unable to get default git notes reference name"];
90+
return nil;
91+
}
92+
93+
if (default_ref_name.ptr != NULL) {
94+
noteRef = @(default_ref_name.ptr);
95+
} else {
96+
if (error != NULL) *error = [NSError git_errorFor:GIT_ERROR description:@"Unable to get default git notes reference name"];
97+
}
98+
99+
git_buf_free(&default_ref_name);
100+
101+
return noteRef;
102+
}
103+
@end

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 *SHA;
19+
@property (nonatomic, readonly, copy, nullable) NSString *SHA;
2020

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

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+Merging.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ - (BOOL)mergeBranchIntoCurrentBranch:(GTBranch *)branch withError:(NSError **)er
139139
// Write conflicts
140140
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
141141
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
142-
checkout_opts.checkout_strategy = GIT_CHECKOUT_ALLOW_CONFLICTS;
142+
checkout_opts.checkout_strategy = (GIT_CHECKOUT_SAFE | GIT_CHECKOUT_ALLOW_CONFLICTS);
143143

144144
git_annotated_commit *annotatedCommit;
145145
[self annotatedCommit:&annotatedCommit fromCommit:remoteCommit error:error];

ObjectiveGit/GTRepository+References.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright (c) 2015 GitHub, Inc. All rights reserved.
77
//
88

9-
#import "GTrepository.h"
9+
#import "GTRepository.h"
1010

1111
NS_ASSUME_NONNULL_BEGIN
1212

ObjectiveGit/GTRepository+RemoteOperations.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ extern NSString *const GTRepositoryRemoteOptionsFetchPrune;
2222
/// A `GTRemoteAutoTagOption`, that will be used to determine how the fetch should handle tags.
2323
extern NSString *const GTRepositoryRemoteOptionsDownloadTags;
2424

25+
/// A `@(BOOL)`, indicating git notes should also be pushed to the default notes reference name (if `@(YES)`), or an `NSArray(NSString)` containing reference names to be pushed through.
26+
extern NSString *const GTRepositoryRemoteOptionsPushNotes;
27+
2528
/// An enum describing the data needed for pruning.
2629
/// See `git_fetch_prune_t`.
2730
typedef NS_ENUM(NSInteger, GTFetchPruneOption) {
@@ -76,6 +79,7 @@ typedef NS_ENUM(NSInteger, GTFetchPruneOption) {
7679
/// options - Options applied to the push operation. Can be NULL.
7780
/// Recognized options are:
7881
/// `GTRepositoryRemoteOptionsCredentialProvider`
82+
/// `GTRepositoryRemoteOptionsPushNotes` (to push together with notes in one push)
7983
/// error - The error if one occurred. Can be NULL.
8084
/// progressBlock - An optional callback for monitoring progress. May be NULL.
8185
///
@@ -89,14 +93,29 @@ typedef NS_ENUM(NSInteger, GTFetchPruneOption) {
8993
/// remote - The remote to push to. Must not be nil.
9094
/// options - Options applied to the push operation. Can be NULL.
9195
/// Recognized options are:
92-
/// `GTRepositoryRemoteOptionsCredentialProvider`
96+
/// `GTRepositoryRemoteOptionsCredentialProvider`,
97+
/// `GTRepositoryRemoteOptionsPushNotes` (to push together with notes in one push)
9398
/// error - The error if one occurred. Can be NULL.
9499
/// progressBlock - An optional callback for monitoring progress. May be NULL.
95100
///
96101
/// Returns YES if the push was successful, NO otherwise (and `error`, if provided,
97102
/// will point to an error describing what happened).
98103
- (BOOL)pushBranches:(NSArray<GTBranch *> *)branches toRemote:(GTRemote *)remote withOptions:(NSDictionary * _Nullable)options error:(NSError **)error progress:(void (^ _Nullable)(unsigned int current, unsigned int total, size_t bytes, BOOL *stop))progressBlock;
99104

105+
/// Push a given Git notes reference name to a remote.
106+
///
107+
/// noteReferenceName - Name of the notes reference. If NULL, will default to whatever the default is (e.g. "refs/notes/commits")
108+
/// remote - The remote to push to. Must not be nil.
109+
/// options - Options applied to the push operation. Can be NULL.
110+
/// Recognized options are:
111+
/// `GTRepositoryRemoteOptionsCredentialProvider`
112+
/// error - The error if one occurred. Can be NULL.
113+
/// progressBlock - An optional callback for monitoring progress. May be NULL.
114+
///
115+
/// Returns YES if the push was successful, NO otherwise (and `error`, if provided,
116+
/// will point to an error describing what happened).
117+
- (BOOL)pushNotes:(nullable NSString *)noteReferenceName toRemote:(GTRemote *)remote withOptions:(nullable NSDictionary *)options error:(NSError **)error progress:(nullable void (^)(unsigned int current, unsigned int total, size_t bytes, BOOL *stop))progressBlock;
118+
100119
/// Delete a remote branch
101120
///
102121
/// branch - The branch to push. Must not be nil.

0 commit comments

Comments
 (0)