Skip to content

Commit 7f86a52

Browse files
committed
Clippy fixes
1 parent 90f9009 commit 7f86a52

File tree

28 files changed

+129
-123
lines changed

28 files changed

+129
-123
lines changed

breezy/main.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ fn check_version(py: Python<'_>) -> PyResult<()> {
99
let major: u32 = env!("CARGO_PKG_VERSION_MAJOR").parse::<u32>().unwrap();
1010
let minor: u32 = env!("CARGO_PKG_VERSION_MINOR").parse::<u32>().unwrap();
1111
let patch: u32 = env!("CARGO_PKG_VERSION_PATCH").parse::<u32>().unwrap();
12-
let breezy = PyModule::import(py, "breezy").map_err(|e| {
12+
let breezy = PyModule::import(py, "breezy").inspect_err(|e| {
1313
eprintln!(
1414
"brz: ERROR: Couldn't import breezy and dependencies.\n\
1515
Please check the directory containing breezy is on your PYTHONPATH.\n"
1616
);
17-
e
1817
})?;
1918

2019
let ver = breezy

crates/bazaar-py/src/dirstate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn bisect_dirblock(
167167
let hi = hi.unwrap_or(dirblocks.len());
168168
let cache = cache.unwrap_or_else(|| PyDict::new(py));
169169

170-
let dirname_split = match cache.get_item(&dirname)? {
170+
let dirname_split = match cache.get_item(dirname)? {
171171
Some(item) => item.extract::<Vec<PathBuf>>()?,
172172
None => {
173173
let split = split_object(dirname)?;
@@ -425,7 +425,7 @@ fn inv_entry_to_details<'a>(
425425
}
426426

427427
#[pyfunction]
428-
fn get_output_lines<'py>(py: Python<'py>, lines: Vec<Vec<u8>>) -> Vec<Bound<'py, PyBytes>> {
428+
fn get_output_lines(py: Python<'_>, lines: Vec<Vec<u8>>) -> Vec<Bound<'_, PyBytes>> {
429429
let lines = lines.iter().map(|x| x.as_slice()).collect::<Vec<&[u8]>>();
430430
bazaar::dirstate::get_output_lines(lines)
431431
.into_iter()

crates/bazaar-py/src/groupcompress.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl TraditionalGroupCompressor {
294294
.map(|x| PyBytes::new(py, x.as_ref()))
295295
.collect())
296296
} else {
297-
Err(PyRuntimeError::new_err("Compressor is already finalized")).unwrap()
297+
Err(PyRuntimeError::new_err("Compressor is already finalized"))
298298
}
299299
}
300300

@@ -303,15 +303,15 @@ impl TraditionalGroupCompressor {
303303
if let Some(c) = self.0.as_ref() {
304304
Ok(c.endpoint())
305305
} else {
306-
Err(PyRuntimeError::new_err("Compressor is already finalized")).unwrap()
306+
Err(PyRuntimeError::new_err("Compressor is already finalized"))
307307
}
308308
}
309309

310310
fn ratio(&self) -> PyResult<f32> {
311311
if let Some(c) = self.0.as_ref() {
312312
Ok(c.ratio())
313313
} else {
314-
Err(PyRuntimeError::new_err("Compressor is already finalized")).unwrap()
314+
Err(PyRuntimeError::new_err("Compressor is already finalized"))
315315
}
316316
}
317317

@@ -329,7 +329,7 @@ impl TraditionalGroupCompressor {
329329
PyBytes::new(py, hash.as_bytes()),
330330
))
331331
} else {
332-
Err(PyRuntimeError::new_err("Compressor is already finalized")).unwrap()
332+
Err(PyRuntimeError::new_err("Compressor is already finalized"))
333333
}
334334
}
335335

@@ -344,7 +344,7 @@ impl TraditionalGroupCompressor {
344344
endpoint,
345345
))
346346
} else {
347-
Err(PyRuntimeError::new_err("Compressor is already finalized")).unwrap()
347+
Err(PyRuntimeError::new_err("Compressor is already finalized"))
348348
}
349349
}
350350

@@ -362,7 +362,7 @@ impl TraditionalGroupCompressor {
362362
endpoint,
363363
))
364364
} else {
365-
Err(PyRuntimeError::new_err("Compressor is already finalized")).unwrap()
365+
Err(PyRuntimeError::new_err("Compressor is already finalized"))
366366
}
367367
}
368368

