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 * @param out_ location to store the odb backend pointer 33 * @param objects_dir the Git repository's objects directory 34 * 35 * @return 0 or an error code 36 */ 37 //GIT_EXTERN 38 int git_odb_backend_pack(libgit2_d.types.git_odb_backend** out_, const (char)* objects_dir); 39 40 /** 41 * Create a backend for loose objects 42 * 43 * @param out_ location to store the odb backend pointer 44 * @param objects_dir the Git repository's objects directory 45 * @param compression_level zlib compression level to use 46 * @param do_fsync whether to do an fsync() after writing 47 * @param dir_mode permissions to use creating a directory or 0 for defaults 48 * @param file_mode permissions to use creating a file or 0 for defaults 49 * 50 * @return 0 or an error code 51 */ 52 //GIT_EXTERN 53 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); 54 55 /** 56 * Create a backend out of a single packfile 57 * 58 * This can be useful for inspecting the contents of a single 59 * packfile. 60 * 61 * @param out_ location to store the odb backend pointer 62 * @param index_file path to the packfile's .idx file 63 * 64 * @return 0 or an error code 65 */ 66 //GIT_EXTERN 67 int git_odb_backend_one_pack(libgit2_d.types.git_odb_backend** out_, const (char)* index_file); 68 69 /** 70 * Streaming mode 71 */ 72 enum git_odb_stream_t 73 { 74 GIT_STREAM_RDONLY = 1 << 1, 75 GIT_STREAM_WRONLY = 1 << 2, 76 GIT_STREAM_RW = GIT_STREAM_RDONLY | GIT_STREAM_WRONLY, 77 } 78 79 /** 80 * A stream to read/write from a backend. 81 * 82 * This represents a stream of data being written to or read from a 83 * backend. When writing, the frontend functions take care of 84 * calculating the object's id and all `finalize_write` needs to do is 85 * store the object with the id it is passed. 86 */ 87 struct git_odb_stream 88 { 89 libgit2_d.types.git_odb_backend* backend; 90 uint mode; 91 void* hash_ctx; 92 93 libgit2_d.types.git_object_size_t declared_size; 94 libgit2_d.types.git_object_size_t received_bytes; 95 96 /** 97 * Write at most `len` bytes into `buffer` and advance the stream. 98 */ 99 int function(.git_odb_stream* stream, char* buffer, size_t len) read; 100 101 /** 102 * Write `len` bytes from `buffer` into the stream. 103 */ 104 int function(.git_odb_stream* stream, const (char)* buffer, size_t len) write; 105 106 /** 107 * Store the contents of the stream as an object with the id 108 * specified in `oid`. 109 * 110 * This method might not be invoked if: 111 * - an error occurs earlier with the `write` callback, 112 * - the object referred to by `oid` already exists in any backend, or 113 * - the final number of received bytes differs from the size declared 114 * with `git_odb_open_wstream()` 115 */ 116 int function(.git_odb_stream* stream, const (libgit2_d.oid.git_oid)* oid) finalize_write; 117 118 /** 119 * Free the stream's memory. 120 * 121 * This method might be called without a call to `finalize_write` if 122 * an error occurs or if the object is already present in the ODB. 123 */ 124 void function(.git_odb_stream* stream) free; 125 } 126 127 /** 128 * A stream to write a pack file to the ODB 129 */ 130 struct git_odb_writepack 131 { 132 libgit2_d.types.git_odb_backend* backend; 133 134 int function(.git_odb_writepack* writepack, const (void)* data, size_t size, libgit2_d.indexer.git_indexer_progress* stats) append; 135 int function(.git_odb_writepack* writepack, libgit2_d.indexer.git_indexer_progress* stats) commit; 136 void function(.git_odb_writepack* writepack) free; 137 }