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.commit_graph;
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/commit_graph.h
19  * @brief Git commit-graph
20  * @defgroup git_commit_graph Git commit-graph APIs
21  * @ingroup Git
22  * @{
23  */
24 extern (C):
25 nothrow @nogc:
26 
27 /**
28  * Opens a `git_commit_graph` from a path to an objects directory.
29  *
30  * This finds, opens, and validates the `commit-graph` file.
31  *
32  * Params:
33  *      cgraph_out = the `git_commit_graph` struct to initialize.
34  *      objects_dir = the path to a git objects directory.
35  *
36  * Returns: Zero on success; -1 on failure.
37  */
38 @GIT_EXTERN
39 int git_commit_graph_open(libgit2.types.git_commit_graph** cgraph_out, const (char)* objects_dir);
40 
41 /**
42  * Frees commit-graph data. This should only be called when memory allocated
43  * using `git_commit_graph_open` is not returned to libgit2 because it was not
44  * associated with the ODB through a successful call to
45  * `git_odb_set_commit_graph`.
46  *
47  * Params:
48  *      cgraph = the commit-graph object to free. If null, no action is taken.
49  */
50 @GIT_EXTERN
51 void git_commit_graph_free(libgit2.types.git_commit_graph* cgraph);
52 
53 /**
54  * Create a new writer for `commit-graph` files.
55  *
56  * Params:
57  *      out_ = Location to store the writer pointer.
58  *      objects_info_dir = The `objects/info` directory. The `commit-graph` file will be written in this directory.
59  *
60  * Returns: 0 or an error code
61  */
62 @GIT_EXTERN
63 int git_commit_graph_writer_new(libgit2.types.git_commit_graph_writer** out_, const (char)* objects_info_dir);
64 
65 /**
66  * Free the commit-graph writer and its resources.
67  *
68  * Params:
69  *      w = The writer to free. If null no action is taken.
70  */
71 @GIT_EXTERN
72 void git_commit_graph_writer_free(libgit2.types.git_commit_graph_writer* w);
73 
74 /**
75  * Add an `.idx` file (associated to a packfile) to the writer.
76  *
77  * Params:
78  *      w = The writer.
79  *      repo = The repository that owns the `.idx` file.
80  *      idx_path = The path of an `.idx` file.
81  *
82  * Returns: 0 or an error code
83  */
84 @GIT_EXTERN
85 int git_commit_graph_writer_add_index_file(libgit2.types.git_commit_graph_writer* w, libgit2.types.git_repository* repo, const (char)* idx_path);
86 
87 /**
88  * Add a revwalk to the writer. This will add all the commits from the revwalk
89  * to the commit-graph.
90  *
91  * Params:
92  *      w = The writer.
93  *      walk = The git_revwalk.
94  *
95  * Returns: 0 or an error code
96  */
97 @GIT_EXTERN
98 int git_commit_graph_writer_add_revwalk(libgit2.types.git_commit_graph_writer* w, libgit2.types.git_revwalk* walk);
99 
100 
101 /**
102  * The strategy to use when adding a new set of commits to a pre-existing
103  * commit-graph chain.
104  */
105 enum git_commit_graph_split_strategy_t
106 {
107 	/**
108 	 * Do not split commit-graph files. The other split strategy-related option
109 	 * fields are ignored.
110 	 */
111 	GIT_COMMIT_GRAPH_SPLIT_STRATEGY_SINGLE_FILE = 0,
112 }
113 
114 //Declaration name in C language
115 enum
116 {
117 	GIT_COMMIT_GRAPH_SPLIT_STRATEGY_SINGLE_FILE = .git_commit_graph_split_strategy_t.GIT_COMMIT_GRAPH_SPLIT_STRATEGY_SINGLE_FILE,
118 }
119 
120 /**
121  * Options structure for
122  * `git_commit_graph_writer_commit`/`git_commit_graph_writer_dump`.
123  *
124  * Initialize with `GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT`. Alternatively, you
125  * can use `git_commit_graph_writer_options_init`.
126  */
127 struct git_commit_graph_writer_options
128 {
129 	uint version_;
130 
131 	/**
132 	 * The strategy to use when adding new commits to a pre-existing commit-graph
133 	 * chain.
134 	 */
135 	.git_commit_graph_split_strategy_t split_strategy;
136 
137 	/**
138 	 * The number of commits in level N is less than X times the number of
139 	 * commits in level N + 1. Default is 2.
140 	 */
141 	float size_multiple;
142 
143 	/**
144 	 * The number of commits in level N + 1 is more than C commits.
145 	 * Default is 64000.
146 	 */
147 	size_t max_commits;
148 }
149 
150 enum GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION = 1;
151 
152 pragma(inline, true)
153 pure nothrow @safe @nogc @live
154 .git_commit_graph_writer_options GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT()
155 
156 	do
157 	{
158 		.git_commit_graph_writer_options OUTPUT =
159 		{
160 			version_: .GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION,
161 		};
162 
163 		return OUTPUT;
164 	}
165 
166 /**
167  * Initialize git_commit_graph_writer_options structure
168  *
169  * Initializes a `git_commit_graph_writer_options` with default values. Equivalent to
170  * creating an instance with `GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT`.
171  *
172  * Params:
173  *      opts = The `git_commit_graph_writer_options` struct to initialize.
174  *      version_ = The struct version; pass `GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION`.
175  *
176  * Returns: Zero on success; -1 on failure.
177  */
178 @GIT_EXTERN
179 int git_commit_graph_writer_options_init(.git_commit_graph_writer_options* opts, uint version_);
180 
181 /**
182  * Write a `commit-graph` file to a file.
183  *
184  * Params:
185  *      w = The writer
186  *      opts = Pointer to git_commit_graph_writer_options struct.
187  *
188  * Returns: 0 or an error code
189  */
190 @GIT_EXTERN
191 int git_commit_graph_writer_commit(libgit2.types.git_commit_graph_writer* w, .git_commit_graph_writer_options* opts);
192 
193 /**
194  * Dump the contents of the `commit-graph` to an in-memory buffer.
195  *
196  * Params:
197  *      buffer = Buffer where to store the contents of the `commit-graph`.
198  *      w = The writer.
199  *      opts = Pointer to git_commit_graph_writer_options struct.
200  *
201  * Returns: 0 or an error code
202  */
203 @GIT_EXTERN
204 int git_commit_graph_writer_dump(libgit2.buffer.git_buf* buffer, libgit2.types.git_commit_graph_writer* w, .git_commit_graph_writer_options* opts);
205 
206 /* @} */