6
6
#include "wt-status.h"
7
7
#include "pkt-line.h"
8
8
#include "trace.h"
9
+ #include "trace2.h"
10
+
11
+ static void set_deserialize_reject_reason (const char * reason )
12
+ {
13
+ trace2_data_string ("status" , the_repository , "deserialize/reject" ,
14
+ reason );
15
+ }
16
+
17
+ int wt_status_deserialize_access (const char * path , int mode )
18
+ {
19
+ int a = access (path , mode );
20
+
21
+ if (a != 0 )
22
+ set_deserialize_reject_reason ("status-cache/access" );
23
+
24
+ return a ;
25
+ }
9
26
10
27
static struct trace_key trace_deserialize = TRACE_KEY_INIT (DESERIALIZE );
11
28
@@ -53,13 +70,15 @@ static int my_validate_index(const struct cache_time *mtime_reported)
53
70
struct cache_time mtime_observed_on_disk ;
54
71
55
72
if (lstat (path , & st )) {
73
+ set_deserialize_reject_reason ("index/not-found" );
56
74
trace_printf_key (& trace_deserialize , "could not stat index" );
57
75
return DESERIALIZE_ERR ;
58
76
}
59
77
mtime_observed_on_disk .sec = st .st_mtime ;
60
78
mtime_observed_on_disk .nsec = ST_MTIME_NSEC (st );
61
79
if ((mtime_observed_on_disk .sec != mtime_reported -> sec ) ||
62
80
(mtime_observed_on_disk .nsec != mtime_reported -> nsec )) {
81
+ set_deserialize_reject_reason ("index/mtime-changed" );
63
82
trace_printf_key (& trace_deserialize ,
64
83
"index mtime changed [des %d %d][obs %d %d]" ,
65
84
mtime_reported -> sec , mtime_reported -> nsec ,
@@ -85,10 +104,12 @@ static int my_validate_excludes(const char *path, const char *key, const char *l
85
104
86
105
r = (strcmp (line , sb .buf ) ? DESERIALIZE_ERR : DESERIALIZE_OK );
87
106
88
- if (r == DESERIALIZE_ERR )
107
+ if (r == DESERIALIZE_ERR ) {
108
+ set_deserialize_reject_reason ("excludes/changed" );
89
109
trace_printf_key (& trace_deserialize ,
90
110
"%s changed [cached '%s'][observed '%s']" ,
91
111
key , line , sb .buf );
112
+ }
92
113
93
114
strbuf_release (& sb );
94
115
return r ;
@@ -144,6 +165,7 @@ static int wt_deserialize_v1_header(struct wt_status *s, int fd)
144
165
& index_mtime .sec ,
145
166
& index_mtime .nsec );
146
167
if (nr_fields != 2 ) {
168
+ set_deserialize_reject_reason ("v1-header/invalid-index-mtime" );
147
169
trace_printf_key (& trace_deserialize , "invalid index_mtime (%d) '%s'" ,
148
170
nr_fields , line );
149
171
return DESERIALIZE_ERR ;
@@ -227,6 +249,7 @@ static int wt_deserialize_v1_header(struct wt_status *s, int fd)
227
249
/* status_format */
228
250
if (skip_prefix (line , "sha1_commit " , & arg )) {
229
251
if (get_oid_hex (arg , & s -> oid_commit )) {
252
+ set_deserialize_reject_reason ("v1-header/invalid-commit-sha" );
230
253
trace_printf_key (& trace_deserialize , "invalid sha1_commit" );
231
254
return DESERIALIZE_ERR ;
232
255
}
@@ -242,19 +265,23 @@ static int wt_deserialize_v1_header(struct wt_status *s, int fd)
242
265
}
243
266
/* prefix */
244
267
268
+ set_deserialize_reject_reason ("v1-header/unexpected-line" );
245
269
trace_printf_key (& trace_deserialize , "unexpected line '%s'" , line );
246
270
return DESERIALIZE_ERR ;
247
271
}
248
272
249
273
if (!have_required_index_mtime ) {
274
+ set_deserialize_reject_reason ("v1-header/missing-index-mtime" );
250
275
trace_printf_key (& trace_deserialize , "missing '%s'" , "index_mtime" );
251
276
return DESERIALIZE_ERR ;
252
277
}
253
278
if (!have_required_core_excludes ) {
279
+ set_deserialize_reject_reason ("v1-header/missing-core-excludes" );
254
280
trace_printf_key (& trace_deserialize , "missing '%s'" , "core_excludes" );
255
281
return DESERIALIZE_ERR ;
256
282
}
257
283
if (!have_required_repo_excludes ) {
284
+ set_deserialize_reject_reason ("v1-header/missing-repo-excludes" );
258
285
trace_printf_key (& trace_deserialize , "missing '%s'" , "repo_excludes" );
259
286
return DESERIALIZE_ERR ;
260
287
}
@@ -341,6 +368,7 @@ static int wt_deserialize_v1_changed_items(const struct wt_status *cmd_s,
341
368
* So we reject the status cache and let the fallback
342
369
* code run.
343
370
*/
371
+ set_deserialize_reject_reason ("v1-data/unmerged" );
344
372
trace_printf_key (
345
373
& trace_deserialize ,
346
374
"reject: V2 format and umerged file: %s" ,
@@ -482,13 +510,15 @@ static int wt_deserialize_v1(const struct wt_status *cmd_s, struct wt_status *s,
482
510
* the serialized data
483
511
*/
484
512
if (validate_untracked_files_arg (cmd_s -> show_untracked_files , & s -> show_untracked_files , & untracked_strategy )) {
513
+ set_deserialize_reject_reason ("args/untracked-files" );
485
514
trace_printf_key (& trace_deserialize , "reject: show_untracked_file: command: %d, serialized : %d" ,
486
515
cmd_s -> show_untracked_files ,
487
516
s -> show_untracked_files );
488
517
return DESERIALIZE_ERR ;
489
518
}
490
519
491
520
if (validate_ignored_files_arg (cmd_s -> show_ignored_mode , s -> show_ignored_mode , & ignored_strategy )) {
521
+ set_deserialize_reject_reason ("args/ignored-mode" );
492
522
trace_printf_key (& trace_deserialize , "reject: show_ignored_mode: command: %d, serialized: %d" ,
493
523
cmd_s -> show_ignored_mode ,
494
524
s -> show_ignored_mode );
@@ -522,6 +552,7 @@ static int wt_deserialize_v1(const struct wt_status *cmd_s, struct wt_status *s,
522
552
return DESERIALIZE_ERR ;
523
553
continue ;
524
554
}
555
+ set_deserialize_reject_reason ("v1-data/unexpected-line" );
525
556
trace_printf_key (& trace_deserialize , "unexpected line '%s'" , line );
526
557
return DESERIALIZE_ERR ;
527
558
}
@@ -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
}
@@ -589,20 +623,24 @@ static int wt_deserialize_fd(const struct wt_status *cmd_s, struct wt_status *de
589
623
* or "--ignored" settings).
590
624
*/
591
625
if (cmd_s -> is_initial != des_s -> is_initial ) {
626
+ set_deserialize_reject_reason ("args/is-initial-changed" );
592
627
trace_printf_key (& trace_deserialize , "reject: is_initial" );
593
628
return DESERIALIZE_ERR ;
594
629
}
595
630
if (my_strcmp_null (cmd_s -> branch , des_s -> branch )) {
631
+ set_deserialize_reject_reason ("args/branch-changed" );
596
632
trace_printf_key (& trace_deserialize , "reject: branch" );
597
633
return DESERIALIZE_ERR ;
598
634
}
599
635
if (my_strcmp_null (cmd_s -> reference , des_s -> reference )) {
636
+ set_deserialize_reject_reason ("args/reference-changed" );
600
637
trace_printf_key (& trace_deserialize , "reject: reference" );
601
638
return DESERIALIZE_ERR ;
602
639
}
603
640
/* verbose */
604
641
/* amend */
605
642
if (cmd_s -> whence != des_s -> whence ) {
643
+ set_deserialize_reject_reason ("args/whence-changed" );
606
644
trace_printf_key (& trace_deserialize , "reject: whence" );
607
645
return DESERIALIZE_ERR ;
608
646
}
@@ -636,19 +674,23 @@ static int wt_deserialize_fd(const struct wt_status *cmd_s, struct wt_status *de
636
674
/* hints */
637
675
/* ahead_behind_flags */
638
676
if (cmd_s -> detect_rename != des_s -> detect_rename ) {
677
+ set_deserialize_reject_reason ("args/detect-rename-changed" );
639
678
trace_printf_key (& trace_deserialize , "reject: detect_rename" );
640
679
return DESERIALIZE_ERR ;
641
680
}
642
681
if (cmd_s -> rename_score != des_s -> rename_score ) {
682
+ set_deserialize_reject_reason ("args/rename-score-changed" );
643
683
trace_printf_key (& trace_deserialize , "reject: rename_score" );
644
684
return DESERIALIZE_ERR ;
645
685
}
646
686
if (cmd_s -> rename_limit != des_s -> rename_limit ) {
687
+ set_deserialize_reject_reason ("args/rename-limit-changed" );
647
688
trace_printf_key (& trace_deserialize , "reject: rename_limit" );
648
689
return DESERIALIZE_ERR ;
649
690
}
650
691
/* status_format */
651
692
if (!oideq (& cmd_s -> oid_commit , & des_s -> oid_commit )) {
693
+ set_deserialize_reject_reason ("args/commit-changed" );
652
694
trace_printf_key (& trace_deserialize , "reject: sha1_commit" );
653
695
return DESERIALIZE_ERR ;
654
696
}
@@ -737,15 +779,18 @@ static int try_deserialize_read_from_file(const struct wt_status *cmd_s,
737
779
enum wt_status_deserialize_wait dw ,
738
780
struct wt_status * des_s )
739
781
{
740
- int k , limit ;
782
+ int k = 0 ;
783
+ int limit ;
741
784
int result = DESERIALIZE_ERR ;
742
785
743
786
/*
744
787
* For "fail" or "no", try exactly once to read the status cache.
745
788
* Return an error if the file is stale.
746
789
*/
747
- if (dw == DESERIALIZE_WAIT__FAIL || dw == DESERIALIZE_WAIT__NO )
748
- return try_deserialize_read_from_file_1 (cmd_s , path , des_s );
790
+ if (dw == DESERIALIZE_WAIT__FAIL || dw == DESERIALIZE_WAIT__NO ) {
791
+ result = try_deserialize_read_from_file_1 (cmd_s , path , des_s );
792
+ goto done ;
793
+ }
749
794
750
795
/*
751
796
* Wait for the status cache file to refresh. Wait duration can
@@ -770,6 +815,12 @@ static int try_deserialize_read_from_file(const struct wt_status *cmd_s,
770
815
sleep_millisec (100 );
771
816
}
772
817
818
+ done :
819
+ trace2_data_string ("status" , the_repository , "deserialize/path" , path );
820
+ trace2_data_intmax ("status" , the_repository , "deserialize/polled" , k );
821
+ trace2_data_string ("status" , the_repository , "deserialize/result" ,
822
+ ((result == DESERIALIZE_OK ) ? "ok" : "reject" ));
823
+
773
824
trace_printf_key (& trace_deserialize ,
774
825
"wait polled=%d result=%d '%s'" ,
775
826
k , result , path );
@@ -795,6 +846,8 @@ int wt_status_deserialize(const struct wt_status *cmd_s,
795
846
struct wt_status des_s ;
796
847
int result ;
797
848
849
+ trace2_region_enter ("status" , "deserialize" , the_repository );
850
+
798
851
if (path && * path && strcmp (path , "0" )) {
799
852
result = try_deserialize_read_from_file (cmd_s , path , dw , & des_s );
800
853
} else {
@@ -805,8 +858,14 @@ int wt_status_deserialize(const struct wt_status *cmd_s,
805
858
* term, since we cannot read stdin multiple times.
806
859
*/
807
860
result = wt_deserialize_fd (cmd_s , & des_s , 0 );
861
+
862
+ trace2_data_string ("status" , the_repository , "deserialize/path" , "STDIN" );
863
+ trace2_data_string ("status" , the_repository , "deserialize/result" ,
864
+ ((result == DESERIALIZE_OK ) ? "ok" : "reject" ));
808
865
}
809
866
867
+ trace2_region_leave ("status" , "deserialize" , the_repository );
868
+
810
869
if (result == DESERIALIZE_OK ) {
811
870
wt_status_get_state (cmd_s -> repo , & des_s .state , des_s .branch &&
812
871
!strcmp (des_s .branch , "HEAD" ));
0 commit comments