@@ -390,7 +390,7 @@ impl TraditionalGroupCompressor {
390390
.map_err(|e| PyValueError::new_err(format!("Error during compress: {:?}", e)))
391391
.map(|(hash, size, chunks, kind)| (PyBytes::new(py, hash.as_ref()), size, chunks, kind))
392392
} else {
393-
Err(PyRuntimeError::new_err("Compressor is already finalized")).unwrap()
393+
Err(PyRuntimeError::new_err("Compressor is already finalized"))
394394
}
395395
}
396396
}

crates/bazaar-py/src/inventory.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl InventoryFile {
373373
let s = slf.into_super();
374374
let init = PyClassInitializer::from(InventoryEntry(s.0.clone()));
375375
let init = init.add_subclass(Self());
376-
Ok(Bound::new(py, init)?)
376+
Bound::new(py, init)
377377
}
378378

379379
fn __repr__(slf: PyRef<Self>, py: Python) -> PyResult<String> {
@@ -486,7 +486,7 @@ impl InventoryDirectory {
486486
let s = slf.into_super();
487487
let init = PyClassInitializer::from(InventoryEntry(s.0.clone()));
488488
let init = init.add_subclass(Self());
489-
Ok(Bound::new(py, init)?)
489+
Bound::new(py, init)
490490
}
491491

492492
#[getter]
@@ -604,7 +604,7 @@ impl TreeReference {
604604
let s = slf.into_super();
605605
let init = PyClassInitializer::from(InventoryEntry(s.0.clone()));
606606
let init = init.add_subclass(Self());
607-
Ok(Bound::new(py, init)?)
607+
Bound::new(py, init)
608608
}
609609
}
610610

@@ -648,7 +648,7 @@ impl InventoryLink {
648648
let s = slf.into_super();
649649
let init = PyClassInitializer::from(InventoryEntry(s.0.clone()));
650650
let init = init.add_subclass(Self());
651-
Ok(Bound::new(py, init)?)
651+
Bound::new(py, init)
652652
}
653653

654654
#[getter]
@@ -1120,7 +1120,7 @@ impl Inventory {
11201120
reference_revision,
11211121
)
11221122
.map_err(|e| inventory_err_to_py_err(e, py))?;
1123-
Ok(self.get_entry(py, file_id)?)
1123+
self.get_entry(py, file_id)
11241124
}
11251125

11261126
#[getter]
@@ -1340,7 +1340,7 @@ impl Inventory {
13401340
old: &Inventory,
13411341
) -> PyResult<Bound<'py, InventoryDelta>> {
13421342
let inventory_delta = self.0.make_delta(&old.0);
1343-
Ok(Bound::new(py, InventoryDelta(inventory_delta))?)
1343+
Bound::new(py, InventoryDelta(inventory_delta))
13441344
}
13451345

13461346
fn remove_recursive_id<'a>(
@@ -1376,10 +1376,10 @@ impl Inventory {
13761376
if children.is_none() {
13771377
return Err(NoSuchId::new_err((py.None(), file_id)));
13781378
}
1379-
Ok(children
1379+
children
13801380
.unwrap()
13811381
.map(|(_n, e)| Ok(entry_to_py(py, e.clone())?.into_any()))
1382-
.collect::<PyResult<Vec<_>>>()?)
1382+
.collect::<PyResult<Vec<_>>>()
13831383
}
13841384

13851385
fn iter_all_ids<'a>(&self, py: Python<'a>) -> PyResult<Bound<'a, PyAny>> {
@@ -1399,10 +1399,10 @@ impl Inventory {
13991399
) -> PyResult<Bound<IterEntriesIterator>> {
14001400
let recursive = recursive.unwrap_or(true);
14011401

1402-
Ok(Bound::new(
1402+
Bound::new(
14031403
py,
14041404
IterEntriesIterator::new(py, slf, from_dir, recursive)?,
1405-
)?)
1405+
)
14061406
}
14071407

14081408
#[pyo3(signature = (from_dir=None, specific_file_ids=None))]
@@ -1412,10 +1412,10 @@ impl Inventory {
14121412
from_dir: Option<FileId>,
14131413
specific_file_ids: Option<HashSet<FileId>>,
14141414
) -> PyResult<Bound<IterEntriesByDirIterator>> {
1415-
Ok(Bound::new(
1415+
Bound::new(
14161416
py,
14171417
IterEntriesByDirIterator::new(py, slf, from_dir, specific_file_ids)?,
1418-
)?)
1418+
)
14191419
}
14201420

