@@ -167,26 +167,34 @@ static int opt_parse_porcelain(const struct option *opt, const char *arg, int un
167167}
168168
169169static int do_serialize = 0 ;
170+ static char * serialize_path = NULL ;
171+
170172static int do_implicit_deserialize = 0 ;
171173static int do_explicit_deserialize = 0 ;
172174static char * deserialize_path = NULL ;
173175
174176/*
175- * --serialize | --serialize=1 | --serialize=v1
177+ * --serialize | --serialize=<path>
178+ *
179+ * Request that we serialize status output rather than or in addition to
180+ * printing in any of the established formats.
181+ *
182+ * Without a path, we write binary serialization data to stdout (and omit
183+ * the normal status output).
176184 *
177- * Request that we serialize our output rather than printing in
178- * any of the established formats. Optionally specify serialization
179- * version.
185+ * With a path, we write binary serialization data to the <path> and then
186+ * write normal status output.
180187 */
181188static int opt_parse_serialize (const struct option * opt , const char * arg , int unset )
182189{
183190 enum wt_status_format * value = (enum wt_status_format * )opt -> value ;
184191 if (unset || !arg )
185192 * value = STATUS_FORMAT_SERIALIZE_V1 ;
186- else if (!strcmp (arg , "v1" ) || !strcmp (arg , "1" ))
187- * value = STATUS_FORMAT_SERIALIZE_V1 ;
188- else
189- die ("unsupported serialize version '%s'" , arg );
193+
194+ if (arg ) {
195+ free (serialize_path );
196+ serialize_path = xstrdup (arg );
197+ }
190198
191199 if (do_explicit_deserialize )
192200 die ("cannot mix --serialize and --deserialize" );
@@ -1638,7 +1646,7 @@ struct repository *repo UNUSED)
16381646 N_ ("version" ), N_ ("machine-readable output" ),
16391647 PARSE_OPT_OPTARG , opt_parse_porcelain ),
16401648 OPT_CALLBACK_F (0 , "serialize" , & status_format ,
1641- N_ ("version " ), N_ ("serialize raw status data to stdout" ),
1649+ N_ ("path " ), N_ ("serialize raw status data to path or stdout" ),
16421650 PARSE_OPT_OPTARG | PARSE_OPT_NONEG , opt_parse_serialize ),
16431651 OPT_CALLBACK_F (0 , "deserialize" , NULL ,
16441652 N_ ("path" ), N_ ("deserialize raw status data from file" ),
@@ -1781,6 +1789,16 @@ struct repository *repo UNUSED)
17811789 if (s .relative_paths )
17821790 s .prefix = prefix ;
17831791
1792+ if (serialize_path ) {
1793+ int fd_serialize = xopen (serialize_path ,
1794+ O_WRONLY | O_CREAT | O_TRUNC , 0666 );
1795+ if (fd_serialize < 0 )
1796+ die_errno (_ ("could not serialize to '%s'" ),
1797+ serialize_path );
1798+ wt_status_serialize_v1 (fd_serialize , & s );
1799+ close (fd_serialize );
1800+ }
1801+
17841802 wt_status_print (& s );
17851803 wt_status_collect_free_buffers (& s );
17861804
0 commit comments