Skip to content

Commit

Permalink
Bump pyo3 version
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Apr 1, 2024
1 parent b0a92eb commit df4d874
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 69 deletions.
72 changes: 36 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[workspace]
members = ["crates/*"]

[workspace.dependencies]
pyo3 = ">=0.19"
2 changes: 1 addition & 1 deletion crates/diff-tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = ">=0.19", features = ["extension-module"]}
pyo3 = { workspace = true, features = ["extension-module"]}
48 changes: 18 additions & 30 deletions crates/diff-tree/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,16 @@

use pyo3::prelude::*;

use pyo3::exceptions::PyTypeError;
use pyo3::types::{PyBytes, PyList, PyTuple};
use pyo3::exceptions::{PyTypeError};
use pyo3::Python;

use std::cmp::Ordering;

const S_IFMT: u32 = 0o170000;
const S_IFDIR: u32 = 0o040000;

fn add_hash(
get: &PyAny,
set: &PyAny,
string: &[u8],
py: Python,
) -> PyResult<()> {
fn add_hash(get: &PyAny, set: &PyAny, string: &[u8], py: Python) -> PyResult<()> {
let str_obj = PyBytes::new(py, string);
let hash_obj = str_obj.hash()?;
let value = get.call1((hash_obj,))?;
Expand All @@ -55,7 +50,9 @@ fn _count_blocks(py: Python, obj: &PyAny) -> PyResult<PyObject> {

let chunks = obj.call_method0("as_raw_chunks")?;
if !chunks.is_instance_of::<PyList>() {
return Err(PyTypeError::new_err("as_raw_chunks() did not return a list"));
return Err(PyTypeError::new_err(
"as_raw_chunks() did not return a list",
));
}

let num_chunks = chunks.extract::<Vec<PyObject>>()?.len();
Expand Down Expand Up @@ -85,7 +82,6 @@ fn _count_blocks(py: Python, obj: &PyAny) -> PyResult<PyObject> {
Ok(counts.to_object(py))
}


#[pyfunction]
fn _is_tree(_py: Python, entry: &PyAny) -> PyResult<bool> {
let mode = entry.getattr("mode")?;
Expand All @@ -98,30 +94,28 @@ fn _is_tree(_py: Python, entry: &PyAny) -> PyResult<bool> {
}
}

fn tree_entries(
path: &[u8],
tree: &PyAny,
py: Python,
) -> PyResult<Vec<PyObject>> {
fn tree_entries(path: &[u8], tree: &PyAny, py: Python) -> PyResult<Vec<PyObject>> {
if tree.is_none() {
return Ok(Vec::new());
}

let dom = py.import("dulwich.objects")?;
let tree_entry_cls = dom.getattr("TreeEntry")?;

let items = tree.call_method1("iteritems", (true,))?.extract::<Vec<PyObject>>()?;
let items = tree
.call_method1("iteritems", (true,))?
.extract::<Vec<PyObject>>()?;

let mut result = Vec::new();
for item in items {
let (name, mode, sha) = item.extract::<(&[u8], u32, PyObject)>(py)?;
let (name, mode, sha) = item.extract::<(Vec<u8>, u32, PyObject)>(py)?;

let mut new_path = Vec::with_capacity(path.len() + name.len() + 1);
if !path.is_empty() {
new_path.extend_from_slice(path);
new_path.push(b'/');
}
new_path.extend_from_slice(name);
new_path.extend_from_slice(name.as_slice());

let tree_entry = tree_entry_cls.call1((PyBytes::new(py, &new_path), mode, sha))?;
result.push(tree_entry.to_object(py));
Expand Down Expand Up @@ -151,28 +145,22 @@ fn _merge_entries(py: Python, path: &[u8], tree1: &PyAny, tree2: &PyAny) -> PyRe
while i1 < entries1.len() && i2 < entries2.len() {
let cmp = entry_path_cmp(entries1[i1].as_ref(py), entries2[i2].as_ref(py))?;
let (e1, e2) = match cmp {
Ordering::Equal => {
(entries1[i1].clone(), entries2[i2].clone())
}
Ordering::Less => {
(entries1[i1].clone(), null_entry.clone())
}
Ordering::Greater => {
(null_entry.clone(), entries2[i2].clone())
}
Ordering::Equal => (entries1[i1].clone(), entries2[i2].clone()),
Ordering::Less => (entries1[i1].clone(), null_entry.clone()),
Ordering::Greater => (null_entry.clone(), entries2[i2].clone()),
};
let pair = PyTuple::new(py, &[e1, e2]);
result.push(pair);
match cmp {
Ordering::Equal => {
i1 += 1;
i2 += 1;
i1 += 1;
i2 += 1;
}
Ordering::Less => {
i1 += 1;
i1 += 1;
}
Ordering::Greater => {
i2 += 1;
i2 += 1;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/objects/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = ">=0.19", features = ["extension-module"]}
pyo3 = { workspace = true, features = ["extension-module"]}
memchr = "2"
2 changes: 1 addition & 1 deletion crates/pack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = ">=0.19", features = ["extension-module"]}
pyo3 = { workspace = true, features = ["extension-module"]}
memchr = "2"

0 comments on commit df4d874

Please sign in to comment.