# HG changeset patch
# User Raphaël Gomès <rgomes@octobus.net>
# Date 1740164171 18000
#      Fri Feb 21 13:56:11 2025 -0500
# Node ID 155e1e8dc055ccb82d291fdb53fac8e8dcbf010a
# Parent  33e06272ff1a225ba5e9fb1bdb8a12c3d9f78a64
rust-nodemap: don't compute the error string unless needed

This is... really dumb and costs a ton of performance in a hot loop. It was
75% of a profile for a tip to null p1 node traversal in pure Rust.

I'm at fault, done in 652149ed64f08ee73e8fd2f76aa480ea8820fe08.

I thought clippy had a lint for this, but apparently not?

diff --git a/rust/hg-core/src/revlog/mod.rs b/rust/hg-core/src/revlog/mod.rs
--- a/rust/hg-core/src/revlog/mod.rs
+++ b/rust/hg-core/src/revlog/mod.rs
@@ -374,7 +374,9 @@
             nodemap
                 .find_bin(self.index(), node)
                 .map_err(|err| (err, format!("{:x}", node)))?
-                .ok_or(RevlogError::InvalidRevision(format!("{:x}", node)))
+                .ok_or_else(|| {
+                    RevlogError::InvalidRevision(format!("{:x}", node))
+                })
         } else {
             self.index().rev_from_node_no_persistent_nodemap(node)
         }
# HG changeset patch
# User Raphaël Gomès <rgomes@octobus.net>
# Date 1740164301 18000
#      Fri Feb 21 13:58:21 2025 -0500
# Node ID 3fae904059667a19b984e3eaed6006b2c871732d
# Parent  155e1e8dc055ccb82d291fdb53fac8e8dcbf010a
rust-index: don't compute error messages unless needed

Same as the previous patch, this is just dumb performance loss.

diff --git a/rust/hg-core/src/revlog/index.rs b/rust/hg-core/src/revlog/index.rs
--- a/rust/hg-core/src/revlog/index.rs
+++ b/rust/hg-core/src/revlog/index.rs
@@ -880,9 +880,9 @@
                 if parent_base.0 == p1.0 {
                     break;
                 }
-                p1 = self.check_revision(parent_base).ok_or(
-                    RevlogError::InvalidRevision(parent_base.to_string()),
-                )?;
+                p1 = self.check_revision(parent_base).ok_or_else(|| {
+                    RevlogError::InvalidRevision(parent_base.to_string())
+                })?;
             }
             while let Some(p2_entry) = self.get_entry(p2) {
                 if p2_entry.compressed_len() != 0 || p2.0 == 0 {
@@ -893,16 +893,16 @@
                 if parent_base.0 == p2.0 {
                     break;
                 }
-                p2 = self.check_revision(parent_base).ok_or(
-                    RevlogError::InvalidRevision(parent_base.to_string()),
-                )?;
+                p2 = self.check_revision(parent_base).ok_or_else(|| {
+                    RevlogError::InvalidRevision(parent_base.to_string())
+                })?;
             }
             if base == p1.0 || base == p2.0 {
                 return Ok(false);
             }
-            rev = self
-                .check_revision(base.into())
-                .ok_or(RevlogError::InvalidRevision(base.to_string()))?;
+            rev = self.check_revision(base.into()).ok_or_else(|| {
+                RevlogError::InvalidRevision(base.to_string())
+            })?;
         }
         Ok(rev == NULL_REVISION)
     }
# HG changeset patch
# User Mitchell Kember <mkember@janestreet.com>
# Date 1740166638 18000
#      Fri Feb 21 14:37:18 2025 -0500
# Node ID 1ef08a0381a0522d787bbe82e875dc01c549ea56
# Parent  3fae904059667a19b984e3eaed6006b2c871732d
rust: enable workspace lints

This means that lints configured in rust/Cargo.toml will apply to all crates
within the workspace. Currently there are none but I plan to add some.

diff --git a/rust/hg-core/Cargo.toml b/rust/hg-core/Cargo.toml
--- a/rust/hg-core/Cargo.toml
+++ b/rust/hg-core/Cargo.toml
@@ -5,6 +5,9 @@
 description = "Mercurial pure Rust core library, with no assumption on Python bindings (FFI)"
 edition = "2021"
 
+[lints]
+workspace = true
+
 [lib]
 name = "hg"
 
diff --git a/rust/hg-cpython/Cargo.toml b/rust/hg-cpython/Cargo.toml
--- a/rust/hg-cpython/Cargo.toml
+++ b/rust/hg-cpython/Cargo.toml
@@ -4,6 +4,9 @@
 authors = ["Georges Racinet <gracinet@anybox.fr>"]
 edition = "2021"
 
+[lints]
+workspace = true
+
 [lib]
 name='rusthg'
 crate-type = ["cdylib"]
diff --git a/rust/hg-pyo3/Cargo.toml b/rust/hg-pyo3/Cargo.toml
--- a/rust/hg-pyo3/Cargo.toml
+++ b/rust/hg-pyo3/Cargo.toml
@@ -3,6 +3,9 @@
 version = "0.1.0"
 edition = "2021"
 
+[lints]
+workspace = true
+
 [lib]
 name='rusthgpyo3'
 crate-type = ["cdylib"]
diff --git a/rust/pyo3-sharedref/Cargo.toml b/rust/pyo3-sharedref/Cargo.toml
--- a/rust/pyo3-sharedref/Cargo.toml
+++ b/rust/pyo3-sharedref/Cargo.toml
@@ -3,6 +3,9 @@
 version = "0.1.0"
 edition = "2021"
 
+[lints]
+workspace = true
+
 [lib]
 name='pyo3_sharedref'
 
diff --git a/rust/rhg/Cargo.toml b/rust/rhg/Cargo.toml
--- a/rust/rhg/Cargo.toml
+++ b/rust/rhg/Cargo.toml
@@ -7,6 +7,9 @@
 ]
 edition = "2021"
 
+[lints]
+workspace = true
+
 [dependencies]
 hg-core = { path = "../hg-core"}
 chrono = "0.4.23"
# HG changeset patch
# User Mitchell Kember <mkember@janestreet.com>
# Date 1740166677 18000
#      Fri Feb 21 14:37:57 2025 -0500
# Node ID c4392e8bfb9fcf199c5999536547d3a5718be40e
# Parent  1ef08a0381a0522d787bbe82e875dc01c549ea56
rust: enable clippy::or_fun_call lint

I confirmed that this would have prevented the issue in !1280.

For details see:
https://rust-lang.github.io/rust-clippy/master/index.html#/or_fun_call

diff --git a/rust/Cargo.toml b/rust/Cargo.toml
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -2,3 +2,6 @@
 members = ["hg-core", "hg-cpython", "hg-pyo3", "rhg", "pyo3-sharedref"]
 exclude = ["chg", "hgcli"]
 resolver = "2"
+
+[workspace.lints.clippy]
+or_fun_call = "deny"