-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathobject.cpp
More file actions
75 lines (62 loc) · 1.57 KB
/
Copy pathobject.cpp
File metadata and controls
75 lines (62 loc) · 1.57 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
73
74
75
#include "git2cpp/object.h"
#include "git2cpp/blob.h"
#include "git2cpp/commit.h"
#include "git2cpp/tree.h"
#include "git2cpp/tag.h"
#include <cassert>
#include <git2/object.h>
namespace git
{
Object::Object(git_object * obj, Repository const & repo)
: obj_(obj)
, repo_(&repo)
{
}
void Object::Destroy::operator()(git_object* obj) const
{
git_object_free(obj);
}
git_object_t Object::type() const
{
return git_object_type(obj_.get());
}
git_oid const & Object::id() const
{
return *git_object_id(obj_.get());
}
#define DEFINE_METHOD_AS(type_name, enum_element) \
git_##type_name * Object::as_##type_name() \
{ \
assert(type() == GIT_OBJECT_##enum_element); \
return reinterpret_cast<git_##type_name *>(obj_.get()); \
}
DEFINE_METHOD_AS(blob, BLOB)
DEFINE_METHOD_AS(commit, COMMIT)
DEFINE_METHOD_AS(tree, TREE)
DEFINE_METHOD_AS(tag, TAG)
#undef DEFINE_METHOD_AS
Tree Object::to_tree() /*&&*/
{
Tree res(as_tree(), *repo_);
obj_ = nullptr;
return res;
}
Commit Object::to_commit() /*&&*/
{
Commit res(as_commit(), *repo_);
obj_ = nullptr;
return res;
}
Blob Object::to_blob() /*&&*/
{
Blob res(as_blob());
obj_ = nullptr;
return res;
}
Tag Object::to_tag() /*&&*/
{
Tag res(as_tag());
obj_ = nullptr;
return res;
}
}