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  * Params:
42  *      out_ = Pointer where to store the ODB backend
43  *
44  * Returns: 0 on success; error code otherwise
45  */
46 //GIT_EXTERN
47 int git_mempack_new(libgit2_d.types.git_odb_backend** out_);
48 
49 /**
50  * Dump all the queued in-memory writes to a packfile.
51  *
52  * The contents of the packfile will be stored in the given buffer.
53  * It is the caller's responsibility to ensure that the generated
54  * packfile is available to the repository (e.g. by writing it
55  * to disk, or doing something crazy like distributing it across
56  * several copies of the repository over a network).
57  *
58  * Once the generated packfile is available to the repository,
59  * call `git_mempack_reset` to cleanup the memory store.
60  *
61  * Calling `git_mempack_reset` before the packfile has been
62  * written to disk will result in an inconsistent repository
63  * (the objects in the memory store won't be accessible).
64  *
65  * Params:
66  *      pack = Buffer where to store the raw packfile
67  *      repo = The active repository where the backend is loaded
68  *      backend = The mempack backend
69  *
70  * Returns: 0 on success; error code otherwise
71  */
72 //GIT_EXTERN
73 int git_mempack_dump(libgit2_d.buffer.git_buf* pack, libgit2_d.types.git_repository* repo, libgit2_d.types.git_odb_backend* backend);
74 
75 /**
76  * Reset the memory packer by clearing all the queued objects.
77  *
78  * This assumes that `git_mempack_dump` has been called before to
79  * store all the queued objects into a single packfile.
80  *
81  * Alternatively, call `reset` without a previous dump to "undo"
82  * all the recently written objects, giving transaction-like
83  * semantics to the Git repository.
84  *
85  * Params:
86  *      backend = The mempack backend
87  *
88  * Returns: 0 on success; error code otherwise
89  */
90 //GIT_EXTERN
91 int git_mempack_reset(libgit2_d.types.git_odb_backend* backend);