-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Git notes #576
Merged
Merged
Git notes #576
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
abc1d74
Updating libgit2 pointer
slavikus 41279e4
Updating for new libgit2 git_remote_connect() call
slavikus 0871b0e
Merge remote-tracking branch 'upstream/master'
slavikus 47dc0fc
Git notes support.
slavikus fe13986
Added support for [GTRepository pushNotes:...]
slavikus 6df9faf
Fixes per @tiennou feedback
slavikus 947058d
Push branches and notes in one operation
slavikus e99a62e
Check if notes reference exists before pushing it
slavikus b64f024
Merge remote-tracking branch 'upstream/master'
slavikus 0661bab
Merge branch 'master' into git-notes
slavikus c27e838
Merge remote-tracking branch 'upstream/master' into git-notes
slavikus 73037a4
Style fixes per @tiennou feedback
slavikus 75e5356
Merge remote-tracking branch 'upstream/master' into git-notes
slavikus 16ef587
Merge remote-tracking branch 'upstream/master'
slavikus 2352543
Respect nullable returns in various methods
slavikus 6e96e11
Merge branch 'master' into git-notes
slavikus 6228da7
Merge remote-tracking branch 'upstream/master' into git-notes
slavikus 2fea0a5
Fix nullability warning for GTNote
slavikus 5bf9d5f
Corrections per @tiennou feedback
slavikus f4a1103
Rollback libgit2 back to globally used release
slavikus 55898a7
More fixes for pull request #576
slavikus 16f980f
Extra newlines removal
slavikus 927cc49
Fix tests for GTNote
slavikus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// | ||
// GTNote.h | ||
// ObjectiveGitFramework | ||
// | ||
// Created by Slava Karpenko on 5/16/2016. | ||
// | ||
// The MIT License | ||
// | ||
// Copyright (c) 2016 Wildbit LLC | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "git2/oid.h" | ||
|
||
@class GTSignature; | ||
@class GTRepository; | ||
@class GTOID; | ||
@class GTObject; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface GTNote : NSObject {} | ||
|
||
/// The author of the note. | ||
@property (nonatomic, readonly, strong, nullable) GTSignature *author; | ||
|
||
/// The committer of the note. | ||
@property (nonatomic, readonly, strong, nullable) GTSignature *committer; | ||
|
||
/// Content of the note. | ||
@property (nonatomic, readonly, strong) NSString *note; | ||
|
||
@property (nonatomic, readonly, strong) GTObject *target; | ||
|
||
/// The underlying `git_note` object. | ||
- (git_note *)git_note __attribute__((objc_returns_inner_pointer)); | ||
|
||
/// Create a note with target OID in the given repository. | ||
/// | ||
/// oid - OID of the target to attach to | ||
/// repository - Repository containing the target OID refers to | ||
/// referenceName - Name for the notes reference in the repo, or nil for default ("refs/notes/commits") | ||
/// error - Will be filled with a NSError object in case of error. | ||
/// May be NULL. | ||
/// | ||
/// Returns initialized GTNote instance or nil on failure (error will be populated, if passed). | ||
- (nullable instancetype)initWithTargetOID:(GTOID *)oid repository:(GTRepository *)repository referenceName:(nullable NSString *)referenceName error:(NSError **)error; | ||
|
||
/// Create a note with target libgit2 oid in the given repository. | ||
/// | ||
/// oid - git_oid of the target to attach to | ||
/// repository - Repository containing the target OID refers to | ||
/// referenceName - Name for the notes reference in the repo, or NULL for default ("refs/notes/commits") | ||
/// | ||
/// Returns initialized GTNote instance or nil on failure. | ||
- (nullable instancetype)initWithTargetGitOID:(git_oid *)oid repository:(git_repository *)repository referenceName:(const char * _Nullable)referenceName error:(NSError **)error NS_DESIGNATED_INITIALIZER; | ||
|
||
- (instancetype)init NS_UNAVAILABLE; | ||
|
||
|
||
/// Return a default reference name (that is used if you pass nil to any referenceName parameter) | ||
/// | ||
/// repository - Repository for which to get the default notes reference name. | ||
/// error - Will be filled with a git error code in case of error. | ||
/// May be NULL. | ||
/// | ||
/// Returns default reference name (usually "refs/notes/commits"). | ||
+ (nullable NSString *)defaultReferenceNameForRepository:(GTRepository *)repository error:(NSError **)error; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// GTNote.m | ||
// ObjectiveGitFramework | ||
// | ||
// Created by Slava Karpenko on 16.05.16. | ||
// Copyright © 2016 Wildbit LLC. All rights reserved. | ||
// | ||
|
||
#import "GTNote.h" | ||
#import "NSError+Git.h" | ||
#import "GTSignature.h" | ||
#import "GTReference.h" | ||
#import "GTRepository.h" | ||
#import "NSString+Git.h" | ||
#import "GTOID.h" | ||
|
||
#import "git2/errors.h" | ||
#import "git2/notes.h" | ||
|
||
@interface GTNote () | ||
{ | ||
git_note *_note; | ||
} | ||
|
||
@end | ||
@implementation GTNote | ||
|
||
- (NSString *)description { | ||
return [NSString stringWithFormat:@"<%@: %p>", NSStringFromClass([self class]), self]; | ||
} | ||
|
||
#pragma mark API | ||
|
||
- (void)dealloc { | ||
if (_note != NULL) { | ||
git_note_free(_note); | ||
} | ||
} | ||
|
||
- (git_note *)git_note { | ||
return _note; | ||
} | ||
|
||
- (NSString *)note { | ||
return @(git_note_message(self.git_note)); | ||
} | ||
|
||
- (GTSignature *)author { | ||
return [[GTSignature alloc] initWithGitSignature:git_note_author(self.git_note)]; | ||
} | ||
|
||
- (GTSignature *)committer { | ||
return [[GTSignature alloc] initWithGitSignature:git_note_committer(self.git_note)]; | ||
} | ||
|
||
- (GTOID *)targetOID { | ||
return [GTOID oidWithGitOid:git_note_id(self.git_note)]; | ||
} | ||
|
||
- (instancetype)initWithTargetOID:(GTOID *)oid repository:(GTRepository *)repository referenceName:(NSString *)referenceName error:(NSError **)error { | ||
return [self initWithTargetGitOID:(git_oid *)oid.git_oid repository:repository.git_repository referenceName:referenceName.UTF8String error:error]; | ||
} | ||
|
||
- (instancetype)initWithTargetGitOID:(git_oid *)oid repository:(git_repository *)repository referenceName:(const char *)referenceName error:(NSError **)error { | ||
self = [super init]; | ||
if (self == nil) return nil; | ||
|
||
int gitErr = git_note_read(&_note, repository, referenceName, oid); | ||
|
||
if (gitErr != GIT_OK) { | ||
if (error != NULL) *error = [NSError git_errorFor:gitErr description:@"Unable to read note"]; | ||
return nil; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (instancetype)init { | ||
NSAssert(NO, @"Call to an unavailable initializer."); | ||
return nil; | ||
} | ||
|
||
+ (NSString *)defaultReferenceNameForRepository:(GTRepository *)repository error:(NSError **)error { | ||
NSString *noteRef = nil; | ||
|
||
git_buf default_ref_name = { 0 }; | ||
int gitErr = git_note_default_ref(&default_ref_name, repository.git_repository); | ||
if (gitErr != GIT_OK) { | ||
if (error != NULL) *error = [NSError git_errorFor:gitErr description:@"Unable to get default git notes reference name"]; | ||
return nil; | ||
} | ||
|
||
if (default_ref_name.ptr != NULL) { | ||
noteRef = @(default_ref_name.ptr); | ||
} else { | ||
if (error != NULL) *error = [NSError git_errorFor:GIT_ERROR description:@"Unable to get default git notes reference name"]; | ||
} | ||
|
||
git_buf_free(&default_ref_name); | ||
|
||
return noteRef; | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/GIT_ERROR/gitErr
.GIT_ERROR
is one of libgit2 error classes, not the error code returned bygit_note_default_ref
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if gitErr is not GIT_OK, then it would return that error earlier. If we got to that point when
git_note_default_ref
returnedGIT_OK
, butdefault_ref_name.ptr
isNULL
for some reason, then I am generating a genericGIT_ERROR
. I know in reality it shouldn't happen, but I am being just extra cautious here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I got confused. Normally you would have to go through the hassle of setting up an
NSError
manually, but since those cases are scarce in the codebase, I'm not against reusingGIT_ERROR
then.