@@ -35,6 +35,15 @@ static int mark_skip_worktree_only;
3535#define UNMARK_FLAG 2
3636static struct strbuf mtime_dir = STRBUF_INIT ;
3737
38+ /* Untracked cache mode */
39+ enum uc_mode {
40+ UC_UNSPECIFIED = -1 ,
41+ UC_DISABLE = 0 ,
42+ UC_ENABLE ,
43+ UC_TEST ,
44+ UC_FORCE
45+ };
46+
3847__attribute__((format (printf , 1 , 2 )))
3948static void report (const char * fmt , ...)
4049{
@@ -121,7 +130,7 @@ static int test_if_untracked_cache_is_supported(void)
121130 if (!mkdtemp (mtime_dir .buf ))
122131 die_errno ("Could not make temporary directory" );
123132
124- fprintf (stderr , _ ("Testing " ));
133+ fprintf (stderr , _ ("Testing mtime in '%s' " ), xgetcwd ( ));
125134 atexit (remove_test_directory );
126135 xstat_mtime_dir (& st );
127136 fill_stat_data (& base , & st );
@@ -904,7 +913,7 @@ static int reupdate_callback(struct parse_opt_ctx_t *ctx,
904913int cmd_update_index (int argc , const char * * argv , const char * prefix )
905914{
906915 int newfd , entries , has_errors = 0 , nul_term_line = 0 ;
907- int untracked_cache = -1 ;
916+ enum uc_mode untracked_cache = UC_UNSPECIFIED ;
908917 int read_from_stdin = 0 ;
909918 int prefix_length = prefix ? strlen (prefix ) : 0 ;
910919 int preferred_index_format = 0 ;
@@ -999,8 +1008,10 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
9991008 N_ ("enable or disable split index" )),
10001009 OPT_BOOL (0 , "untracked-cache" , & untracked_cache ,
10011010 N_ ("enable/disable untracked cache" )),
1011+ OPT_SET_INT (0 , "test-untracked-cache" , & untracked_cache ,
1012+ N_ ("test if the filesystem supports untracked cache" ), UC_TEST ),
10021013 OPT_SET_INT (0 , "force-untracked-cache" , & untracked_cache ,
1003- N_ ("enable untracked cache without testing the filesystem" ), 2 ),
1014+ N_ ("enable untracked cache without testing the filesystem" ), UC_FORCE ),
10041015 OPT_END ()
10051016 };
10061017
@@ -1109,27 +1120,32 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11091120 the_index .split_index = NULL ;
11101121 the_index .cache_changed |= SOMETHING_CHANGED ;
11111122 }
1112- if (untracked_cache > 0 ) {
1113- struct untracked_cache * uc ;
11141123
1115- if (untracked_cache < 2 ) {
1116- setup_work_tree ();
1117- if (!test_if_untracked_cache_is_supported ())
1118- return 1 ;
1119- }
1120- if (!the_index .untracked ) {
1121- uc = xcalloc (1 , sizeof (* uc ));
1122- strbuf_init (& uc -> ident , 100 );
1123- uc -> exclude_per_dir = ".gitignore" ;
1124- /* should be the same flags used by git-status */
1125- uc -> dir_flags = DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES ;
1126- the_index .untracked = uc ;
1127- }
1128- add_untracked_ident (the_index .untracked );
1129- the_index .cache_changed |= UNTRACKED_CHANGED ;
1130- } else if (!untracked_cache && the_index .untracked ) {
1131- the_index .untracked = NULL ;
1132- the_index .cache_changed |= UNTRACKED_CHANGED ;
1124+ switch (untracked_cache ) {
1125+ case UC_UNSPECIFIED :
1126+ break ;
1127+ case UC_DISABLE :
1128+ if (git_config_get_untracked_cache () == 1 )
1129+ warning ("core.untrackedCache is set to true; "
1130+ "remove or change it, if you really want to "
1131+ "disable the untracked cache" );
1132+ remove_untracked_cache (& the_index );
1133+ report (_ ("Untracked cache disabled" ));
1134+ break ;
1135+ case UC_TEST :
1136+ setup_work_tree ();
1137+ return !test_if_untracked_cache_is_supported ();
1138+ case UC_ENABLE :
1139+ case UC_FORCE :
1140+ if (git_config_get_untracked_cache () == 0 )
1141+ warning ("core.untrackedCache is set to false; "
1142+ "remove or change it, if you really want to "
1143+ "enable the untracked cache" );
1144+ add_untracked_cache (& the_index );
1145+ report (_ ("Untracked cache enabled for '%s'" ), get_git_work_tree ());
1146+ break ;
1147+ default :
1148+ die ("Bug: bad untracked_cache value: %d" , untracked_cache );
11331149 }
11341150
11351151 if (active_cache_changed ) {
0 commit comments