1 module git.object_; 2 3 import git.oid; 4 import git.repository; 5 import git.types; 6 import git.util; 7 8 import deimos.git2.object_; 9 import deimos.git2.types; 10 11 // Note: This file includes none of the original comments, as they might 12 // be copyrightable material. 13 14 /// 15 struct GitObject 16 { 17 // Internal, see free-standing constructor functions below. 18 package this(GitRepo repo, git_object* obj) 19 { 20 _repo = repo; 21 _data = Data(obj); 22 } 23 24 /// 25 @property GitOid id() 26 { 27 return GitOid(*git_object_id(_data._payload)); 28 } 29 30 /// 31 @property GitType type() 32 { 33 return cast(GitType)git_object_type(_data._payload); 34 } 35 36 /// 37 @property inout(GitRepo) owner() inout { return _repo; } 38 39 /// 40 @property GitObject dup() 41 { 42 git_object* result; 43 require(git_object_dup(&result, _data._payload) == 0); 44 return GitObject(_repo, result); 45 } 46 47 /// 48 @property GitObject peel(GitType targetType) 49 { 50 git_object* result; 51 require(git_object_peel(&result, _data._payload, cast(git_otype)targetType) == 0); 52 return GitObject(_repo, result); 53 } 54 55 mixin RefCountedGitObject!(git_object, git_object_free); 56 // Reference to the parent repository to keep it alive. 57 private GitRepo _repo; 58 } 59 60 /// 61 GitObject lookupObject(GitRepo repo, GitOid oid, GitType type = GitType.any) 62 { 63 git_object* result; 64 auto cOid = oid._get_oid; 65 require(git_object_lookup(&result, repo.cHandle, &cOid, cast(git_otype)type) == 0); 66 return GitObject(repo, result); 67 } 68 69 /// 70 GitObject lookupObjectPrefix(GitRepo repo, GitOid oid, size_t prefixLen, GitType type = GitType.any) 71 { 72 git_object* result; 73 auto cOid = oid._get_oid; 74 require(git_object_lookup(&result, repo.cHandle, &cOid, cast(git_otype)type) == 0); 75 return GitObject(repo, result); 76 } 77 78 /// 79 GitObject lookupObject(GitRepo repo, in char[] hexString, GitType type = GitType.any) 80 { 81 auto oid = GitOid(hexString); 82 if (hexString.length < GitOid.MaxHexSize) 83 { 84 return lookupObjectPrefix(repo, oid, hexString.length, type); 85 } 86 else 87 { 88 return lookupObject(repo, oid, type); 89 } 90 } 91 92 deprecated("Please use lookupObject instead.") alias lookup = lookupObject; 93 deprecated("Please use lookupObjectPrefix instead.") alias lookupByPrefix = lookupObjectPrefix; 94 95 /// 96 const(char)[] toString(GitType type) 97 { 98 return git_object_type2string(cast(git_otype)type).toSlice; 99 } 100 101 /// 102 GitType toType(in char[] str) 103 { 104 return cast(GitType)git_object_string2type(str.gitStr); 105 } 106 107 /// 108 bool isLoose(GitType type) 109 { 110 return git_object_typeisloose(cast(git_otype)type) != 0; 111 } 112 113 /+ 114 extern (C): 115 size_t git_object__size(git_otype type); 116 +/