[Commented On] D10983: dirstate-item: also build DistateItem in dirstate.directories()

baymax (Baymax, Your Personal Patch-care Companion) phabricator at mercurial-scm.org
Thu Jul 8 15:05:17 UTC 2021


baymax added a comment.
baymax updated this revision to Diff 29009.


  ✅ refresh by Heptapod after a successful CI run (🐙 💚)

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D10983?vs=28838&id=29009

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D10983/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D10983

AFFECTED FILES
  rust/hg-cpython/src/dirstate.rs
  rust/hg-cpython/src/dirstate/dirstate_map.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs b/rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs
@@ -19,6 +19,7 @@
 
 use crate::{
     dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator},
+    dirstate::make_directory_item,
     dirstate::make_dirstate_item,
     dirstate::non_normal_entries::{
         NonNormalEntries, NonNormalEntriesIterator,
@@ -519,7 +520,8 @@
             let (path, mtime) = item.map_err(|e| v2_error(py, e))?;
             let path = PyBytes::new(py, path.as_bytes());
             let mtime = mtime.map(|t| t.0).unwrap_or(-1);
-            let tuple = (path, (b'd', 0, 0, mtime));
+            let item = make_directory_item(py, mtime as i32)?;
+            let tuple = (path, item);
             dirs.append(py, tuple.to_py_object(py).into_object())
         }
         Ok(dirs)
diff --git a/rust/hg-cpython/src/dirstate.rs b/rust/hg-cpython/src/dirstate.rs
--- a/rust/hg-cpython/src/dirstate.rs
+++ b/rust/hg-cpython/src/dirstate.rs
@@ -73,6 +73,19 @@
     maybe_obj.ok_or_else(|| PyErr::fetch(py))
 }
 
+// XXX a bit strange to have a dedicated function, but directory are not
+// treated as dirstate node by hg-core for now so…
+pub fn make_directory_item(py: Python, mtime: i32) -> PyResult<PyObject> {
+    // might be silly to retrieve capsule function in hot loop
+    let make = make_dirstate_item_capi::retrieve(py)?;
+
+    let maybe_obj = unsafe {
+        let ptr = make(b'd' as c_char, 0 as i32, 0 as i32, mtime);
+        PyObject::from_owned_ptr_opt(py, ptr)
+    };
+    maybe_obj.ok_or_else(|| PyErr::fetch(py))
+}
+
 pub fn extract_dirstate(py: Python, dmap: &PyDict) -> Result<StateMap, PyErr> {
     dmap.items(py)
         .iter()



To: marmoute, #hg-reviewers, SimonSapin
Cc: SimonSapin, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210708/2543e45f/attachment-0002.html>


More information about the Mercurial-patches mailing list