forked from p-ranav/cppgit2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.hpp
More file actions
96 lines (72 loc) · 2.18 KB
/
Copy pathobject.hpp
File metadata and controls
96 lines (72 loc) · 2.18 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#pragma once
#include <git2.h>
#include <cppgit2/git_exception.hpp>
#include <cppgit2/libgit2_api.hpp>
#include <cppgit2/oid.hpp>
#include <cppgit2/ownership.hpp>
namespace cppgit2 {
class object : public libgit2_api {
public:
// Default construct a git object
object();
// Construct from libgit2 C ptr
object(git_object* c_ptr, ownership owner_ = ownership::libgit2);
// Free git object if owned by user
~object();
// SHA1 hash of this object
oid id() const;
// Short abbreviated OID string of this object
std::string short_id() const;
// Clone this object
object copy() const;
// Basic type (loose or packed) of any git object
enum class object_type {
any = -2,
invalid = -1,
commit = 1,
tree = 2,
blob = 3,
tag = 4,
ofs_delta = 6,
ref_delta = 7
};
// object tyoe to string
static std::string object_type_to_string(object_type type);
using object_size = git_object_size_t;
// Recursively peel until an object of the specified type is met
object peel_until(object_type target);
// Type of this git object
object_type type() const;
// Type of this git object - as string
std::string type_string() const;
// Convert a string object type to object_type
static object_type type_from_string(const std::string& type_string);
// Convert an object type to string representation
static std::string string_from_type(object_type type);
// Determine if the given type is a valid loose object type
static bool is_type_loose(object_type type);
// Get owner repository
class repository owner() const;
// Cast to blob
// Throws git_exception if object is not a blob
class blob as_blob();
// Cast to commit
// Throws git_exception if object is not a commit
class commit as_commit();
// Cast to tree
// Throws git_exception if object is not a tree
class tree as_tree();
// Cast to tag
// Throws git_exception if object is not a tag
class tag as_tag();
// Access libgit2 C ptr
const git_object* c_ptr() const { return c_ptr_; }
private:
friend class reference;
friend class repository;
friend class revspec;
friend class tag;
ownership owner_;
git_object* c_ptr_;
};
} // namespace cppgit2