rust/hg-cpython/src/dirstate/item.rs
changeset 48271 269ff8978086
parent 48269 c591944f42c1
child 48426 3d6eb119200d
--- a/rust/hg-cpython/src/dirstate/item.rs	Tue Oct 19 21:03:13 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/item.rs	Mon Oct 18 11:23:07 2021 +0200
@@ -9,6 +9,7 @@
 use cpython::PythonObject;
 use hg::dirstate::DirstateEntry;
 use hg::dirstate::EntryState;
+use hg::dirstate::TruncatedTimestamp;
 use std::cell::Cell;
 use std::convert::TryFrom;
 
@@ -22,7 +23,7 @@
         p2_info: bool = false,
         has_meaningful_data: bool = true,
         has_meaningful_mtime: bool = true,
-        parentfiledata: Option<(u32, u32, u32)> = None,
+        parentfiledata: Option<(u32, u32, (u32, u32))> = None,
         fallback_exec: Option<bool> = None,
         fallback_symlink: Option<bool> = None,
 
@@ -34,7 +35,7 @@
                 mode_size_opt = Some((mode, size))
             }
             if has_meaningful_mtime {
-                mtime_opt = Some(mtime)
+                mtime_opt = Some(timestamp(py, mtime)?)
             }
         }
         let entry = DirstateEntry::from_v2_data(
@@ -191,10 +192,19 @@
         Ok(mtime)
     }
 
-    def need_delay(&self, now: i32) -> PyResult<bool> {
+    def need_delay(&self, now: (u32, u32)) -> PyResult<bool> {
+        let now = timestamp(py, now)?;
         Ok(self.entry(py).get().need_delay(now))
     }
 
+    def mtime_likely_equal_to(&self, other: (u32, u32)) -> PyResult<bool> {
+        if let Some(mtime) = self.entry(py).get().truncated_mtime() {
+            Ok(mtime.likely_equal(timestamp(py, other)?))
+        } else {
+            Ok(false)
+        }
+    }
+
     @classmethod
     def from_v1_data(
         _cls,
@@ -220,8 +230,9 @@
         &self,
         mode: u32,
         size: u32,
-        mtime: u32,
+        mtime: (u32, u32),
     ) -> PyResult<PyNone> {
+        let mtime = timestamp(py, mtime)?;
         self.update(py, |entry| entry.set_clean(mode, size, mtime));
         Ok(PyNone)
     }
@@ -261,3 +272,15 @@
         self.entry(py).set(entry)
     }
 }
+
+pub(crate) fn timestamp(
+    py: Python<'_>,
+    (s, ns): (u32, u32),
+) -> PyResult<TruncatedTimestamp> {
+    TruncatedTimestamp::from_already_truncated(s, ns).map_err(|_| {
+        PyErr::new::<exc::ValueError, _>(
+            py,
+            "expected mtime truncated to 31 bits",
+        )
+    })
+}