-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #576 from slavikus/git-notes
Git notes
- Loading branch information
Showing
12 changed files
with
478 additions
and
5 deletions.
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.