rust-index: honour incoming using_general_delta in `deltachain`
authorGeorges Racinet on incendie.racinet.fr <georges@racinet.fr>
Fri, 27 Oct 2023 23:21:50 +0200
changeset 51235 456e0fe702e8
parent 51234 59183a19954e
child 51236 eb676c35a29b
rust-index: honour incoming using_general_delta in `deltachain` It looks to be a leftover from some past, but the C index considers only the value passed from Python whereas up to now the Rust index was using the value of its attribute. As a middle ground, we make this argument of `deltachain` optional from the Python side, with the Rust implementation only defaulting to its attribute. This way, we reduce false leads when a difference in results is spotted.
rust/hg-core/src/revlog/index.rs
rust/hg-cpython/src/revlog.rs
--- a/rust/hg-core/src/revlog/index.rs	Fri Oct 27 21:48:45 2023 +0200
+++ b/rust/hg-core/src/revlog/index.rs	Fri Oct 27 23:21:50 2023 +0200
@@ -599,15 +599,18 @@
         &self,
         rev: Revision,
         stop_rev: Option<Revision>,
+        using_general_delta: Option<bool>,
     ) -> Result<(Vec<Revision>, bool), HgError> {
         let mut current_rev = rev;
         let mut entry = self.get_entry(rev).unwrap();
         let mut chain = vec![];
+        let using_general_delta =
+            using_general_delta.unwrap_or_else(|| self.uses_generaldelta());
         while current_rev.0 != entry.base_revision_or_base_of_delta_chain().0
             && stop_rev.map(|r| r != current_rev).unwrap_or(true)
         {
             chain.push(current_rev);
-            let new_rev = if self.uses_generaldelta() {
+            let new_rev = if using_general_delta {
                 entry.base_revision_or_base_of_delta_chain()
             } else {
                 UncheckedRevision(current_rev.0 - 1)
--- a/rust/hg-cpython/src/revlog.rs	Fri Oct 27 21:48:45 2023 +0200
+++ b/rust/hg-cpython/src/revlog.rs	Fri Oct 27 23:21:50 2023 +0200
@@ -368,7 +368,12 @@
                 nodemap_error(py, NodeMapError::RevisionNotInIndex(stop_rev))
             })?)
         } else {None};
-        let (chain, stopped) = index.delta_chain(rev, stop_rev).map_err(|e| {
+        let using_general_delta = args.get_item(py, 2)
+            .extract::<Option<u32>>(py)?
+            .map(|i| i != 0);
+        let (chain, stopped) = index.delta_chain(
+            rev, stop_rev, using_general_delta
+        ).map_err(|e| {
             PyErr::new::<cpython::exc::ValueError, _>(py, e.to_string())
         })?;