-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathGTOdbObject.m
More file actions
72 lines (54 loc) · 1.49 KB
/
GTOdbObject.m
File metadata and controls
72 lines (54 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// GTOdbObject.m
// ObjectiveGitFramework
//
// Created by Timothy Clem on 3/23/11.
// Copyright 2011 GitHub, Inc. All rights reserved.
//
#import "GTOdbObject.h"
#import "NSString+Git.h"
#import "GTOID.h"
#import <git2/odb.h>
@interface GTOdbObject ()
@property (nonatomic, assign, readonly) git_odb_object *git_odb_object;
@end
@implementation GTOdbObject
- (void)dealloc {
if (_git_odb_object != NULL) {
git_odb_object_free(_git_odb_object);
_git_odb_object = NULL;
}
}
- (NSString *)description {
return [NSString stringWithFormat:@"<%@: %p> shaHash: %@, length: %zi, data: %@", NSStringFromClass([self class]), self, [self shaHash], [self length], [self data]];
}
#pragma mark API
- (instancetype)init {
NSAssert(NO, @"Call to an unavailable initializer.");
return nil;
}
- (instancetype)initWithOdbObj:(git_odb_object *)object repository:(GTRepository *)repository {
NSParameterAssert(object != NULL);
NSParameterAssert(repository != nil);
self = [super init];
if (self == nil) return nil;
_git_odb_object = object;
_repository = repository;
return self;
}
- (NSString *)shaHash {
return self.OID.SHA;
}
- (GTObjectType)type {
return (GTObjectType) git_odb_object_type(self.git_odb_object);
}
- (size_t)length {
return git_odb_object_size(self.git_odb_object);
}
- (NSData *)data {
return [NSData dataWithBytes:git_odb_object_data(self.git_odb_object) length:self.length];
}
- (GTOID *)OID {
return [GTOID oidWithGitOid:git_odb_object_id(self.git_odb_object)];
}
@end