{
ce->ce_ctime.sec = (unsigned int)st->st_ctime;
ce->ce_mtime.sec = (unsigned int)st->st_mtime;
-#ifdef USE_NSEC
- ce->ce_ctime.nsec = (unsigned int)st->st_ctim.tv_nsec;
- ce->ce_mtime.nsec = (unsigned int)st->st_mtim.tv_nsec;
-#else
- ce->ce_ctime.nsec = 0;
- ce->ce_mtime.nsec = 0;
-#endif
+ ce->ce_ctime.nsec = ST_CTIME_NSEC(*st);
+ ce->ce_mtime.nsec = ST_MTIME_NSEC(*st);
ce->ce_dev = st->st_dev;
ce->ce_ino = st->st_ino;
ce->ce_uid = st->st_uid;
changed |= CTIME_CHANGED;
#ifdef USE_NSEC
- if (ce->ce_mtime.nsec != (unsigned int)st->st_mtim.tv_nsec)
+ if (ce->ce_mtime.nsec != ST_MTIME_NSEC(*st))
changed |= MTIME_CHANGED;
- if (trust_ctime && ce->ce_ctime.nsec != (unsigned int)st->st_ctim.tv_nsec)
+ if (trust_ctime && ce->ce_ctime.nsec != ST_CTIME_NSEC(*st))
changed |= CTIME_CHANGED;
#endif
ce->ce_ctime.sec = ntohl(ondisk->ctime.sec);
ce->ce_mtime.sec = ntohl(ondisk->mtime.sec);
-#ifdef USE_NSEC
ce->ce_ctime.nsec = ntohl(ondisk->ctime.nsec);
ce->ce_mtime.nsec = ntohl(ondisk->mtime.nsec);
-#else
- ce->ce_ctime.nsec = 0;
- ce->ce_mtime.nsec = 0;
-#endif
ce->ce_dev = ntohl(ondisk->dev);
ce->ce_ino = ntohl(ondisk->ino);
ce->ce_mode = ntohl(ondisk->mode);
dst_offset += ce_size(ce);
}
istate->timestamp.sec = st.st_mtime;
-#ifdef USE_NSEC
- istate->timestamp.nsec = (unsigned int)st.st_mtim.tv_nsec;
-#else
- istate->timestamp.nsec = 0;
-#endif
+ istate->timestamp.nsec = ST_MTIME_NSEC(st);
while (src_offset <= mmap_size - 20 - 8) {
/* After an array of active_nr index entries,
ondisk->ctime.sec = htonl(ce->ce_ctime.sec);
ondisk->mtime.sec = htonl(ce->ce_mtime.sec);
-#ifdef USE_NSEC
ondisk->ctime.nsec = htonl(ce->ce_ctime.nsec);
ondisk->mtime.nsec = htonl(ce->ce_mtime.nsec);
-#else
- ondisk->ctime.nsec = 0;
- ondisk->mtime.nsec = 0;
-#endif
ondisk->dev = htonl(ce->ce_dev);
ondisk->ino = htonl(ce->ce_ino);
ondisk->mode = htonl(ce->ce_mode);
return ce_write(c, fd, ondisk, size);
}
-int write_index(const struct index_state *istate, int newfd)
+int write_index(struct index_state *istate, int newfd)
{
git_SHA_CTX c;
struct cache_header hdr;
int i, err, removed, extended;
struct cache_entry **cache = istate->cache;
int entries = istate->cache_nr;
+ struct stat st;
for (i = removed = extended = 0; i < entries; i++) {
if (cache[i]->ce_flags & CE_REMOVE)
if (err)
return -1;
}
- return ce_flush(&c, newfd);
+
+ if (ce_flush(&c, newfd) || fstat(newfd, &st))
+ return -1;
+ istate->timestamp.sec = (unsigned int)st.st_mtime;
+ istate->timestamp.nsec = ST_MTIME_NSEC(st);
+ return 0;
}
/*