-
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
Git notes #576
Changes from 12 commits
abc1d74
41279e4
0871b0e
47dc0fc
fe13986
6df9faf
947058d
e99a62e
b64f024
0661bab
c27e838
73037a4
75e5356
16ef587
2352543
6e96e11
6228da7
2fea0a5
5bf9d5f
f4a1103
55898a7
16f980f
927cc49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// | ||
// 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") | ||
/// error - Will be filled with a git error code in case of error. | ||
/// May be NULL. | ||
/// | ||
/// Returns initialized GTNote instance or nil on failure (error will be populated, if passed). | ||
- (nullable instancetype)initWithTargetGitOID:(git_oid *)oid repository:(git_repository *)repository referenceName:(const char * _Nullable)referenceName error:(int * _Nullable)error; | ||
|
||
- (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"). | ||
+ (NSString *)defaultReferenceNameForRepository:(GTRepository *)repository error:(NSError **)error; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// | ||
// 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 { | ||
int err = GIT_OK; | ||
|
||
id object = [self initWithTargetGitOID:(git_oid *)oid.git_oid repository:repository.git_repository referenceName:referenceName.UTF8String error:&err]; | ||
|
||
if (err != GIT_OK && error != NULL) { | ||
*error = [NSError git_errorFor:err description:@"Failed to create a note."]; | ||
} | ||
|
||
return object; | ||
} | ||
|
||
- (instancetype)initWithTargetGitOID:(git_oid *)oid repository:(git_repository *)repository referenceName:(const char *)referenceName error:(int *)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 = gitErr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I do not think it works that way 😉. Actually, it does. Can you make it less "unexpected" ? As in, not using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the error altogether. In all other parts of the framework initializers that take libgit2 pointers never return the error, only |
||
|
||
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) { | ||
git_buf_free(&default_ref_name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you can get both an error and a pointer to free ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Who knows? After all, if it failed filling a pointer, |
||
|
||
if (error != NULL) { | ||
*error = [NSError git_errorFor:gitErr description:@"Unable to get default git notes reference name"]; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: whitespace. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm blind. What's wrong with the whitespace above? Triple checked and don't see anything wrong. :\ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I meant the newline is unwarranted. |
||
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 |
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.
Error message says "create" but method works as "read".