@@ -143,26 +143,32 @@ static int opt_parse_porcelain(const struct option *opt, const char *arg, int un
143143}
144144
145145static int do_serialize = 0 ;
146+ static char * serialize_path = NULL ;
147+
146148static int do_implicit_deserialize = 0 ;
147149static int do_explicit_deserialize = 0 ;
148150static char * deserialize_path = NULL ;
149151
150152/*
151- * --serialize | --serialize=1 | --serialize=v1
153+ * --serialize | --serialize=<path>
154+ *
155+ * Request that we serialize status output rather than or in addition to
156+ * printing in any of the established formats.
157+ *
158+ * Without a path, we write binary serialization data to stdout (and omit
159+ * the normal status output).
152160 *
153- * Request that we serialize our output rather than printing in
154- * any of the established formats. Optionally specify serialization
155- * version.
161+ * With a path, we write binary serialization data to the <path> and then
162+ * write normal status output.
156163 */
157164static int opt_parse_serialize (const struct option * opt , const char * arg , int unset )
158165{
159166 enum wt_status_format * value = (enum wt_status_format * )opt -> value ;
160167 if (unset || !arg )
161168 * value = STATUS_FORMAT_SERIALIZE_V1 ;
162- else if (!strcmp (arg , "v1" ) || !strcmp (arg , "1" ))
163- * value = STATUS_FORMAT_SERIALIZE_V1 ;
164- else
165- die ("unsupported serialize version '%s'" , arg );
169+
170+ if (arg )
171+ serialize_path = xstrdup (arg );
166172
167173 if (do_explicit_deserialize )
168174 die ("cannot mix --serialize and --deserialize" );
@@ -1415,7 +1421,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
14151421 N_ ("version" ), N_ ("machine-readable output" ),
14161422 PARSE_OPT_OPTARG , opt_parse_porcelain },
14171423 { OPTION_CALLBACK , 0 , "serialize" , & status_format ,
1418- N_ ("version " ), N_ ("serialize raw status data to stdout" ),
1424+ N_ ("path " ), N_ ("serialize raw status data to path or stdout" ),
14191425 PARSE_OPT_OPTARG | PARSE_OPT_NONEG , opt_parse_serialize },
14201426 { OPTION_CALLBACK , 0 , "deserialize" , NULL ,
14211427 N_ ("path" ), N_ ("deserialize raw status data from file" ),
@@ -1557,6 +1563,16 @@ int cmd_status(int argc, const char **argv, const char *prefix)
15571563 if (s .relative_paths )
15581564 s .prefix = prefix ;
15591565
1566+ if (serialize_path ) {
1567+ int fd_serialize = xopen (serialize_path ,
1568+ O_WRONLY | O_CREAT | O_TRUNC , 0666 );
1569+ if (fd_serialize < 0 )
1570+ die_errno (_ ("could not serialize to '%s'" ),
1571+ serialize_path );
1572+ wt_status_serialize_v1 (fd_serialize , & s );
1573+ close (fd_serialize );
1574+ }
1575+
15601576 wt_status_print (& s );
15611577 wt_status_collect_free_buffers (& s );
15621578
0 commit comments