This repository was archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathindexer.hpp
More file actions
132 lines (102 loc) · 3.92 KB
/
Copy pathindexer.hpp
File metadata and controls
132 lines (102 loc) · 3.92 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#pragma once
#include <cppgit2/libgit2_api.hpp>
#include <cppgit2/odb.hpp>
#include <cppgit2/oid.hpp>
#include <cppgit2/ownership.hpp>
#include <functional>
#include <git2.h>
namespace cppgit2 {
class indexer : public libgit2_api {
public:
// Default construct an indexer
indexer();
// Construct from libgit2 C ptr
indexer(git_indexer *c_ptr, ownership owner);
// Free indexer if owned by user
~indexer();
// This structure is used to provide callers information about the progress of
// indexing a packfile, either directly or part of a fetch or clone that
// downloads a packfile.
class progress : public libgit2_api {
public:
// Default construct progress
progress() : c_ptr_(nullptr) { c_ptr_ = &default_; }
// Construct from libgit2 C ptr
progress(const git_indexer_progress *c_ptr) : c_ptr_(c_ptr) {}
// number of objects in the packfile being indexed
unsigned long total_objects() const { return c_ptr_->total_objects; }
// received objects that have been hashed
unsigned long indexer_objects() const { return c_ptr_->indexed_objects; }
// received_objects: objects which have been downloaded
unsigned long received_objects() const { return c_ptr_->received_objects; }
// locally-available objects that have been injected in order to fix a thin
// pack
unsigned long local_objects() const { return c_ptr_->local_objects; }
// number of deltas in the packfile being indexed
unsigned long total_deltas() const { return c_ptr_->total_deltas; }
// received deltas that have been indexed
unsigned long indexed_deltas() const { return c_ptr_->indexed_deltas; }
// size of the packfile received up to now
size_t received_bytes() const { return c_ptr_->received_bytes; }
const git_indexer_progress *c_ptr() const { return c_ptr_; }
private:
friend indexer;
const git_indexer_progress *c_ptr_;
git_indexer_progress default_;
};
// Add data to the indexer
void append(void *data, size_t size);
// Finalize the pack and index
// Resolve any pending deltas and write out the index file
void commit();
// Get the packfile's hash
// A packfile's name is derived from the sorted hashing of
// all object names. This is only correct after the index
// has been finalized.
oid hash();
class options : public libgit2_api {
public:
options() {
auto ret = git_indexer_init_options(&default_options_,
GIT_INDEXER_OPTIONS_VERSION);
c_ptr_ = &default_options_;
if (ret != 0)
throw git_exception();
}
options(git_indexer_options *c_ptr) : c_ptr_(c_ptr) {}
// Version
unsigned int version() const { return c_ptr_->version; }
void set_version(unsigned int value) { c_ptr_->version = value; }
// Indexer Progress callback
void set_indexer_progress_callback(
std::function<void(const indexer::progress &progress)> callback) {
struct visitor_wrapper {
std::function<void(const indexer::progress &progress)> fn;
};
visitor_wrapper wrapper;
wrapper.fn = callback;
c_ptr_->progress_cb = [](const git_indexer_progress *stats,
void *payload) {
auto wrapper = reinterpret_cast<visitor_wrapper *>(payload);
wrapper->fn(indexer::progress(stats));
return 0;
};
}
// Do connectivity checks for the received pack
unsigned char verify() const { return c_ptr_->verify; }
const git_indexer_options *c_ptr() const { return c_ptr_; }
private:
friend indexer;
git_indexer_options *c_ptr_;
git_indexer_options default_options_;
};
// Create a new indexer instance
indexer(const std::string &path, unsigned int mode, const odb &odb,
const indexer::options &options = indexer::options());
private:
friend class repository;
progress progress_; // stat storage
ownership owner_;
git_indexer *c_ptr_;
};
} // namespace cppgit2