timestamp: make the reliable comparison more usable from outside
authorRaphaël Gomès <rgomes@octobus.net>
Wed, 16 Oct 2024 18:41:49 +0200
changeset 52057 572d80e51094
parent 52056 7ea1cb46b590
child 52058 f5742367a279
timestamp: make the reliable comparison more usable from outside This is going to be used with pre-computed times unlike in status.
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