- return struct.pack(INDEX_SIG,
- self.dev, self.ctime, self.mtime,
- self.uid, self.gid, self.size, self.mode,
- self.gitmode, self.sha, self.flags,
- self.children_ofs, self.children_n)
-
- def from_stat(self, st, tstart):
- old = (self.dev, self.ctime, self.mtime,
- self.uid, self.gid, self.size, self.flags & IX_EXISTS)
- new = (st.st_dev, int(st.st_ctime), int(st.st_mtime),
- st.st_uid, st.st_gid, st.st_size, IX_EXISTS)
+ try:
+ ctime = xstat.nsecs_to_timespec(self.ctime)
+ mtime = xstat.nsecs_to_timespec(self.mtime)
+ atime = xstat.nsecs_to_timespec(self.atime)
+ return struct.pack(INDEX_SIG,
+ self.dev, self.ino, self.nlink,
+ ctime[0], ctime[1],
+ mtime[0], mtime[1],
+ atime[0], atime[1],
+ self.size, self.mode,
+ self.gitmode, self.sha, self.flags,
+ self.children_ofs, self.children_n,
+ self.meta_ofs)
+ except (DeprecationWarning, struct.error) as e:
+ log('pack error: %s (%r)\n' % (e, self))
+ raise
+
+ def stale(self, st, tstart, check_device=True):
+ if self.size != st.st_size:
+ return True
+ if self.mtime != st.st_mtime:
+ return True
+ if self.sha == EMPTY_SHA:
+ return True
+ if not self.gitmode:
+ return True
+ if self.ctime != st.st_ctime:
+ return True
+ if self.ino != st.st_ino:
+ return True
+ if self.nlink != st.st_nlink:
+ return True
+ if not (self.flags & IX_EXISTS):
+ return True
+ if check_device and (self.dev != st.st_dev):
+ return True
+ # Check that the ctime's "second" is at or after tstart's.
+ ctime_sec_in_ns = xstat.fstime_floor_secs(st.st_ctime) * 10**9
+ if ctime_sec_in_ns >= tstart:
+ return True
+ return False
+
+ def update_from_stat(self, st, meta_ofs):
+ # Should only be called when the entry is stale(), and
+ # invalidate() should almost certainly be called afterward.