@@ -176,26 +176,34 @@ static int opt_parse_porcelain(const struct option *opt, const char *arg, int un
176176}
177177
178178static int do_serialize = 0 ;
179+ static char * serialize_path = NULL ;
180+
179181static int do_implicit_deserialize = 0 ;
180182static int do_explicit_deserialize = 0 ;
181183static char * deserialize_path = NULL ;
182184
183185/*
184- * --serialize | --serialize=1 | --serialize=v1
186+ * --serialize | --serialize=<path>
187+ *
188+ * Request that we serialize status output rather than or in addition to
189+ * printing in any of the established formats.
190+ *
191+ * Without a path, we write binary serialization data to stdout (and omit
192+ * the normal status output).
185193 *
186- * Request that we serialize our output rather than printing in
187- * any of the established formats. Optionally specify serialization
188- * version.
194+ * With a path, we write binary serialization data to the <path> and then
195+ * write normal status output.
189196 */
190197static int opt_parse_serialize (const struct option * opt , const char * arg , int unset )
191198{
192199 enum wt_status_format * value = (enum wt_status_format * )opt -> value ;
193200 if (unset || !arg )
194201 * value = STATUS_FORMAT_SERIALIZE_V1 ;
195- else if (!strcmp (arg , "v1" ) || !strcmp (arg , "1" ))
196- * value = STATUS_FORMAT_SERIALIZE_V1 ;
197- else
198- die ("unsupported serialize version '%s'" , arg );
202+
203+ if (arg ) {
204+ free (serialize_path );
205+ serialize_path = xstrdup (arg );
206+ }
199207
200208 if (do_explicit_deserialize )
201209 die ("cannot mix --serialize and --deserialize" );
@@ -1599,7 +1607,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
15991607 N_ ("version" ), N_ ("machine-readable output" ),
16001608 PARSE_OPT_OPTARG , opt_parse_porcelain ),
16011609 { OPTION_CALLBACK , 0 , "serialize" , & status_format ,
1602- N_ ("version " ), N_ ("serialize raw status data to stdout" ),
1610+ N_ ("path " ), N_ ("serialize raw status data to path or stdout" ),
16031611 PARSE_OPT_OPTARG | PARSE_OPT_NONEG , opt_parse_serialize },
16041612 { OPTION_CALLBACK , 0 , "deserialize" , NULL ,
16051613 N_ ("path" ), N_ ("deserialize raw status data from file" ),
@@ -1725,6 +1733,16 @@ int cmd_status(int argc, const char **argv, const char *prefix)
17251733 if (s .relative_paths )
17261734 s .prefix = prefix ;
17271735
1736+ if (serialize_path ) {
1737+ int fd_serialize = xopen (serialize_path ,
1738+ O_WRONLY | O_CREAT | O_TRUNC , 0666 );
1739+ if (fd_serialize < 0 )
1740+ die_errno (_ ("could not serialize to '%s'" ),
1741+ serialize_path );
1742+ wt_status_serialize_v1 (fd_serialize , & s );
1743+ close (fd_serialize );
1744+ }
1745+
17281746 wt_status_print (& s );
17291747 wt_status_collect_free_buffers (& s );
17301748
0 commit comments