@@ -166,6 +166,70 @@ static int opt_parse_porcelain(const struct option *opt, const char *arg, int un
166166 return 0 ;
167167}
168168
169+ static int do_serialize = 0 ;
170+ static int do_implicit_deserialize = 0 ;
171+ static int do_explicit_deserialize = 0 ;
172+ static char * deserialize_path = NULL ;
173+
174+ /*
175+ * --serialize | --serialize=1 | --serialize=v1
176+ *
177+ * Request that we serialize our output rather than printing in
178+ * any of the established formats. Optionally specify serialization
179+ * version.
180+ */
181+ static int opt_parse_serialize (const struct option * opt , const char * arg , int unset )
182+ {
183+ enum wt_status_format * value = (enum wt_status_format * )opt -> value ;
184+ if (unset || !arg )
185+ * 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 );
190+
191+ if (do_explicit_deserialize )
192+ die ("cannot mix --serialize and --deserialize" );
193+ do_implicit_deserialize = 0 ;
194+
195+ do_serialize = 1 ;
196+ return 0 ;
197+ }
198+
199+ /*
200+ * --deserialize | --deserialize=<path> |
201+ * --no-deserialize
202+ *
203+ * Request that we deserialize status data from some existing resource
204+ * rather than performing a status scan.
205+ *
206+ * The input source can come from stdin or a path given here -- or be
207+ * inherited from the config settings.
208+ */
209+ static int opt_parse_deserialize (const struct option * opt UNUSED , const char * arg , int unset )
210+ {
211+ if (unset ) {
212+ do_implicit_deserialize = 0 ;
213+ do_explicit_deserialize = 0 ;
214+ } else {
215+ if (do_serialize )
216+ die ("cannot mix --serialize and --deserialize" );
217+ if (arg ) {
218+ /* override config or stdin */
219+ free (deserialize_path );
220+ deserialize_path = xstrdup (arg );
221+ }
222+ if (deserialize_path && * deserialize_path
223+ && (access (deserialize_path , R_OK ) != 0 ))
224+ die ("cannot find serialization file '%s'" ,
225+ deserialize_path );
226+
227+ do_explicit_deserialize = 1 ;
228+ }
229+
230+ return 0 ;
231+ }
232+
169233static int opt_parse_m (const struct option * opt , const char * arg , int unset )
170234{
171235 struct strbuf * buf = opt -> value ;
@@ -1209,6 +1273,8 @@ static enum untracked_status_type parse_untracked_setting_name(const char *u)
12091273 return SHOW_NORMAL_UNTRACKED_FILES ;
12101274 else if (!strcmp (u , "all" ))
12111275 return SHOW_ALL_UNTRACKED_FILES ;
1276+ else if (!strcmp (u ,"complete" ))
1277+ return SHOW_COMPLETE_UNTRACKED_FILES ;
12121278 else
12131279 return SHOW_UNTRACKED_FILES_ERROR ;
12141280}
@@ -1504,6 +1570,19 @@ static int git_status_config(const char *k, const char *v,
15041570 s -> relative_paths = git_config_bool (k , v );
15051571 return 0 ;
15061572 }
1573+ if (!strcmp (k , "status.deserializepath" )) {
1574+ /*
1575+ * Automatically assume deserialization if this is
1576+ * set in the config and the file exists. Do not
1577+ * complain if the file does not exist, because we
1578+ * silently fall back to normal mode.
1579+ */
1580+ if (v && * v && access (v , R_OK ) == 0 ) {
1581+ do_implicit_deserialize = 1 ;
1582+ deserialize_path = xstrdup (v );
1583+ }
1584+ return 0 ;
1585+ }
15071586 if (!strcmp (k , "status.showuntrackedfiles" )) {
15081587 enum untracked_status_type u ;
15091588
@@ -1543,7 +1622,8 @@ struct repository *repo UNUSED)
15431622 static const char * rename_score_arg = (const char * )-1 ;
15441623 static struct wt_status s ;
15451624 unsigned int progress_flag = 0 ;
1546- int fd ;
1625+ int try_deserialize ;
1626+ int fd = -1 ;
15471627 struct object_id oid ;
15481628 static struct option builtin_status_options [] = {
15491629 OPT__VERBOSE (& verbose , N_ ("be verbose" )),
@@ -1558,6 +1638,12 @@ struct repository *repo UNUSED)
15581638 OPT_CALLBACK_F (0 , "porcelain" , & status_format ,
15591639 N_ ("version" ), N_ ("machine-readable output" ),
15601640 PARSE_OPT_OPTARG , opt_parse_porcelain ),
1641+ OPT_CALLBACK_F (0 , "serialize" , & status_format ,
1642+ N_ ("version" ), N_ ("serialize raw status data to stdout" ),
1643+ PARSE_OPT_OPTARG | PARSE_OPT_NONEG , opt_parse_serialize ),
1644+ OPT_CALLBACK_F (0 , "deserialize" , NULL ,
1645+ N_ ("path" ), N_ ("deserialize raw status data from file" ),
1646+ PARSE_OPT_OPTARG , opt_parse_deserialize ),
15611647 OPT_SET_INT (0 , "long" , & status_format ,
15621648 N_ ("show status in long format (default)" ),
15631649 STATUS_FORMAT_LONG ),
@@ -1619,10 +1705,26 @@ struct repository *repo UNUSED)
16191705 s .show_untracked_files == SHOW_NO_UNTRACKED_FILES )
16201706 die (_ ("Unsupported combination of ignored and untracked-files arguments" ));
16211707
1708+ if (s .show_untracked_files == SHOW_COMPLETE_UNTRACKED_FILES &&
1709+ s .show_ignored_mode == SHOW_NO_IGNORED )
1710+ die (_ ("Complete Untracked only supported with ignored files" ));
1711+
16221712 parse_pathspec (& s .pathspec , 0 ,
16231713 PATHSPEC_PREFER_FULL ,
16241714 prefix , argv );
16251715
1716+ /*
1717+ * If we want to try to deserialize status data from a cache file,
1718+ * we need to re-order the initialization code. The problem is that
1719+ * this makes for a very nasty diff and causes merge conflicts as we
1720+ * carry it forward. And it easy to mess up the merge, so we
1721+ * duplicate some code here to hopefully reduce conflicts.
1722+ */
1723+ try_deserialize = (!do_serialize &&
1724+ (do_implicit_deserialize || do_explicit_deserialize ));
1725+ if (try_deserialize )
1726+ goto skip_init ;
1727+
16261728 enable_fscache (0 );
16271729 if (status_format != STATUS_FORMAT_PORCELAIN &&
16281730 status_format != STATUS_FORMAT_PORCELAIN_V2 )
@@ -1637,6 +1739,7 @@ struct repository *repo UNUSED)
16371739 else
16381740 fd = -1 ;
16391741
1742+ skip_init :
16401743 s .is_initial = repo_get_oid (the_repository , s .reference , & oid ) ? 1 : 0 ;
16411744 if (!s .is_initial )
16421745 oidcpy (& s .oid_commit , & oid );
@@ -1653,6 +1756,24 @@ struct repository *repo UNUSED)
16531756 s .rename_score = parse_rename_score (& rename_score_arg );
16541757 }
16551758
1759+ if (try_deserialize ) {
1760+ if (s .relative_paths )
1761+ s .prefix = prefix ;
1762+
1763+ if (wt_status_deserialize (& s , deserialize_path ) == DESERIALIZE_OK )
1764+ return 0 ;
1765+
1766+ /* deserialize failed, so force the initialization we skipped above. */
1767+ enable_fscache (1 );
1768+ repo_read_index_preload (the_repository , & s .pathspec , 0 );
1769+ refresh_index (the_repository -> index , REFRESH_QUIET |REFRESH_UNMERGED , & s .pathspec , NULL , NULL );
1770+
1771+ if (use_optional_locks ())
1772+ fd = repo_hold_locked_index (the_repository , & index_lock , 0 );
1773+ else
1774+ fd = -1 ;
1775+ }
1776+
16561777 wt_status_collect (& s );
16571778
16581779 if (0 <= fd )
0 commit comments