9
9
10
10
static char const * const builtin_commit_graph_usage [] = {
11
11
N_ ("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]" ),
12
- N_ ("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] [--[no-]progress] <split options>" ),
12
+ N_ ("git commit-graph write [--object-dir <objdir>] [--append] "
13
+ "[--split[=<strategy>]] [--reachable|--stdin-packs|--stdin-commits] "
14
+ "[--[no-]progress] <split options>" ),
13
15
NULL
14
16
};
15
17
@@ -19,7 +21,9 @@ static const char * const builtin_commit_graph_verify_usage[] = {
19
21
};
20
22
21
23
static const char * const builtin_commit_graph_write_usage [] = {
22
- N_ ("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] [--[no-]progress] <split options>" ),
24
+ N_ ("git commit-graph write [--object-dir <objdir>] [--append] "
25
+ "[--split[=<strategy>]] [--reachable|--stdin-packs|--stdin-commits] "
26
+ "[--[no-]progress] <split options>" ),
23
27
NULL
24
28
};
25
29
@@ -114,10 +118,29 @@ static int graph_verify(int argc, const char **argv)
114
118
extern int read_replace_refs ;
115
119
static struct split_commit_graph_opts split_opts ;
116
120
121
+ static int write_option_parse_split (const struct option * opt , const char * arg ,
122
+ int unset )
123
+ {
124
+ enum commit_graph_split_flags * flags = opt -> value ;
125
+
126
+ opts .split = 1 ;
127
+ if (!arg )
128
+ return 0 ;
129
+
130
+ if (!strcmp (arg , "no-merge" ))
131
+ * flags = COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED ;
132
+ else if (!strcmp (arg , "replace" ))
133
+ * flags = COMMIT_GRAPH_SPLIT_REPLACE ;
134
+ else
135
+ die (_ ("unrecognized --split argument, %s" ), arg );
136
+
137
+ return 0 ;
138
+ }
139
+
117
140
static int graph_write (int argc , const char * * argv )
118
141
{
119
142
struct string_list * pack_indexes = NULL ;
120
- struct string_list * commit_hex = NULL ;
143
+ struct oidset commits = OIDSET_INIT ;
121
144
struct object_directory * odb = NULL ;
122
145
struct string_list lines ;
123
146
int result = 0 ;
@@ -136,8 +159,10 @@ static int graph_write(int argc, const char **argv)
136
159
OPT_BOOL (0 , "append" , & opts .append ,
137
160
N_ ("include all commits already in the commit-graph file" )),
138
161
OPT_BOOL (0 , "progress" , & opts .progress , N_ ("force progress reporting" )),
139
- OPT_BOOL (0 , "split" , & opts .split ,
140
- N_ ("allow writing an incremental commit-graph file" )),
162
+ OPT_CALLBACK_F (0 , "split" , & split_opts .flags , NULL ,
163
+ N_ ("allow writing an incremental commit-graph file" ),
164
+ PARSE_OPT_OPTARG | PARSE_OPT_NONEG ,
165
+ write_option_parse_split ),
141
166
OPT_INTEGER (0 , "max-commits" , & split_opts .max_commits ,
142
167
N_ ("maximum number of commits in a non-base split commit-graph" )),
143
168
OPT_INTEGER (0 , "size-multiple" , & split_opts .size_multiple ,
@@ -188,7 +213,20 @@ static int graph_write(int argc, const char **argv)
188
213
if (opts .stdin_packs )
189
214
pack_indexes = & lines ;
190
215
if (opts .stdin_commits ) {
191
- commit_hex = & lines ;
216
+ struct string_list_item * item ;
217
+ oidset_init (& commits , lines .nr );
218
+ for_each_string_list_item (item , & lines ) {
219
+ struct object_id oid ;
220
+ const char * end ;
221
+
222
+ if (parse_oid_hex (item -> string , & oid , & end )) {
223
+ error (_ ("unexpected non-hex object ID: "
224
+ "%s" ), item -> string );
225
+ return 1 ;
226
+ }
227
+
228
+ oidset_insert (& commits , & oid );
229
+ }
192
230
flags |= COMMIT_GRAPH_WRITE_CHECK_OIDS ;
193
231
}
194
232
@@ -197,7 +235,7 @@ static int graph_write(int argc, const char **argv)
197
235
198
236
if (write_commit_graph (odb ,
199
237
pack_indexes ,
200
- commit_hex ,
238
+ opts . stdin_commits ? & commits : NULL ,
201
239
flags ,
202
240
& split_opts ))
203
241
result = 1 ;
0 commit comments