-
Notifications
You must be signed in to change notification settings - Fork 2
/
git_cat_file.h
60 lines (47 loc) · 1.34 KB
/
git_cat_file.h
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
#ifndef GIT_CAT_FILE_H
#define GIT_CAT_FILE_H
#include <mutex>
#include <string>
#include <vector>
#include "disallow.h"
#include "scoped_fd.h"
namespace GitCatFile {
// Metadata for response from git-cat-file daemon.
class GitCatFileMetadata {
public:
explicit GitCatFileMetadata(const std::string& header);
~GitCatFileMetadata();
// The header size, including the terminating newline.
int first_line_size_{-1};
// The size of the message content.
int size_{-1};
std::string sha1_{};
std::string type_{};
};
// Internal utility class for bidirectional pipe for daemon process.
class BidirectionalPopen {
public:
BidirectionalPopen(const std::vector<std::string>& command,
const std::string* cwd);
~BidirectionalPopen();
void Write(const std::string& s) const;
std::string Read(int max_size) const;
private:
ScopedFd read_fd_{-1};
ScopedFd write_fd_{-1};
pid_t pid_{-1};
DISALLOW_COPY_AND_ASSIGN(BidirectionalPopen);
};
class GitCatFileProcess {
public:
explicit GitCatFileProcess(const std::string* cwd);
GitCatFileProcess(const std::string& cwd, const std::string& ssh);
~GitCatFileProcess();
std::string Request(const std::string& ref) const;
struct ObjectNotFoundException {};
private:
const BidirectionalPopen process_;
mutable std::mutex m_;
};
} // namespace GitCatFile
#endif