@@ -105,36 +105,29 @@ static void setup_race(void)
105
105
{
106
106
git_buf path = GIT_BUF_INIT ;
107
107
git_index * index ;
108
- const git_index_entry * entry ;
109
- int i , found_race = 0 ;
108
+ git_index_entry * entry ;
109
+ struct stat st ;
110
110
111
111
/* Make sure we do have a timestamp */
112
112
cl_git_pass (git_repository_index__weakptr (& index , g_repo ));
113
113
cl_git_pass (git_index_write (index ));
114
114
115
115
cl_git_pass (git_buf_joinpath (& path , git_repository_workdir (g_repo ), "A" ));
116
116
117
- /* Make sure writing the file, adding and rewriting happen in the same second */
118
- for (i = 0 ; i < 10 ; i ++ ) {
119
- struct stat st ;
120
- cl_git_mkfile (path .ptr , "A" );
117
+ cl_git_mkfile (path .ptr , "A" );
118
+ cl_git_pass (git_index_add_bypath (index , "A" ));
121
119
122
- cl_git_pass (git_index_add_bypath (index , "A" ));
123
- cl_git_mkfile (path .ptr , "B" );
124
- cl_git_pass (git_index_write (index ));
120
+ cl_git_mkfile (path .ptr , "B" );
121
+ cl_git_pass (git_index_write (index ));
125
122
126
- cl_git_mkfile (path .ptr , "" );
123
+ cl_git_mkfile (path .ptr , "" );
127
124
128
- cl_git_pass (p_stat (path .ptr , & st ));
129
- cl_assert (entry = git_index_get_bypath (index , "A" , 0 ));
130
- if (entry -> mtime .seconds == (int32_t ) st .st_mtime ) {
131
- found_race = 1 ;
132
- break ;
133
- }
134
- }
125
+ cl_git_pass (p_stat (path .ptr , & st ));
126
+ cl_assert (entry = (git_index_entry * )git_index_get_bypath (index , "A" , 0 ));
135
127
136
- if (!found_race )
137
- cl_fail ("failed to find race after 10 attempts" );
128
+ /* force a race */
129
+ entry -> mtime .seconds = st .st_mtime ;
130
+ entry -> mtime .nanoseconds = st .st_mtime_nsec ;
138
131
139
132
git_buf_free (& path );
140
133
}
0 commit comments