14211421
fn change_root_id(&mut self, new_root_id: FileId) -> PyResult<()> {
@@ -1614,8 +1614,8 @@ struct IterEntriesIterator {
16141614
}
16151615

16161616
impl IterEntriesIterator {
1617-
fn new<'py>(
1618-
py: Python<'py>,
1617+
fn new(
1618+
py: Python<'_>,
16191619
inv: Py<Inventory>,
16201620
mut from_dir: Option<FileId>,
16211621
recursive: bool,

crates/bazaar-py/src/rio.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl RioReader {
327327
stanza: stanza.unwrap(),
328328
})?;
329329
}
330-
Ok(PyIterator::from_object(&ret)?)
330+
PyIterator::from_object(&ret)
331331
}
332332
}
333333

@@ -349,7 +349,7 @@ fn rio_iter<'a>(
349349
let line = line.as_slice();
350350
ret.append(PyBytes::new(py, line))?;
351351
}
352-
Ok(PyIterator::from_object(&ret)?)
352+
PyIterator::from_object(&ret)
353353
}
354354

355355
pub(crate) fn rio(m: &Bound<PyModule>) -> PyResult<()> {

crates/bazaar/src/chk_inventory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub fn chk_inventory_entry_to_bytes(entry: &Entry) -> Vec<u8> {
9999
),
100100
};
101101

102-
let header = vec![header, b": ", entry.file_id().as_bytes()].concat();
102+
let header = [header, b": ", entry.file_id().as_bytes()].concat();
103103

104104
lines.insert(0, header.as_slice());
105105

crates/bazaar/src/dirstate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl IdIndex {
348348
let entry_keys = self
349349
.id_index
350350
.entry(file_id.clone())
351-
.or_insert_with(Vec::new);
351+
.or_default();
352352
entry_keys.push((entry_key.0.to_vec(), entry_key.1.to_vec(), file_id.clone()));
353353
}
354354

crates/bazaar/src/gen_ids.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,10 @@ pub fn gen_revision_id(username: &str, timestamp: Option<u64>) -> Vec<u8> {
117117
.unwrap()
118118
.as_secs()
119119
});
120-
vec![
121-
user_or_email,
120+
[user_or_email,
122121
breezy_osutils::time::compact_date(timestamp)
123122
.as_bytes()
124123
.to_vec(),
125-
unique_chunk,
126-
]
124+
unique_chunk]
127125
.join(&b'-')
128126
}

crates/bazaar/src/groupcompress/compressor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl GroupCompressor for TraditionalGroupCompressor {
156156
];
157157
index_lines.clear();
158158
index_lines.extend(vec![false, false]);
159-
index_lines.extend(vec![true].repeat(new_lines.len()));
159+
index_lines.extend([true].repeat(new_lines.len()));
160160
out_lines.extend(new_lines);
161161
("fulltext", out_lines)
162162
} else {

crates/bazaar/src/groupcompress/line_delta.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl LinesDeltaIndex {
150150
}
151151
matches
152152
.entry(line.clone())
153-
.or_insert_with(HashSet::new)
153+
.or_default()
154154
.insert(start_idx + idx);
155155
}
156156
}

crates/bazaar/src/groupcompress/rabin_delta.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub struct IndexEntry<'a> {
191191
pub data: &'a [u8],
192192
}
193193

