@@ -40,6 +40,135 @@ GIT_EXTERN(int) git_commit_graph_open(git_commit_graph **cgraph_out, const char
4040 */
4141GIT_EXTERN (void ) git_commit_graph_free (git_commit_graph * cgraph );
4242
43- GIT_END_DECL
43+ /**
44+ * Create a new writer for `commit-graph` files.
45+ *
46+ * @param out Location to store the writer pointer.
47+ * @param objects_info_dir The `objects/info` directory.
48+ * The `commit-graph` file will be written in this directory.
49+ * @return 0 or an error code
50+ */
51+ GIT_EXTERN (int ) git_commit_graph_writer_new (
52+ git_commit_graph_writer * * out ,
53+ const char * objects_info_dir );
54+
55+ /**
56+ * Free the commit-graph writer and its resources.
57+ *
58+ * @param w The writer to free. If NULL no action is taken.
59+ */
60+ GIT_EXTERN (void ) git_commit_graph_writer_free (git_commit_graph_writer * w );
61+
62+ /**
63+ * Add an `.idx` file (associated to a packfile) to the writer.
64+ *
65+ * @param w The writer.
66+ * @param repo The repository that owns the `.idx` file.
67+ * @param idx_path The path of an `.idx` file.
68+ * @return 0 or an error code
69+ */
70+ GIT_EXTERN (int ) git_commit_graph_writer_add_index_file (
71+ git_commit_graph_writer * w ,
72+ git_repository * repo ,
73+ const char * idx_path );
74+
75+ /**
76+ * Add a revwalk to the writer. This will add all the commits from the revwalk
77+ * to the commit-graph.
78+ *
79+ * @param w The writer.
80+ * @param walk The git_revwalk.
81+ * @return 0 or an error code
82+ */
83+ GIT_EXTERN (int ) git_commit_graph_writer_add_revwalk (
84+ git_commit_graph_writer * w ,
85+ git_revwalk * walk );
86+
4487
88+ /**
89+ * The strategy to use when adding a new set of commits to a pre-existing
90+ * commit-graph chain.
91+ */
92+ typedef enum {
93+ /**
94+ * Do not split commit-graph files. The other split strategy-related option
95+ * fields are ignored.
96+ */
97+ GIT_COMMIT_GRAPH_SPLIT_STRATEGY_SINGLE_FILE = 0 ,
98+ } git_commit_graph_split_strategy_t ;
99+
100+ /**
101+ * Options structure for
102+ * `git_commit_graph_writer_commit`/`git_commit_graph_writer_dump`.
103+ *
104+ * Initialize with `GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT`. Alternatively, you
105+ * can use `git_commit_graph_writer_options_init`.
106+ */
107+ typedef struct {
108+ unsigned int version ;
109+
110+ /**
111+ * The strategy to use when adding new commits to a pre-existing commit-graph
112+ * chain.
113+ */
114+ git_commit_graph_split_strategy_t split_strategy ;
115+
116+ /**
117+ * The number of commits in level N is less than X times the number of
118+ * commits in level N + 1. Default is 2.
119+ */
120+ float size_multiple ;
121+
122+ /**
123+ * The number of commits in level N + 1 is more than C commits.
124+ * Default is 64000.
125+ */
126+ size_t max_commits ;
127+ } git_commit_graph_writer_options ;
128+
129+ #define GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION 1
130+ #define GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT { \
131+ GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION \
132+ }
133+
134+ /**
135+ * Initialize git_commit_graph_writer_options structure
136+ *
137+ * Initializes a `git_commit_graph_writer_options` with default values. Equivalent to
138+ * creating an instance with `GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT`.
139+ *
140+ * @param opts The `git_commit_graph_writer_options` struct to initialize.
141+ * @param version The struct version; pass `GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION`.
142+ * @return Zero on success; -1 on failure.
143+ */
144+ GIT_EXTERN (int ) git_commit_graph_writer_options_init (
145+ git_commit_graph_writer_options * opts ,
146+ unsigned int version );
147+
148+ /**
149+ * Write a `commit-graph` file to a file.
150+ *
151+ * @param w The writer
152+ * @param opts Pointer to git_commit_graph_writer_options struct.
153+ * @return 0 or an error code
154+ */
155+ GIT_EXTERN (int ) git_commit_graph_writer_commit (
156+ git_commit_graph_writer * w ,
157+ git_commit_graph_writer_options * opts );
158+
159+ /**
160+ * Dump the contents of the `commit-graph` to an in-memory buffer.
161+ *
162+ * @param buffer Buffer where to store the contents of the `commit-graph`.
163+ * @param w The writer.
164+ * @param opts Pointer to git_commit_graph_writer_options struct.
165+ * @return 0 or an error code
166+ */
167+ GIT_EXTERN (int ) git_commit_graph_writer_dump (
168+ git_buf * buffer ,
169+ git_commit_graph_writer * w ,
170+ git_commit_graph_writer_options * opts );
171+
172+ /** @} */
173+ GIT_END_DECL
45174#endif
0 commit comments