@@ -719,18 +719,27 @@ int git_index__changed_relative_to(
719
719
return !!git_oid_cmp (& index -> checksum , checksum );
720
720
}
721
721
722
- static bool is_racy_timestamp (git_time_t stamp , git_index_entry * entry )
722
+ static bool is_racy_timestamp (const struct timespec * stamp , git_index_entry * entry )
723
723
{
724
724
/* Git special-cases submodules in the check */
725
725
if (S_ISGITLINK (entry -> mode ))
726
726
return false;
727
727
728
728
/* If we never read the index, we can't have this race either */
729
- if (stamp == 0 )
729
+ if (stamp -> tv_sec == 0 )
730
730
return false;
731
731
732
732
/* If the timestamp is the same or newer than the index, it's racy */
733
- return ((int32_t ) stamp ) <= entry -> mtime .seconds ;
733
+ #if defined(GIT_USE_NSEC )
734
+ if ((int32_t ) stamp -> tv_sec < entry -> mtime .seconds )
735
+ return true;
736
+ else if ((int32_t ) stamp -> tv_sec > entry -> mtime .seconds )
737
+ return false;
738
+ else
739
+ return (uint32_t ) stamp -> tv_nsec <= entry -> mtime .nanoseconds ;
740
+ #else
741
+ return ((int32_t ) stamp -> tv_sec ) <= entry -> mtime .seconds ;
742
+ #endif
734
743
}
735
744
736
745
/*
@@ -742,7 +751,6 @@ static int truncate_racily_clean(git_index *index)
742
751
size_t i ;
743
752
int error ;
744
753
git_index_entry * entry ;
745
- git_time_t ts = index -> stamp .mtime ;
746
754
git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT ;
747
755
git_diff * diff ;
748
756
@@ -756,7 +764,7 @@ static int truncate_racily_clean(git_index *index)
756
764
757
765
diff_opts .flags |= GIT_DIFF_INCLUDE_TYPECHANGE | GIT_DIFF_IGNORE_SUBMODULES | GIT_DIFF_DISABLE_PATHSPEC_MATCH ;
758
766
git_vector_foreach (& index -> entries , i , entry ) {
759
- if (!is_racy_timestamp (ts , entry ))
767
+ if (!is_racy_timestamp (& index -> stamp . mtime , entry ))
760
768
continue ;
761
769
762
770
/* TODO: use the (non-fnmatching) filelist iterator */
@@ -858,8 +866,10 @@ void git_index_entry__init_from_stat(
858
866
{
859
867
entry -> ctime .seconds = (git_time_t )st -> st_ctime ;
860
868
entry -> mtime .seconds = (git_time_t )st -> st_mtime ;
861
- /* entry->mtime.nanoseconds = st->st_mtimensec; */
862
- /* entry->ctime.nanoseconds = st->st_ctimensec; */
869
+ #if defined(GIT_USE_NSEC )
870
+ entry -> mtime .nanoseconds = st -> st_mtim .tv_nsec ;
871
+ entry -> ctime .nanoseconds = st -> st_ctim .tv_nsec ;
872
+ #endif
863
873
entry -> dev = st -> st_rdev ;
864
874
entry -> ino = st -> st_ino ;
865
875
entry -> mode = (!trust_mode && S_ISREG (st -> st_mode )) ?
@@ -2924,9 +2934,9 @@ int git_index_read_index(
2924
2934
(error = git_iterator_for_index (& new_iterator , (git_index * )new_index , & opts )) < 0 )
2925
2935
goto done ;
2926
2936
2927
- if (((error = git_iterator_current (& old_entry , index_iterator )) < 0 &&
2937
+ if (((error = git_iterator_current (& old_entry , index_iterator )) < 0 &&
2928
2938
error != GIT_ITEROVER ) ||
2929
- ((error = git_iterator_current (& new_entry , new_iterator )) < 0 &&
2939
+ ((error = git_iterator_current (& new_entry , new_iterator )) < 0 &&
2930
2940
error != GIT_ITEROVER ))
2931
2941
goto done ;
2932
2942
0 commit comments