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 /** 8 * License: GPL-2.0(Linking Exception) 9 */ 10 module libgit2.sys.mempack; 11 12 13 private static import libgit2.buffer; 14 private static import libgit2.types; 15 private import libgit2.common: GIT_EXTERN; 16 17 /* 18 * @file git2/sys/mempack.h 19 * @brief Custom ODB backend that permits packing objects in-memory 20 * @defgroup git_backend Git custom backend APIs 21 * @ingroup Git 22 * @{ 23 */ 24 extern (C): 25 nothrow @nogc: 26 27 /** 28 * Instantiate a new mempack backend. 29 * 30 * The backend must be added to an existing ODB with the highest 31 * priority. 32 * 33 * git_mempack_new(&mempacker); 34 * git_repository_odb(&odb, repository); 35 * git_odb_add_backend(odb, mempacker, 999); 36 * 37 * Once the backend has been loaded, all writes to the ODB will 38 * instead be queued in memory, and can be finalized with 39 * `git_mempack_dump`. 40 * 41 * Subsequent reads will also be served from the in-memory store 42 * to ensure consistency, until the memory store is dumped. 43 * 44 * Params: 45 * out_ = Pointer where to store the ODB backend 46 * 47 * Returns: 0 on success; error code otherwise 48 */ 49 @GIT_EXTERN 50 int git_mempack_new(libgit2.types.git_odb_backend** out_); 51 52 /** 53 * Dump all the queued in-memory writes to a packfile. 54 * 55 * The contents of the packfile will be stored in the given buffer. 56 * It is the caller's responsibility to ensure that the generated 57 * packfile is available to the repository (e.g. by writing it 58 * to disk, or doing something crazy like distributing it across 59 * several copies of the repository over a network). 60 * 61 * Once the generated packfile is available to the repository, 62 * call `git_mempack_reset` to cleanup the memory store. 63 * 64 * Calling `git_mempack_reset` before the packfile has been 65 * written to disk will result in an inconsistent repository 66 * (the objects in the memory store won't be accessible). 67 * 68 * Params: 69 * pack = Buffer where to store the raw packfile 70 * repo = The active repository where the backend is loaded 71 * backend = The mempack backend 72 * 73 * Returns: 0 on success; error code otherwise 74 */ 75 @GIT_EXTERN 76 int git_mempack_dump(libgit2.buffer.git_buf* pack, libgit2.types.git_repository* repo, libgit2.types.git_odb_backend* backend); 77 78 /** 79 * Reset the memory packer by clearing all the queued objects. 80 * 81 * This assumes that `git_mempack_dump` has been called before to 82 * store all the queued objects into a single packfile. 83 * 84 * Alternatively, call `reset` without a previous dump to "undo" 85 * all the recently written objects, giving transaction-like 86 * semantics to the Git repository. 87 * 88 * Params: 89 * backend = The mempack backend 90 * 91 * Returns: 0 on success; error code otherwise 92 */ 93 @GIT_EXTERN 94 int git_mempack_reset(libgit2.types.git_odb_backend* backend);