# HG changeset patch # User Raphaël Gomès # Date 1729096909 -7200 # Node ID 572d80e510948f60d6b11ce208c3e4f3213e22d8 # Parent 7ea1cb46b590e8bc35393c80c58a9e34680dd7a4 timestamp: make the reliable comparison more usable from outside This is going to be used with pre-computed times unlike in status. diff -r 7ea1cb46b590 -r 572d80e51094 mercurial/dirstateutils/timestamp.py --- a/mercurial/dirstateutils/timestamp.py Wed Oct 16 18:40:59 2024 +0200 +++ b/mercurial/dirstateutils/timestamp.py Wed Oct 16 18:41:49 2024 +0200 @@ -100,6 +100,14 @@ def reliable_mtime_of( stat_result: os.stat_result, present_mtime: timestamp ) -> Optional[timestamp]: + """Wrapper for `make_mtime_reliable` for stat objects""" + file_mtime = mtime_of(stat_result) + return make_mtime_reliable(file_mtime, present_mtime) + + +def make_mtime_reliable( + file_timestamp: timestamp, present_mtime: timestamp +) -> Optional[timestamp]: """Same as `mtime_of`, but return `None` or a `Timestamp` with `second_ambiguous` set if the date might be ambiguous. @@ -108,9 +116,8 @@ Otherwise a concurrent modification might happens with the same mtime. """ - file_mtime = mtime_of(stat_result) - file_second = file_mtime[0] - file_ns = file_mtime[1] + file_second = file_timestamp[0] + file_ns = file_timestamp[1] boundary_second = present_mtime[0] boundary_ns = present_mtime[1] # If the mtime of the ambiguous file is younger (or equal) to the starting @@ -129,4 +136,4 @@ elif boundary_second < file_second < (3600 * 24 + boundary_second): return None else: - return file_mtime + return file_timestamp