Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 28659e5

Browse files
committed
diff: refactor complex timestamp check into its own function
1 parent 973a09a commit 28659e5

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/diff.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static bool diff_pathspec_match(
7979
git_diff *diff,
8080
const git_index_entry *entry)
8181
{
82-
bool disable_pathspec_match =
82+
bool disable_pathspec_match =
8383
DIFF_FLAG_IS_SET(diff, GIT_DIFF_DISABLE_PATHSPEC_MATCH);
8484

8585
/* If we're disabling fnmatch, then the iterator has already applied
@@ -703,6 +703,31 @@ static bool diff_time_eq(
703703
(!use_nanos || a->nanoseconds == b->nanoseconds);
704704
}
705705

706+
/*
707+
* Test if the given index time is newer than the given existing index entry.
708+
* If the timestamps are exactly equivalent, then the given index time is
709+
* considered "racily newer" than the existing index entry.
710+
*/
711+
static bool diff_newer_than_index(
712+
const git_index_time *a, const git_index *b, bool use_nanos)
713+
{
714+
bool is_newer = false;
715+
716+
if(!b)
717+
return false;
718+
719+
is_newer = is_newer || (a->seconds > (int32_t) b->stamp.mtime.tv_sec);
720+
is_newer = is_newer || (!use_nanos &&
721+
(a->seconds == (int32_t) b->stamp.mtime.tv_sec));
722+
if(use_nanos)
723+
{
724+
is_newer = is_newer || ((a->seconds == (int32_t) b->stamp.mtime.tv_sec) &&
725+
(a->nanoseconds >= (uint32_t) b->stamp.mtime.tv_nsec));
726+
}
727+
728+
return is_newer;
729+
}
730+
706731
typedef struct {
707732
git_repository *repo;
708733
git_iterator *old_iter;
@@ -864,10 +889,7 @@ static int maybe_modified(
864889
oitem->ino != nitem->ino ||
865890
oitem->uid != nitem->uid ||
866891
oitem->gid != nitem->gid ||
867-
(index &&
868-
((nitem->mtime.seconds > (int32_t) index->stamp.mtime.tv_sec) ||
869-
((nitem->mtime.seconds == (int32_t) index->stamp.mtime.tv_sec) &&
870-
(nitem->mtime.nanoseconds >= (uint32_t) index->stamp.mtime.tv_nsec)))))
892+
diff_newer_than_index(&nitem->mtime, index, use_nanos))
871893
{
872894
status = GIT_DELTA_MODIFIED;
873895
modified_uncertain = true;

0 commit comments

Comments
 (0)