@@ -40,6 +40,136 @@ GIT_EXTERN(int) git_commit_graph_open(git_commit_graph **cgraph_out, const char
40
40
*/
41
41
GIT_EXTERN (void ) git_commit_graph_free (git_commit_graph * cgraph );
42
42
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
+
44
87
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.
119
+ */
120
+ float size_multiple ;
121
+
122
+ /**
123
+ * The number of commits in level N + 1 is more than C commits.
124
+ */
125
+ size_t max_commits ;
126
+ } git_commit_graph_writer_options ;
127
+
128
+ #define GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION 1
129
+ #define GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT \
130
+ { \
131
+ GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION, \
132
+ GIT_COMMIT_GRAPH_SPLIT_STRATEGY_SINGLE_FILE, 2.0f, 64000 \
133
+ }
134
+
135
+ /**
136
+ * Initialize git_commit_graph_writer_options structure
137
+ *
138
+ * Initializes a `git_commit_graph_writer_options` with default values. Equivalent to
139
+ * creating an instance with `GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT`.
140
+ *
141
+ * @param opts The `git_commit_graph_writer_options` struct to initialize.
142
+ * @param version The struct version; pass `GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION`.
143
+ * @return Zero on success; -1 on failure.
144
+ */
145
+ GIT_EXTERN (int ) git_commit_graph_writer_options_init (
146
+ git_commit_graph_writer_options * opts ,
147
+ unsigned int version );
148
+
149
+ /**
150
+ * Write a `commit-graph` file to a file.
151
+ *
152
+ * @param w The writer
153
+ * @param opts Pointer to git_commit_graph_writer_options struct.
154
+ * @return 0 or an error code
155
+ */
156
+ GIT_EXTERN (int ) git_commit_graph_writer_commit (
157
+ git_commit_graph_writer * w ,
158
+ git_commit_graph_writer_options * opts );
159
+
160
+ /**
161
+ * Dump the contents of the `commit-graph` to an in-memory buffer.
162
+ *
163
+ * @param buffer Buffer where to store the contents of the `commit-graph`.
164
+ * @param w The writer.
165
+ * @param opts Pointer to git_commit_graph_writer_options struct.
166
+ * @return 0 or an error code
167
+ */
168
+ GIT_EXTERN (int ) git_commit_graph_writer_dump (
169
+ git_buf * buffer ,
170
+ git_commit_graph_writer * w ,
171
+ git_commit_graph_writer_options * opts );
172
+
173
+ /** @} */
174
+ GIT_END_DECL
45
175
#endif
0 commit comments