@@ -26,7 +26,6 @@ int read_fsmonitor_extension(struct index_state *istate, const void *data,
2626 uint32_t hdr_version ;
2727 uint32_t ewah_size ;
2828 struct ewah_bitmap * fsmonitor_dirty ;
29- int i ;
3029 int ret ;
3130
3231 if (sz < sizeof (uint32_t ) + sizeof (uint64_t ) + sizeof (uint32_t ))
@@ -49,31 +48,25 @@ int read_fsmonitor_extension(struct index_state *istate, const void *data,
4948 ewah_free (fsmonitor_dirty );
5049 return error ("failed to parse ewah bitmap reading fsmonitor index extension" );
5150 }
52-
53- if (git_config_get_fsmonitor ()) {
54- /* Mark all entries valid */
55- for (i = 0 ; i < istate -> cache_nr ; i ++ )
56- istate -> cache [i ]-> ce_flags |= CE_FSMONITOR_VALID ;
57-
58- /* Mark all previously saved entries as dirty */
59- ewah_each_bit (fsmonitor_dirty , fsmonitor_ewah_callback , istate );
60-
61- /* Now mark the untracked cache for fsmonitor usage */
62- if (istate -> untracked )
63- istate -> untracked -> use_fsmonitor = 1 ;
64- }
65- ewah_free (fsmonitor_dirty );
51+ istate -> fsmonitor_dirty = fsmonitor_dirty ;
6652
6753 trace_printf_key (& trace_fsmonitor , "read fsmonitor extension successful" );
6854 return 0 ;
6955}
7056
57+ void fill_fsmonitor_bitmap (struct index_state * istate )
58+ {
59+ int i ;
60+ istate -> fsmonitor_dirty = ewah_new ();
61+ for (i = 0 ; i < istate -> cache_nr ; i ++ )
62+ if (!(istate -> cache [i ]-> ce_flags & CE_FSMONITOR_VALID ))
63+ ewah_set (istate -> fsmonitor_dirty , i );
64+ }
65+
7166void write_fsmonitor_extension (struct strbuf * sb , struct index_state * istate )
7267{
7368 uint32_t hdr_version ;
7469 uint64_t tm ;
75- struct ewah_bitmap * bitmap ;
76- int i ;
7770 uint32_t ewah_start ;
7871 uint32_t ewah_size = 0 ;
7972 int fixup = 0 ;
@@ -87,12 +80,9 @@ void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate)
8780 strbuf_add (sb , & ewah_size , sizeof (uint32_t )); /* we'll fix this up later */
8881
8982 ewah_start = sb -> len ;
90- bitmap = ewah_new ();
91- for (i = 0 ; i < istate -> cache_nr ; i ++ )
92- if (!(istate -> cache [i ]-> ce_flags & CE_FSMONITOR_VALID ))
93- ewah_set (bitmap , i );
94- ewah_serialize_strbuf (bitmap , sb );
95- ewah_free (bitmap );
83+ ewah_serialize_strbuf (istate -> fsmonitor_dirty , sb );
84+ ewah_free (istate -> fsmonitor_dirty );
85+ istate -> fsmonitor_dirty = NULL ;
9686
9787 /* fix up size field */
9888 put_be32 (& ewah_size , sb -> len - ewah_start );
@@ -121,6 +111,7 @@ static int query_fsmonitor(int version, uint64_t last_update, struct strbuf *que
121111 argv [3 ] = NULL ;
122112 cp .argv = argv ;
123113 cp .use_shell = 1 ;
114+ cp .dir = get_git_work_tree ();
124115
125116 return capture_command (& cp , query_result , 1024 );
126117}
@@ -238,7 +229,29 @@ void remove_fsmonitor(struct index_state *istate)
238229
239230void tweak_fsmonitor (struct index_state * istate )
240231{
241- switch (git_config_get_fsmonitor ()) {
232+ int i ;
233+ int fsmonitor_enabled = git_config_get_fsmonitor ();
234+
235+ if (istate -> fsmonitor_dirty ) {
236+ if (fsmonitor_enabled ) {
237+ /* Mark all entries valid */
238+ for (i = 0 ; i < istate -> cache_nr ; i ++ ) {
239+ istate -> cache [i ]-> ce_flags |= CE_FSMONITOR_VALID ;
240+ }
241+
242+ /* Mark all previously saved entries as dirty */
243+ ewah_each_bit (istate -> fsmonitor_dirty , fsmonitor_ewah_callback , istate );
244+
245+ /* Now mark the untracked cache for fsmonitor usage */
246+ if (istate -> untracked )
247+ istate -> untracked -> use_fsmonitor = 1 ;
248+ }
249+
250+ ewah_free (istate -> fsmonitor_dirty );
251+ istate -> fsmonitor_dirty = NULL ;
252+ }
253+
254+ switch (fsmonitor_enabled ) {
242255 case -1 : /* keep: do nothing */
243256 break ;
244257 case 0 : /* false */
0 commit comments