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