Skip to content

Commit

Permalink
Add AsLocation
Browse files Browse the repository at this point in the history
by jelmer review by jelmer
  • Loading branch information
jelmer authored and The Breezy Bot committed Dec 23, 2023
2 parents 98686b5 + b67dadc commit 50dba6e
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 10 deletions.
1 change: 1 addition & 0 deletions breezy/bzr/groupcompress.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ class PyrexGroupCompressor:
"""

chunks: list[bytes]

def __init__(self, settings=None):
"""Create a GroupCompressor."""
self._last = None
Expand Down
2 changes: 1 addition & 1 deletion breezy/bzr/tests/test_bzrdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
self.assertRaises(errors.NoRepositoryPresent, branch.controldir.open_repository)

def test_create_branch_convenience_under_shared_repo_no_tree_policy_force_tree(
self
self,
):
# inside a repo the default convenience output is a branch+ follow the
# repo tree policy but we can override that
Expand Down
3 changes: 2 additions & 1 deletion breezy/git/dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def retire_controldir(self, limit=10000):
self.root_transport.rename(".git", to_path)
trace.note(
"renamed {} to {}".format(
self.root_transport.abspath(".git"), to_path)
self.root_transport.abspath(".git"), to_path
)
)
return
except (brz_errors.TransportError, OSError, brz_errors.PathError):
Expand Down
5 changes: 2 additions & 3 deletions breezy/git/workingtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1636,13 +1636,12 @@ def subsume(self, other_tree):

ids = {}
for p, e in other_tree.index.iteritems():
newp = other_tree_bytes + b"/" + p
newp = other_tree_bytes + b"/" + p
self.index[newp] = e
self._index_dirty = True
ids[e.sha] = newp

self.store.add_objects(
[(other_tree.store[i], p) for (i, p) in ids.items()])
self.store.add_objects([(other_tree.store[i], p) for (i, p) in ids.items()])

other_tree.controldir.retire_controldir()

Expand Down
12 changes: 9 additions & 3 deletions breezy/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,15 @@ def stopTestRun(self):
)
# We don't report the main thread as an active one.
self.stream.write(
"%d non-main threads were left active in the end: %r.\n"
% (len(self._active_threads) - 1,
[t for t in self._active_threads if not isinstance(t, threading._MainThread)])
"%d non-main threads were left active in the end: %r.\n"
% (
len(self._active_threads) - 1,
[
t
for t in self._active_threads
if not isinstance(t, threading._MainThread)
],
)
)

def getDescription(self, test):
Expand Down
2 changes: 0 additions & 2 deletions breezy/tests/test__known_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@


class TestCaseWithKnownGraph(tests.TestCase):

def make_known_graph(self, ancestry):
return KnownGraph(ancestry)

Expand Down Expand Up @@ -167,7 +166,6 @@ def test_fill_in_ghost(self):


class TestKnownGraphHeads(TestCaseWithKnownGraph):

def test_heads_null(self):
graph = self.make_known_graph(test_graph.ancestry_1)
self.assertEqual({b"null:"}, graph.heads([b"null:"]))
Expand Down
25 changes: 25 additions & 0 deletions src/location.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use percent_encoding::{utf8_percent_encode, CONTROLS};
use pyo3::prelude::*;
use url::Url;

use regex::Regex;
Expand Down Expand Up @@ -101,3 +102,27 @@ pub fn cvs_to_url(location: &str) -> Result<Url, Error> {
.map_err(|e| Error(format!("Invalid URL: {}", e)))?;
Ok(url)
}

pub trait AsLocation {
fn as_location(&self) -> PyObject;
}

impl AsLocation for &url::Url {
fn as_location(&self) -> PyObject {
Python::with_gil(|py| {
pyo3::types::PyString::new(py, self.to_string().as_str()).to_object(py)
})
}
}

impl AsLocation for &str {
fn as_location(&self) -> PyObject {
Python::with_gil(|py| pyo3::types::PyString::new(py, self).to_object(py))
}
}

impl AsLocation for &std::path::Path {
fn as_location(&self) -> PyObject {
Python::with_gil(|py| pyo3::types::PyString::new(py, self.to_str().unwrap()).to_object(py))
}
}

0 comments on commit 50dba6e

Please sign in to comment.