@@ -173,26 +173,34 @@ static int opt_parse_porcelain(const struct option *opt, const char *arg, int un
173173}
174174
175175static int do_serialize = 0 ;
176+ static char * serialize_path = NULL ;
177+
176178static int do_implicit_deserialize = 0 ;
177179static int do_explicit_deserialize = 0 ;
178180static char * deserialize_path = NULL ;
179181
180182/*
181- * --serialize | --serialize=1 | --serialize=v1
183+ * --serialize | --serialize=<path>
184+ *
185+ * Request that we serialize status output rather than or in addition to
186+ * printing in any of the established formats.
187+ *
188+ * Without a path, we write binary serialization data to stdout (and omit
189+ * the normal status output).
182190 *
183- * Request that we serialize our output rather than printing in
184- * any of the established formats. Optionally specify serialization
185- * version.
191+ * With a path, we write binary serialization data to the <path> and then
192+ * write normal status output.
186193 */
187194static int opt_parse_serialize (const struct option * opt , const char * arg , int unset )
188195{
189196 enum wt_status_format * value = (enum wt_status_format * )opt -> value ;
190197 if (unset || !arg )
191198 * value = STATUS_FORMAT_SERIALIZE_V1 ;
192- else if (!strcmp (arg , "v1" ) || !strcmp (arg , "1" ))
193- * value = STATUS_FORMAT_SERIALIZE_V1 ;
194- else
195- die ("unsupported serialize version '%s'" , arg );
199+
200+ if (arg ) {
201+ free (serialize_path );
202+ serialize_path = xstrdup (arg );
203+ }
196204
197205 if (do_explicit_deserialize )
198206 die ("cannot mix --serialize and --deserialize" );
@@ -1595,7 +1603,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
15951603 N_ ("version" ), N_ ("machine-readable output" ),
15961604 PARSE_OPT_OPTARG , opt_parse_porcelain ),
15971605 { OPTION_CALLBACK , 0 , "serialize" , & status_format ,
1598- N_ ("version " ), N_ ("serialize raw status data to stdout" ),
1606+ N_ ("path " ), N_ ("serialize raw status data to path or stdout" ),
15991607 PARSE_OPT_OPTARG | PARSE_OPT_NONEG , opt_parse_serialize },
16001608 { OPTION_CALLBACK , 0 , "deserialize" , NULL ,
16011609 N_ ("path" ), N_ ("deserialize raw status data from file" ),
@@ -1721,6 +1729,16 @@ int cmd_status(int argc, const char **argv, const char *prefix)
17211729 if (s .relative_paths )
17221730 s .prefix = prefix ;
17231731
1732+ if (serialize_path ) {
1733+ int fd_serialize = xopen (serialize_path ,
1734+ O_WRONLY | O_CREAT | O_TRUNC , 0666 );
1735+ if (fd_serialize < 0 )
1736+ die_errno (_ ("could not serialize to '%s'" ),
1737+ serialize_path );
1738+ wt_status_serialize_v1 (fd_serialize , & s );
1739+ close (fd_serialize );
1740+ }
1741+
17241742 wt_status_print (& s );
17251743 wt_status_collect_free_buffers (& s );
17261744
0 commit comments