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
#ifndef OBJECT_IO_H
#define OBJECT_IO_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <time.h>
#include "transport.h"
void *read_object(const object_hash_t hash, object_type_t *type, size_t *length);
typedef struct {
object_hash_t tree_hash;
size_t parents;
object_hash_t *parent_hashes;
char *author;
time_t author_time;
char *committer;
time_t commit_time;
char *message;
} commit_t;
commit_t *read_commit(const object_hash_t hash);
void free_commit(commit_t *);
typedef enum {
MODE_DIRECTORY = 0040000,
MODE_FILE = 0100644,
MODE_EXECUTABLE = 0100755,
MODE_SYMLINK = 0120000
} file_mode_t;
typedef struct {
file_mode_t mode;
char *name; // file or directory name
object_hash_t hash; // blob (for files) or tree (for directories)
} tree_entry_t;
typedef struct {
size_t entry_count;
tree_entry_t *entries;
} tree_t;
tree_t *read_tree(const object_hash_t hash);
void free_tree(tree_t *);
typedef struct {
size_t length;
uint8_t *contents;
} blob_t;
blob_t *read_blob(const object_hash_t hash);
void free_blob(blob_t *);
void apply_ref_delta(
const object_hash_t base_hash,
const uint8_t *data,
size_t length,
object_hash_t hash
);
void write_object(
object_type_t type,
const void *contents,
size_t length,
object_hash_t hash
);
#endif // #ifndef OBJECT_IO_H