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 /** 83 * A stream to read/write from a backend. 84 * 85 * This represents a stream of data being written to or read from a 86 * backend. When writing, the frontend functions take care of 87 * calculating the object's id and all `finalize_write` needs to do is 88 * store the object with the id it is passed. 89 */ 90 struct git_odb_stream 91 { 92 libgit2_d.types.git_odb_backend* backend; 93 uint mode; 94 void* hash_ctx; 95 96 libgit2_d.types.git_object_size_t declared_size; 97 libgit2_d.types.git_object_size_t received_bytes; 98 99 /** 100 * Write at most `len` bytes into `buffer` and advance the stream. 101 */ 102 int function(.git_odb_stream* stream, char* buffer, size_t len) read; 103 104 /** 105 * Write `len` bytes from `buffer` into the stream. 106 */ 107 int function(.git_odb_stream* stream, const (char)* buffer, size_t len) write; 108 109 /** 110 * Store the contents of the stream as an object with the id 111 * specified in `oid`. 112 * 113 * This method might not be invoked if: 114 * - an error occurs earlier with the `write` callback, 115 * - the object referred to by `oid` already exists in any backend, or 116 * - the final number of received bytes differs from the size declared 117 * with `git_odb_open_wstream()` 118 */ 119 int function(.git_odb_stream* stream, const (libgit2_d.oid.git_oid)* oid) finalize_write; 120 121 /** 122 * Free the stream's memory. 123 * 124 * This method might be called without a call to `finalize_write` if 125 * an error occurs or if the object is already present in the ODB. 126 */ 127 void function(.git_odb_stream* stream) free; 128 } 129 130 /** 131 * A stream to write a pack file to the ODB 132 */ 133 struct git_odb_writepack 134 { 135 libgit2_d.types.git_odb_backend* backend; 136 137 int function(.git_odb_writepack* writepack, const (void)* data, size_t size, libgit2_d.indexer.git_indexer_progress* stats) append; 138 int function(.git_odb_writepack* writepack, libgit2_d.indexer.git_indexer_progress* stats) commit; 139 void function(.git_odb_writepack* writepack) free; 140 }