9
9
#include "statinfo.h"
10
10
#include "hex.h"
11
11
#include "path.h"
12
+ #include "trace2.h"
13
+
14
+ static void set_deserialize_reject_reason (const char * reason )
15
+ {
16
+ trace2_data_string ("status" , the_repository , "deserialize/reject" ,
17
+ reason );
18
+ }
19
+
20
+ int wt_status_deserialize_access (const char * path , int mode )
21
+ {
22
+ int a = access (path , mode );
23
+
24
+ if (a != 0 )
25
+ set_deserialize_reject_reason ("status-cache/access" );
26
+
27
+ return a ;
28
+ }
12
29
13
30
static struct trace_key trace_deserialize = TRACE_KEY_INIT (DESERIALIZE );
14
31
@@ -55,13 +72,15 @@ static int my_validate_index(const char *path, const struct cache_time *mtime_re
55
72
struct cache_time mtime_observed_on_disk ;
56
73
57
74
if (lstat (path , & st )) {
75
+ set_deserialize_reject_reason ("index/not-found" );
58
76
trace_printf_key (& trace_deserialize , "could not stat index" );
59
77
return DESERIALIZE_ERR ;
60
78
}
61
79
mtime_observed_on_disk .sec = st .st_mtime ;
62
80
mtime_observed_on_disk .nsec = ST_MTIME_NSEC (st );
63
81
if ((mtime_observed_on_disk .sec != mtime_reported -> sec ) ||
64
82
(mtime_observed_on_disk .nsec != mtime_reported -> nsec )) {
83
+ set_deserialize_reject_reason ("index/mtime-changed" );
65
84
trace_printf_key (& trace_deserialize ,
66
85
"index mtime changed [des %d %d][obs %d %d]" ,
67
86
mtime_reported -> sec , mtime_reported -> nsec ,
@@ -87,10 +106,12 @@ static int my_validate_excludes(const char *path, const char *key, const char *l
87
106
88
107
r = (strcmp (line , sb .buf ) ? DESERIALIZE_ERR : DESERIALIZE_OK );
89
108
90
- if (r == DESERIALIZE_ERR )
109
+ if (r == DESERIALIZE_ERR ) {
110
+ set_deserialize_reject_reason ("excludes/changed" );
91
111
trace_printf_key (& trace_deserialize ,
92
112
"%s changed [cached '%s'][observed '%s']" ,
93
113
key , line , sb .buf );
114
+ }
94
115
95
116
strbuf_release (& sb );
96
117
return r ;
@@ -146,6 +167,7 @@ static int wt_deserialize_v1_header(struct wt_status *s, int fd)
146
167
& index_mtime .sec ,
147
168
& index_mtime .nsec );
148
169
if (nr_fields != 2 ) {
170
+ set_deserialize_reject_reason ("v1-header/invalid-index-mtime" );
149
171
trace_printf_key (& trace_deserialize , "invalid index_mtime (%d) '%s'" ,
150
172
nr_fields , line );
151
173
return DESERIALIZE_ERR ;
@@ -229,6 +251,7 @@ static int wt_deserialize_v1_header(struct wt_status *s, int fd)
229
251
/* status_format */
230
252
if (skip_prefix (line , "sha1_commit " , & arg )) {
231
253
if (get_oid_hex (arg , & s -> oid_commit )) {
254
+ set_deserialize_reject_reason ("v1-header/invalid-commit-sha" );
232
255
trace_printf_key (& trace_deserialize , "invalid sha1_commit" );
233
256
return DESERIALIZE_ERR ;
234
257
}
@@ -244,19 +267,23 @@ static int wt_deserialize_v1_header(struct wt_status *s, int fd)
244
267
}
245
268
/* prefix */
246
269
270
+ set_deserialize_reject_reason ("v1-header/unexpected-line" );
247
271
trace_printf_key (& trace_deserialize , "unexpected line '%s'" , line );
248
272
return DESERIALIZE_ERR ;
249
273
}
250
274
251
275
if (!have_required_index_mtime ) {
276
+ set_deserialize_reject_reason ("v1-header/missing-index-mtime" );
252
277
trace_printf_key (& trace_deserialize , "missing '%s'" , "index_mtime" );
253
278
return DESERIALIZE_ERR ;
254
279
}
255
280
if (!have_required_core_excludes ) {
281
+ set_deserialize_reject_reason ("v1-header/missing-core-excludes" );
256
282
trace_printf_key (& trace_deserialize , "missing '%s'" , "core_excludes" );
257
283
return DESERIALIZE_ERR ;
258
284
}
259
285
if (!have_required_repo_excludes ) {
286
+ set_deserialize_reject_reason ("v1-header/missing-repo-excludes" );
260
287
trace_printf_key (& trace_deserialize , "missing '%s'" , "repo_excludes" );
261
288
return DESERIALIZE_ERR ;
262
289
}
@@ -343,6 +370,7 @@ static int wt_deserialize_v1_changed_items(const struct wt_status *cmd_s,
343
370
* So we reject the status cache and let the fallback
344
371
* code run.
345
372
*/
373
+ set_deserialize_reject_reason ("v1-data/unmerged" );
346
374
trace_printf_key (
347
375
& trace_deserialize ,
348
376
"reject: V2 format and umerged file: %s" ,
@@ -484,13 +512,15 @@ static int wt_deserialize_v1(const struct wt_status *cmd_s, struct wt_status *s,
484
512
* the serialized data
485
513
*/
486
514
if (validate_untracked_files_arg (cmd_s -> show_untracked_files , & s -> show_untracked_files , & untracked_strategy )) {
515
+ set_deserialize_reject_reason ("args/untracked-files" );
487
516
trace_printf_key (& trace_deserialize , "reject: show_untracked_file: command: %d, serialized : %d" ,
488
517
cmd_s -> show_untracked_files ,
489
518
s -> show_untracked_files );
490
519
return DESERIALIZE_ERR ;
491
520
}
492
521
493
522
if (validate_ignored_files_arg (cmd_s -> show_ignored_mode , s -> show_ignored_mode , & ignored_strategy )) {
523
+ set_deserialize_reject_reason ("args/ignored-mode" );
494
524
trace_printf_key (& trace_deserialize , "reject: show_ignored_mode: command: %d, serialized: %d" ,
495
525
cmd_s -> show_ignored_mode ,
496
526
s -> show_ignored_mode );
@@ -524,6 +554,7 @@ static int wt_deserialize_v1(const struct wt_status *cmd_s, struct wt_status *s,
524
554
return DESERIALIZE_ERR ;
525
555
continue ;
526
556
}
557
+ set_deserialize_reject_reason ("v1-data/unexpected-line" );
527
558
trace_printf_key (& trace_deserialize , "unexpected line '%s'" , line );
528
559
return DESERIALIZE_ERR ;
529
560
}
@@ -543,6 +574,7 @@ static int wt_deserialize_parse(const struct wt_status *cmd_s, struct wt_status
543
574
if (version == 1 )
544
575
return wt_deserialize_v1 (cmd_s , s , fd );
545
576
}
577
+ set_deserialize_reject_reason ("status-cache/unsupported-version" );
546
578
trace_printf_key (& trace_deserialize , "missing/unsupported version" );
547
579
return DESERIALIZE_ERR ;
548
580
}
@@ -563,6 +595,7 @@ static int wt_deserialize_fd(const struct wt_status *cmd_s, struct wt_status *de
563
595
* Check the path spec on the current command
564
596
*/
565
597
if (cmd_s -> pathspec .nr > 1 ) {
598
+ set_deserialize_reject_reason ("args/multiple-pathspecs" );
566
599
trace_printf_key (& trace_deserialize , "reject: multiple pathspecs" );
567
600
return DESERIALIZE_ERR ;
568
601
}
@@ -573,6 +606,7 @@ static int wt_deserialize_fd(const struct wt_status *cmd_s, struct wt_status *de
573
606
*/
574
607
if (cmd_s -> pathspec .nr == 1 &&
575
608
my_strcmp_null (cmd_s -> pathspec .items [0 ].match , "" )) {
609
+ set_deserialize_reject_reason ("args/root-pathspec" );
576
610
trace_printf_key (& trace_deserialize , "reject: pathspec" );
577
611
return DESERIALIZE_ERR ;
578
612
}
@@ -595,20 +629,24 @@ static int wt_deserialize_fd(const struct wt_status *cmd_s, struct wt_status *de
595
629
* or "--ignored" settings).
596
630
*/
597
631
if (cmd_s -> is_initial != des_s -> is_initial ) {
632
+ set_deserialize_reject_reason ("args/is-initial-changed" );
598
633
trace_printf_key (& trace_deserialize , "reject: is_initial" );
599
634
return DESERIALIZE_ERR ;
600
635
}
601
636
if (my_strcmp_null (cmd_s -> branch , des_s -> branch )) {
637
+ set_deserialize_reject_reason ("args/branch-changed" );
602
638
trace_printf_key (& trace_deserialize , "reject: branch" );
603
639
return DESERIALIZE_ERR ;
604
640
}
605
641
if (my_strcmp_null (cmd_s -> reference , des_s -> reference )) {
642
+ set_deserialize_reject_reason ("args/reference-changed" );
606
643
trace_printf_key (& trace_deserialize , "reject: reference" );
607
644
return DESERIALIZE_ERR ;
608
645
}
609
646
/* verbose */
610
647
/* amend */
611
648
if (cmd_s -> whence != des_s -> whence ) {
649
+ set_deserialize_reject_reason ("args/whence-changed" );
612
650
trace_printf_key (& trace_deserialize , "reject: whence" );
613
651
return DESERIALIZE_ERR ;
614
652
}
@@ -642,19 +680,23 @@ static int wt_deserialize_fd(const struct wt_status *cmd_s, struct wt_status *de
642
680
/* hints */
643
681
/* ahead_behind_flags */
644
682
if (cmd_s -> detect_rename != des_s -> detect_rename ) {
683
+ set_deserialize_reject_reason ("args/detect-rename-changed" );
645
684
trace_printf_key (& trace_deserialize , "reject: detect_rename" );
646
685
return DESERIALIZE_ERR ;
647
686
}
648
687
if (cmd_s -> rename_score != des_s -> rename_score ) {
688
+ set_deserialize_reject_reason ("args/rename-score-changed" );
649
689
trace_printf_key (& trace_deserialize , "reject: rename_score" );
650
690
return DESERIALIZE_ERR ;
651
691
}
652
692
if (cmd_s -> rename_limit != des_s -> rename_limit ) {
693
+ set_deserialize_reject_reason ("args/rename-limit-changed" );
653
694
trace_printf_key (& trace_deserialize , "reject: rename_limit" );
654
695
return DESERIALIZE_ERR ;
655
696
}
656
697
/* status_format */
657
698
if (!oideq (& cmd_s -> oid_commit , & des_s -> oid_commit )) {
699
+ set_deserialize_reject_reason ("args/commit-changed" );
658
700
trace_printf_key (& trace_deserialize , "reject: sha1_commit" );
659
701
return DESERIALIZE_ERR ;
660
702
}
@@ -742,15 +784,18 @@ static int try_deserialize_read_from_file(const struct wt_status *cmd_s,
742
784
enum wt_status_deserialize_wait dw ,
743
785
struct wt_status * des_s )
744
786
{
745
- int k , limit ;
787
+ int k = 0 ;
788
+ int limit ;
746
789
int result = DESERIALIZE_ERR ;
747
790
748
791
/*
749
792
* For "fail" or "no", try exactly once to read the status cache.
750
793
* Return an error if the file is stale.
751
794
*/
752
- if (dw == DESERIALIZE_WAIT__FAIL || dw == DESERIALIZE_WAIT__NO )
753
- return try_deserialize_read_from_file_1 (cmd_s , path , des_s );
795
+ if (dw == DESERIALIZE_WAIT__FAIL || dw == DESERIALIZE_WAIT__NO ) {
796
+ result = try_deserialize_read_from_file_1 (cmd_s , path , des_s );
797
+ goto done ;
798
+ }
754
799
755
800
/*
756
801
* Wait for the status cache file to refresh. Wait duration can
@@ -775,6 +820,12 @@ static int try_deserialize_read_from_file(const struct wt_status *cmd_s,
775
820
sleep_millisec (100 );
776
821
}
777
822
823
+ done :
824
+ trace2_data_string ("status" , the_repository , "deserialize/path" , path );
825
+ trace2_data_intmax ("status" , the_repository , "deserialize/polled" , k );
826
+ trace2_data_string ("status" , the_repository , "deserialize/result" ,
827
+ ((result == DESERIALIZE_OK ) ? "ok" : "reject" ));
828
+
778
829
trace_printf_key (& trace_deserialize ,
779
830
"wait polled=%d result=%d '%s'" ,
780
831
k , result , path );
@@ -801,6 +852,8 @@ int wt_status_deserialize(const struct wt_status *cmd_s,
801
852
int result ;
802
853
struct string_list_item * change ;
803
854
855
+ trace2_region_enter ("status" , "deserialize" , the_repository );
856
+
804
857
if (path && * path && strcmp (path , "0" )) {
805
858
result = try_deserialize_read_from_file (cmd_s , path , dw , & des_s );
806
859
} else {
@@ -811,8 +864,14 @@ int wt_status_deserialize(const struct wt_status *cmd_s,
811
864
* term, since we cannot read stdin multiple times.
812
865
*/
813
866
result = wt_deserialize_fd (cmd_s , & des_s , 0 );
867
+
868
+ trace2_data_string ("status" , the_repository , "deserialize/path" , "STDIN" );
869
+ trace2_data_string ("status" , the_repository , "deserialize/result" ,
870
+ ((result == DESERIALIZE_OK ) ? "ok" : "reject" ));
814
871
}
815
872
873
+ trace2_region_leave ("status" , "deserialize" , the_repository );
874
+
816
875
if (result == DESERIALIZE_OK ) {
817
876
wt_status_get_state (cmd_s -> repo , & des_s .state , des_s .branch &&
818
877
!strcmp (des_s .branch , "HEAD" ));
0 commit comments