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 pathpack_builder.hpp
More file actions
86 lines (65 loc) · 2.52 KB
/
Copy pathpack_builder.hpp
File metadata and controls
86 lines (65 loc) · 2.52 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
#pragma once
#include <cppgit2/data_buffer.hpp>
#include <cppgit2/indexer.hpp>
#include <cppgit2/libgit2_api.hpp>
#include <cppgit2/oid.hpp>
#include <cppgit2/ownership.hpp>
#include <cppgit2/revwalk.hpp>
#include <functional>
#include <git2.h>
#include <string>
namespace cppgit2 {
class pack_builder : public libgit2_api {
public:
// Default construct a pack_builder
pack_builder();
// Construct from libgit2 C ptr
pack_builder(git_packbuilder *c_ptr, ownership owner);
// Free packbuilder ptr if owned by user
~pack_builder();
// Create the new pack and pass each object to the callback
void for_each_object(
std::function<void(void *object_data, size_t object_size)> visitor);
// 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 packfile has been written.
oid hash();
// Get the packfile's hash
oid id() const;
// Insert a commit object
void insert_commit(const oid &commit_id);
// Insert a single object
// For an optimal pack it's mandatory to insert objects in recency order,
// commits followed by trees and blobs.
void insert_object(const oid &commit_id, const std::string &name = "");
// Recursively insert an object and its referenced objects
// Insert the object as well as any object it references
void insert_object_recursively(const oid &commit_id,
const std::string &name = "");
// Insert a tree object
// This will add the tree as well as all referenced trees and blobs
void insert_tree(const oid &tree_id);
// Insert objects as given by the walk
void insert_revwalk(const revwalk &walk);
// Get the total number of objects the packbuilder will write out
size_t size() const;
// Set the callbacks for a packbuilder
void
set_progress_callback(std::function<void(int, uint32_t, uint32_t)> callback);
// Set number of threads to spawn
void set_threads(unsigned int num_threads);
// Write the new pack and corresponding index file to path.
void write(const std::string &path, unsigned int mode,
std::function<void(const indexer::progress &)> &progress_callback);
// Write the contents of the packfile to an in-memory buffer
data_buffer write_to_buffer();
// Get the number of objects the packbuilder has already written out
size_t written() const;
// Access libgit2 C ptr
const git_packbuilder *c_ptr() const;
private:
friend class repository;
git_packbuilder *c_ptr_;
ownership owner_;
};
} // namespace cppgit2