1 /*
2  * Copyright (C) the libgit2 contributors. All rights reserved.
3  *
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.
6  */
7 module libgit2_d.odb_backend;
8 
9 
10 private static import libgit2_d.indexer;
11 private static import libgit2_d.oid;
12 private static import libgit2_d.types;
13 
14 /**
15  * @file git2/backend.h
16  * @brief Git custom backend functions
17  * @defgroup git_odb Git object database routines
18  * @ingroup Git
19  * @{
20  */
21 extern (C):
22 nothrow @nogc:
23 public:
24 
25 /*
26  * Constructors for in-box ODB backends.
27  */
28 
29 /**
30  * Create a backend for the packfiles.
31  *
32  * Params:
33  *      out_ = location to store the odb backend pointer
34  *      objects_dir = the Git repository's objects directory
35  *
36  * Returns: 0 or an error code
37  */
38 //GIT_EXTERN
39 int git_odb_backend_pack(libgit2_d.types.git_odb_backend** out_, const (char)* objects_dir);
40 
41 /**
42  * Create a backend for loose objects
43  *
44  * Params:
45  *      out_ = location to store the odb backend pointer
46  *      objects_dir = the Git repository's objects directory
47  *      compression_level = zlib compression level to use
48  *      do_fsync = whether to do an fsync() after writing
49  *      dir_mode = permissions to use creating a directory or 0 for defaults
50  *      file_mode = permissions to use creating a file or 0 for defaults
51  *
52  * Returns: 0 or an error code
53  */
54 //GIT_EXTERN
55 int git_odb_backend_loose(libgit2_d.types.git_odb_backend** out_, const (char)* objects_dir, int compression_level, int do_fsync, uint dir_mode, uint file_mode);
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  * Params:
64  *      out_ = location to store the odb backend pointer
65  *      index_file = path to the packfile's .idx file
66  *
67  * Returns: 0 or an error code
68  */
69 //GIT_EXTERN
70 int git_odb_backend_one_pack(libgit2_d.types.git_odb_backend** out_, const (char)* index_file);
71 
72 /**
73  * Streaming mode
74  */
75 enum git_odb_stream_t
76 {
77 	GIT_STREAM_RDONLY = 1 << 1,
78 	GIT_STREAM_WRONLY = 1 << 2,
79 	GIT_STREAM_RW = GIT_STREAM_RDONLY | GIT_STREAM_WRONLY,
80 }
81 
82 //Declaration name in C language
83 enum
84 {
85 	GIT_STREAM_RDONLY = .git_odb_stream_t.GIT_STREAM_RDONLY,
86 	GIT_STREAM_WRONLY = .git_odb_stream_t.GIT_STREAM_WRONLY,
87 	GIT_STREAM_RW = .git_odb_stream_t.GIT_STREAM_RW,
88 }
89 
90 /**
91  * A stream to read/write from a backend.
92  *
93  * This represents a stream of data being written to or read from a
94  * backend. When writing, the frontend functions take care of
95  * calculating the object's id and all `finalize_write` needs to do is
96  * store the object with the id it is passed.
97  */
98 struct git_odb_stream
99 {
100 	libgit2_d.types.git_odb_backend* backend;
101 	uint mode;
102 	void* hash_ctx;
103 
104 	libgit2_d.types.git_object_size_t declared_size;
105 	libgit2_d.types.git_object_size_t received_bytes;
106 
107 	/**
108 	 * Write at most `len` bytes into `buffer` and advance the stream.
109 	 */
110 	int function(.git_odb_stream* stream, char* buffer, size_t len) read;
111 
112 	/**
113 	 * Write `len` bytes from `buffer` into the stream.
114 	 */
115 	int function(.git_odb_stream* stream, const (char)* buffer, size_t len) write;
116 
117 	/**
118 	 * Store the contents of the stream as an object with the id
119 	 * specified in `oid`.
120 	 *
121 	 * This method might not be invoked if:
122 	 * - an error occurs earlier with the `write` callback,
123 	 * - the object referred to by `oid` already exists in any backend, or
124 	 * - the final number of received bytes differs from the size declared
125 	 *   with `git_odb_open_wstream()`
126 	 */
127 	int function(.git_odb_stream* stream, const (libgit2_d.oid.git_oid)* oid) finalize_write;
128 
129 	/**
130 	 * Free the stream's memory.
131 	 *
132 	 * This method might be called without a call to `finalize_write` if
133 	 * an error occurs or if the object is already present in the ODB.
134 	 */
135 	void function(.git_odb_stream* stream) free;
136 }
137 
138 /**
139  * A stream to write a pack file to the ODB
140  */
141 struct git_odb_writepack
142 {
143 	libgit2_d.types.git_odb_backend* backend;
144 
145 	int function(.git_odb_writepack* writepack, const (void)* data, size_t size, libgit2_d.indexer.git_indexer_progress* stats) append;
146 	int function(.git_odb_writepack* writepack, libgit2_d.indexer.git_indexer_progress* stats) commit;
147 	void function(.git_odb_writepack* writepack) free;
148 }