-
Notifications
You must be signed in to change notification settings - Fork 2
/
git-githubfs.h
82 lines (66 loc) · 2.22 KB
/
git-githubfs.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef GIT_GITHUBFS_H_
#define GIT_GITHUBFS_H_
#include <mutex>
#include <unordered_map>
#include "cached_file.h"
#include "directory_container.h"
#include "disallow.h"
namespace githubfs {
enum class GitFileType { blob, tree, commit };
// Github api v3 response parsers.
// Parse tree content.
bool ParseTrees(
const std::string& trees_string,
std::function<void(const std::string& path, int mode,
const GitFileType type, const std::string& sha,
const int size, const std::string& url)>
file_handler);
// Parse github commits list and return the tree hash.
// for /commits endpoint.
std::string ParseCommits(const std::string& commits_string);
// for /commits/hash endpoint.
std::string ParseCommit(const std::string& commit_string);
// Parse blob.
std::string ParseBlob(const std::string& blob_string);
class GitTree;
struct FileElement : public directory_container::File {
public:
FileElement(int attribute, const std::string& sha1, int size,
GitTree* parent);
virtual int Open() override;
virtual ssize_t Read(char* buf, size_t size, off_t offset) override;
virtual ssize_t Readlink(char* buf, size_t size) override;
virtual int Getattr(struct stat* stbuf) override;
virtual int Release() override;
private:
ssize_t maybe_cat_file_locked();
int attribute_;
std::string sha1_;
int size_;
GitTree* parent_;
const Cache::Memory* memory_{};
std::mutex buf_mutex_{};
DISALLOW_COPY_AND_ASSIGN(FileElement);
};
class GitTree {
public:
GitTree(const char* hash, const char* github_api_prefix,
directory_container::DirectoryContainer* c,
const std::string& cache_dir);
~GitTree();
const std::string& get_github_api_prefix() const {
return github_api_prefix_;
}
Cache& cache() { return cache_; }
private:
void LoadDirectoryInternal(const std::string& subdir,
const std::string& tree_hash, bool remote_recurse);
// Directory for git directory. Needed because fuse chdir to / on
// becoming a daemon.
const std::string github_api_prefix_;
directory_container::DirectoryContainer* container_;
Cache cache_;
DISALLOW_COPY_AND_ASSIGN(GitTree);
};
} // namespace githubfs
#endif