194-
impl<'a> IndexEntry<'a> {
194+
impl IndexEntry<'_> {
195195
pub fn add(&self, offset: usize) -> Self {
196196
Self {
197197
offset: self.offset + offset,
@@ -200,6 +200,12 @@ impl<'a> IndexEntry<'a> {
200200
}
201201
}
202202

203+
impl Default for DeltaIndex<'_> {
204+
fn default() -> Self {
205+
Self::new()
206+
}
207+
}
208+
203209
impl<'a> DeltaIndex<'a> {
204210
pub fn iter_matches(&self, val: &RabinHash) -> impl Iterator<Item = &IndexEntry<'a>> + '_ {
205211
self.entries
@@ -269,7 +275,7 @@ impl<'a> DeltaIndex<'a> {
269275
let val = rabin_hash(data[i..i + RABIN_WINDOW].try_into().unwrap());
270276
self.entries
271277
.entry(val.into())
272-
.or_insert_with(Vec::new)
278+
.or_default()
273279
.push(IndexEntry::<'a> {
274280
offset: self.last_offset + pos,
275281
data: &data[i..],
@@ -312,7 +318,7 @@ impl<'a> DeltaIndex<'a> {
312318
prev_val = Some(val);
313319
self.entries
314320
.entry(val.into())
315-
.or_insert_with(Vec::new)
321+
.or_default()
316322
.push(IndexEntry::<'a> {
317323
offset: self.last_offset + i,
318324
data: &src[i..],

crates/bazaar/src/inventory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ impl MutableInventory {
11441144
/// Unlike iter_entries(), just the entries are returned (not (path, ie))
11451145
/// and the order of entries is undefined.
11461146
pub fn iter_just_entries(&self) -> impl Iterator<Item = &Entry> + '_ {
1147-
return self.by_id.values();
1147+
self.by_id.values()
11481148
}
11491149

11501150
pub fn get_child(&self, parent_id: &FileId, filename: &str) -> Option<&Entry> {

crates/bazaar/src/inventory_delta.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ pub fn serialize_inventory_delta(
221221
) -> Result<Vec<Vec<u8>>, InventoryDeltaSerializeError> {
222222
let mut lines = vec![
223223
format!("format: {}\n", FORMAT_1).into_bytes(),
224-
vec![&b"parent: "[..], old_name.as_bytes(), &b"\n"[..]].concat(),
225-
vec![&b"version: "[..], new_name.as_bytes(), &b"\n"[..]].concat(),
224+
[&b"parent: "[..], old_name.as_bytes(), &b"\n"[..]].concat(),
225+
[&b"version: "[..], new_name.as_bytes(), &b"\n"[..]].concat(),
226226
format!("versioned_root: {}\n", serialize_bool(versioned_root)).into_bytes(),
227227
format!("tree_references: {}\n", serialize_bool(tree_references)).into_bytes(),
228228
];
@@ -337,14 +337,12 @@ fn delta_entry_to_line(
337337
}
338338
content = serialize_inventory_entry(new_entry)?;
339339
}
340-
let entries = vec![
341-
oldpath_utf8.as_bytes(),
340+
let entries = [oldpath_utf8.as_bytes(),
342341
newpath_utf8.as_bytes(),
343342
delta_item.file_id.as_bytes(),
344343
parent_id,
345344
last_modified.as_bytes(),
346-
content.as_slice(),
347-
];
345+
content.as_slice()];
348346
let mut line = entries.join(&b"\x00"[..]);
349347
line.push(b'\n');
350348
Ok(line)
@@ -548,7 +546,7 @@ pub fn parse_inventory_delta(
548546
.map(|x| x.strip_suffix(b"\n").unwrap())
549547
.collect::<Vec<_>>();
550548

551-
if lines.is_empty() || lines[0] != vec![&b"format: "[..], FORMAT_1.as_bytes()].concat() {
549+
if lines.is_empty() || lines[0] != [&b"format: "[..], FORMAT_1.as_bytes()].concat() {
552550
return Err(InventoryDeltaParseError::Invalid(format!(
553551
"unknown format: {}",
554552
String::from_utf8_lossy(&lines[0][8..])

crates/bazaar/src/rio.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub struct RioReaderIter<'a, R: BufRead> {
9595
reader: &'a mut RioReader<R>,
9696
}
9797

98-
impl<'a, R: BufRead> Iterator for RioReaderIter<'a, R> {
98+
impl<R: BufRead> Iterator for RioReaderIter<'_, R> {
9999
type Item = Result<Option<Stanza>, Error>;
100100

101101
fn next(&mut self) -> Option<Self::Item> {
@@ -283,7 +283,7 @@ where
283283
let mut accum_value: Option<Vec<String>> = None;
284284

285285
for bline in lines {
286-
let mut line = bline.map_err(Error::from)?;
286+
let mut line = bline?;
287287
trim_newline(&mut line);
288288
if line.is_empty() {
289289
break; // end of stanza

crates/bazaar/src/versionedfile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl pyo3::FromPyObject<'_> for Key {
212212
.unwrap()
213213
.to_string()
214214
.split('.')
215-
.last()
215+
.next_back()
216216
.unwrap()
217217
{
218218
"tuple" | "StaticTuple" => {}

0 commit comments

Comments
 (0)