##// END OF EJS Templates
dirstate-v2: actually use sub-second mtime precision...
Simon Sapin -
r49082:83d0bd45 default
parent child Browse files
Show More
@@ -66,12 +66,22 b' def mtime_of(stat_result):'
66 Takes an `os.stat_result`-like object and returns a `timestamp` object
66 Takes an `os.stat_result`-like object and returns a `timestamp` object
67 for its modification time.
67 for its modification time.
68 """
68 """
69 # https://docs.python.org/2/library/os.html#os.stat_float_times
69 try:
70 # "For compatibility with older Python versions,
70 # TODO: add this attribute to `osutil.stat` objects,
71 # accessing stat_result as a tuple always returns integers."
71 # see `mercurial/cext/osutil.c`.
72 secs = stat_result[stat.ST_MTIME]
72 #
73 # This attribute is also not available on Python 2.
74 nanos = stat_result.st_mtime_ns
75 except AttributeError:
76 # https://docs.python.org/2/library/os.html#os.stat_float_times
77 # "For compatibility with older Python versions,
78 # accessing stat_result as a tuple always returns integers."
79 secs = stat_result[stat.ST_MTIME]
73
80
74 # For now
81 subsec_nanos = 0
75 subsec_nanos = 0
82 else:
83 billion = int(1e9)
84 secs = nanos // billion
85 subsec_nanos = nanos % billion
76
86
77 return timestamp((secs, subsec_nanos))
87 return timestamp((secs, subsec_nanos))
@@ -101,15 +101,12 b' def parse_nodes(map, copy_map, data, sta'
101 flags,
101 flags,
102 size,
102 size,
103 mtime_s,
103 mtime_s,
104 _mtime_ns,
104 mtime_ns,
105 ) = NODE.unpack(node_bytes)
105 ) = NODE.unpack(node_bytes)
106
106
107 # Parse child nodes of this node recursively
107 # Parse child nodes of this node recursively
108 parse_nodes(map, copy_map, data, children_start, children_count)
108 parse_nodes(map, copy_map, data, children_start, children_count)
109
109
110 # Don’t yet use sub-second precision if it exists in the file,
111 # since other parts of the code still set it to zero.
112 mtime_ns = 0
113 item = parsers.DirstateItem.from_v2_data(flags, size, mtime_s, mtime_ns)
110 item = parsers.DirstateItem.from_v2_data(flags, size, mtime_s, mtime_ns)
114 if not item.any_tracked:
111 if not item.any_tracked:
115 continue
112 continue
@@ -91,11 +91,6 b' impl TruncatedTimestamp {'
91 }
91 }
92 }
92 }
93
93
94 pub fn to_integer_second(mut self) -> Self {
95 self.nanoseconds = 0;
96 self
97 }
98
99 /// The lower 31 bits of the number of seconds since the epoch.
94 /// The lower 31 bits of the number of seconds since the epoch.
100 pub fn truncated_seconds(&self) -> u32 {
95 pub fn truncated_seconds(&self) -> u32 {
101 self.truncated_seconds
96 self.truncated_seconds
@@ -376,15 +376,7 b' impl Node {'
376 // MTIME_SECOND_AMBIGUOUS requires. So we ignore the mtime
376 // MTIME_SECOND_AMBIGUOUS requires. So we ignore the mtime
377 && !self.flags().contains(Flags::MTIME_SECOND_AMBIGUOUS)
377 && !self.flags().contains(Flags::MTIME_SECOND_AMBIGUOUS)
378 {
378 {
379 // TODO: replace this by `self.mtime.try_into()?` to use
379 Some(self.mtime.try_into()?)
380 // sub-second precision from the file.
381 // We don’t do this yet because other parts of the code
382 // always set it to zero.
383 let mtime = TruncatedTimestamp::from_already_truncated(
384 self.mtime.truncated_seconds.get(),
385 0,
386 )?;
387 Some(mtime)
388 } else {
380 } else {
389 None
381 None
390 };
382 };
@@ -531,9 +531,7 b" impl<'a, 'tree, 'on_disk> StatusCommon<'"
531 let mtime_looks_clean;
531 let mtime_looks_clean;
532 if let Some(dirstate_mtime) = entry.truncated_mtime() {
532 if let Some(dirstate_mtime) = entry.truncated_mtime() {
533 let fs_mtime = TruncatedTimestamp::for_mtime_of(fs_metadata)
533 let fs_mtime = TruncatedTimestamp::for_mtime_of(fs_metadata)
534 .expect("OS/libc does not support mtime?")
534 .expect("OS/libc does not support mtime?");
535 // For now don’t use sub-second precision for file mtimes
536 .to_integer_second();
537 mtime_looks_clean = fs_mtime.likely_equal(dirstate_mtime)
535 mtime_looks_clean = fs_mtime.likely_equal(dirstate_mtime)
538 && !fs_mtime.likely_equal(self.options.last_normal_time)
536 && !fs_mtime.likely_equal(self.options.last_normal_time)
539 } else {
537 } else {
General Comments 0
You need to be logged in to leave comments. Login now