-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.h
More file actions
169 lines (138 loc) · 5.91 KB
/
storage.h
File metadata and controls
169 lines (138 loc) · 5.91 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#ifndef STORAGE_H
#define STORAGE_H
#include <stdio.h>
#ifndef SQLITE_CORE
#include "sqlite3ext.h"
#else
#include <sqlite3.h>
#endif
#include <git2.h>
/*
* Open (or create) the sqlite.db in the given directory.
* If path ends with /objects, strips it to find the gitdir root.
*/
int storage_open(const char *path_arg);
/*
* Use an existing database connection for storage.
* If persistent is true, prepared statements are cached for the
* lifetime of the connection (caller must call storage_close or
* use sqlite3_close_v2). If false, statements are prepared and
* finalized per call (safe with sqlite3_close v1).
*/
int storage_open_db(sqlite3 *db, int persistent);
void storage_close(void);
void storage_refresh(void);
void storage_destroy(void);
sqlite3 *storage_db(void);
/* Transaction control */
void storage_begin(void);
void storage_commit(void);
void storage_savepoint(const char *name);
void storage_release(const char *name);
void storage_rollback_to(const char *name);
/*
* Object operations. OIDs are git_oid (binary 20 bytes).
* Read resolves delta chains. Write handles compression + delta.
* Caller must free *out_data from read.
*/
int storage_read_object(const git_oid *oid,
git_object_t *out_type, size_t *out_size,
unsigned char **out_data);
void storage_write_object(const git_oid *oid, git_object_t type,
const void *data, size_t size);
void storage_write_object_named(const git_oid *oid, git_object_t type,
const void *data, size_t size,
const char *path);
int storage_object_exists(const git_oid *oid);
/*
* Ref operations. OIDs stored as BLOB(20) internally.
*/
int storage_ref_read(const char *refname, git_oid *oid, char *symref, size_t symref_len);
void storage_ref_write(const char *refname, const git_oid *oid, const char *symref);
void storage_ref_delete(const char *refname);
/* Callback for ref iteration. Return non-zero to stop. */
typedef int (*storage_ref_cb)(const char *refname, const git_oid *oid,
const char *symref, void *data);
int storage_ref_list(const char *prefix, storage_ref_cb cb, void *data);
/* Object listing callback. */
typedef int (*storage_obj_cb)(const git_oid *oid, git_object_t type,
size_t size, void *data);
int storage_obj_list(storage_obj_cb cb, void *data);
/* OID-only iteration (no type/size overhead) */
int storage_obj_oids(git_odb_foreach_cb cb, void *data);
int storage_obj_list_filtered(int promisor_only, int skip_kept,
storage_obj_cb cb, void *data);
/* Kept/promisor object metadata */
void storage_mark_kept(const git_oid *oid);
void storage_mark_kept_recent(void);
void storage_end_kept_batch(void);
void storage_clear_kept(void);
int storage_have_kept(const git_oid *oid);
void storage_mark_promisor(const git_oid *oid);
void storage_mark_promisor_recent(void);
void storage_end_promisor_batch(void);
/* OID mapping for hash algorithm migration */
int storage_convert_oid(const git_oid *src, const char *algo,
git_oid *dest);
void storage_store_oid_map(const git_oid *src, const git_oid *dest,
const char *algo);
/* Packfile ingestion: read a git packfile from stream, store all objects */
int storage_write_packfile(FILE *in);
/* Connectivity verification using libgit2 revwalk */
int storage_check_connectivity(void);
/* GC and repack */
int storage_gc(void);
int storage_repack(void);
/* Reflog operations */
int storage_reflog_exists(const char *refname);
void storage_reflog_delete(const char *refname);
/* Reflog read callback */
typedef int (*storage_reflog_cb)(const git_oid *old_oid, const git_oid *new_oid,
const char *committer, long long timestamp,
int tz, const char *msg, void *data);
int storage_reflog_read(const char *refname, storage_reflog_cb cb, void *data);
int storage_reflog_read_reverse(const char *refname, storage_reflog_cb cb, void *data);
/* Reflog name listing callback. */
typedef int (*storage_reflog_name_cb)(const char *refname, void *data);
int storage_reflog_list(storage_reflog_name_cb cb, void *data);
void storage_reflog_append(const char *refname, const git_oid *old_oid,
const git_oid *new_oid, const char *committer,
long long timestamp, int tz, const char *msg);
/* Partial clone: promised objects and promisor remotes */
void storage_promise_object(const git_oid *oid, const char *remote);
int storage_is_promised(const git_oid *oid);
int storage_fetch_promised(const git_oid *oid);
void storage_add_promisor_remote(const char *name, const char *url);
void storage_remove_promisor_remote(const char *name);
/* Commit graph: generation numbers and commit timestamps */
int storage_build_commit_graph(void);
int storage_commit_generation(const git_oid *oid);
/* Worktree support */
void storage_worktree_add(const char *name, const char *path, const char *branch);
void storage_worktree_remove(const char *name);
typedef int (*storage_worktree_cb)(const char *name, const char *path,
const char *head_ref, void *data);
int storage_worktree_list(storage_worktree_cb cb, void *data);
/* Alternates: borrow objects from other sqlite.db files */
void storage_alternate_add(const char *path);
void storage_alternate_remove(const char *path);
typedef int (*storage_alternate_cb)(const char *path, void *data);
int storage_alternate_list(storage_alternate_cb cb, void *data);
/*
* LFS content storage. OID is SHA-256 (32 bytes) per git-lfs spec.
* Data is zlib compressed.
*/
#define LFS_OID_RAWSZ 32
#define LFS_OID_HEXSZ 64
void storage_lfs_sha256(const void *data, size_t len,
unsigned char out[LFS_OID_RAWSZ]);
void storage_lfs_oid_to_hex(const unsigned char oid[LFS_OID_RAWSZ],
char hex[LFS_OID_HEXSZ + 1]);
int storage_lfs_oid_from_hex(const char *hex,
unsigned char oid[LFS_OID_RAWSZ]);
int storage_lfs_read(const unsigned char oid[LFS_OID_RAWSZ],
size_t *out_size, unsigned char **out_data);
void storage_lfs_write(const unsigned char oid[LFS_OID_RAWSZ],
const void *data, size_t size);
int storage_lfs_exists(const unsigned char oid[LFS_OID_RAWSZ]);
#endif