]>
Commit | Line | Data |
---|---|---|
f5918330 | 1 | /* |
359fc2d2 | 2 | * Copyright (C) the libgit2 contributors. All rights reserved. |
f5918330 | 3 | * |
bb742ede VM |
4 | * This file is part of libgit2, distributed under the GNU GPL v2 with |
5 | * a Linking Exception. For full terms see the included COPYING file. | |
f5918330 | 6 | */ |
d12299fe VM |
7 | #ifndef INCLUDE_git_odb_backend_h__ |
8 | #define INCLUDE_git_odb_backend_h__ | |
9 | ||
f313843c JJ |
10 | #include "common.h" |
11 | #include "types.h" | |
22a2d3d5 | 12 | #include "indexer.h" |
d12299fe | 13 | |
f5918330 VM |
14 | /** |
15 | * @file git2/backend.h | |
16 | * @brief Git custom backend functions | |
83cc70d9 | 17 | * @defgroup git_odb Git object database routines |
f5918330 VM |
18 | * @ingroup Git |
19 | * @{ | |
20 | */ | |
d12299fe VM |
21 | GIT_BEGIN_DECL |
22 | ||
9a9de29d | 23 | /* |
83cc70d9 | 24 | * Constructors for in-box ODB backends. |
c3fb7d04 | 25 | */ |
9a9de29d CMN |
26 | |
27 | /** | |
28 | * Create a backend for the packfiles. | |
29 | * | |
30 | * @param out location to store the odb backend pointer | |
31 | * @param objects_dir the Git repository's objects directory | |
32 | * | |
33 | * @return 0 or an error code | |
34 | */ | |
83cc70d9 | 35 | GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_dir); |
9a9de29d CMN |
36 | |
37 | /** | |
38 | * Create a backend for loose objects | |
39 | * | |
40 | * @param out location to store the odb backend pointer | |
41 | * @param objects_dir the Git repository's objects directory | |
42 | * @param compression_level zlib compression level to use | |
fc27fe21 | 43 | * @param do_fsync whether to do an fsync() after writing |
dd64c71c ET |
44 | * @param dir_mode permissions to use creating a directory or 0 for defaults |
45 | * @param file_mode permissions to use creating a file or 0 for defaults | |
9a9de29d CMN |
46 | * |
47 | * @return 0 or an error code | |
48 | */ | |
dd64c71c ET |
49 | GIT_EXTERN(int) git_odb_backend_loose( |
50 | git_odb_backend **out, | |
51 | const char *objects_dir, | |
52 | int compression_level, | |
53 | int do_fsync, | |
f966acd1 ET |
54 | unsigned int dir_mode, |
55 | unsigned int file_mode); | |
9a9de29d CMN |
56 | |
57 | /** | |
58 | * Create a backend out of a single packfile | |
59 | * | |
60 | * This can be useful for inspecting the contents of a single | |
61 | * packfile. | |
62 | * | |
63 | * @param out location to store the odb backend pointer | |
64 | * @param index_file path to the packfile's .idx file | |
65 | * | |
66 | * @return 0 or an error code | |
67 | */ | |
83cc70d9 | 68 | GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *index_file); |
bde336ea | 69 | |
2e2e9785 | 70 | /** Streaming mode */ |
0f1f9833 | 71 | typedef enum { |
2e2e9785 VM |
72 | GIT_STREAM_RDONLY = (1 << 1), |
73 | GIT_STREAM_WRONLY = (1 << 2), | |
e579e0f7 | 74 | GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY) |
0f1f9833 | 75 | } git_odb_stream_t; |
2e2e9785 | 76 | |
7a3764be CMN |
77 | /** |
78 | * A stream to read/write from a backend. | |
79 | * | |
80 | * This represents a stream of data being written to or read from a | |
81 | * backend. When writing, the frontend functions take care of | |
82 | * calculating the object's id and all `finalize_write` needs to do is | |
83 | * store the object with the id it is passed. | |
84 | */ | |
72a3fe42 | 85 | struct git_odb_stream { |
83cc70d9 | 86 | git_odb_backend *backend; |
0ed67c1c | 87 | unsigned int mode; |
67c177ef | 88 | void *hash_ctx; |
72a3fe42 | 89 | |
22a2d3d5 UG |
90 | git_object_size_t declared_size; |
91 | git_object_size_t received_bytes; | |
031f3f80 | 92 | |
7a3764be | 93 | /** |
4dfe3820 | 94 | * Write at most `len` bytes into `buffer` and advance the stream. |
7a3764be | 95 | */ |
ac3d33df | 96 | int GIT_CALLBACK(read)(git_odb_stream *stream, char *buffer, size_t len); |
7a3764be CMN |
97 | |
98 | /** | |
99 | * Write `len` bytes from `buffer` into the stream. | |
100 | */ | |
ac3d33df | 101 | int GIT_CALLBACK(write)(git_odb_stream *stream, const char *buffer, size_t len); |
7a3764be CMN |
102 | |
103 | /** | |
104 | * Store the contents of the stream as an object with the id | |
105 | * specified in `oid`. | |
4047950f | 106 | * |
4dfe3820 RB |
107 | * This method might not be invoked if: |
108 | * - an error occurs earlier with the `write` callback, | |
109 | * - the object referred to by `oid` already exists in any backend, or | |
110 | * - the final number of received bytes differs from the size declared | |
111 | * with `git_odb_open_wstream()` | |
7a3764be | 112 | */ |
ac3d33df | 113 | int GIT_CALLBACK(finalize_write)(git_odb_stream *stream, const git_oid *oid); |
7a3764be CMN |
114 | |
115 | /** | |
116 | * Free the stream's memory. | |
4dfe3820 RB |
117 | * |
118 | * This method might be called without a call to `finalize_write` if | |
119 | * an error occurs or if the object is already present in the ODB. | |
7a3764be | 120 | */ |
ac3d33df | 121 | void GIT_CALLBACK(free)(git_odb_stream *stream); |
72a3fe42 VM |
122 | }; |
123 | ||
09cc0b92 ET |
124 | /** A stream to write a pack file to the ODB */ |
125 | struct git_odb_writepack { | |
83cc70d9 | 126 | git_odb_backend *backend; |
09cc0b92 | 127 | |
22a2d3d5 UG |
128 | int GIT_CALLBACK(append)(git_odb_writepack *writepack, const void *data, size_t size, git_indexer_progress *stats); |
129 | int GIT_CALLBACK(commit)(git_odb_writepack *writepack, git_indexer_progress *stats); | |
ac3d33df | 130 | void GIT_CALLBACK(free)(git_odb_writepack *writepack); |
09cc0b92 ET |
131 | }; |
132 | ||
d12299fe VM |
133 | GIT_END_DECL |
134 | ||
135 | #endif |