History

thanks clippy

Sebastian Thiel committed 5 years ago

Commit 6200ed91 parent 217451320 files · +52 −50Browse files

Unified · Split

20 files
  1. git-config/src/file.rs +9 −7
  2. git-config/src/values.rs +1 −1
  3. git-hash/src/owned.rs +2 −2
  4. git-object/src/mutable/tag.rs +1 −1
  5. git-object/src/types.rs +2 −2
  6. git-pack/src/data/entry/header.rs +4 −4
  7. git-pack/src/data/entry/mod.rs +1 −1
  8. git-pack/src/data/file/decode_entry.rs +2 −2
  9. git-pack/src/data/input/iter.rs +1 −1
  10. git-pack/src/data/output/bytes.rs +1 −1
  11. git-pack/src/data/output/entry/mod.rs +1 −1
  12. git-pack/src/index/traverse/indexed.rs +1 −1
  13. git-pack/src/index/write/mod.rs +1 −1
  14. git-pack/tests/pack/iter.rs +1 −1
  15. git-packetline/src/immutable/blocking_io.rs +4 −4
  16. git-packetline/src/immutable/mod.rs +3 −3
  17. git-packetline/tests/decode/mod.rs +8 −8
  18. git-transport/src/client/async_io/request.rs +4 −4
  19. git-transport/src/client/blocking_io/request.rs +4 −4
  20. git-transport/src/client/capabilities.rs +1 −1
git-config/src/file.rs+9−7
@@ -250,7 +250,7 @@ impl<'event> SectionBody<'event> { · 249 unmodified lines
250250 // We hit this lint because of the unreachable!() call may panic, but this
251251 // is a clippy bug (rust-clippy#6699), so we allow this lint for this
252252 // function.
253− #[allow(clippy::clippy::missing_panics_doc)]
253+ #[allow(clippy::missing_panics_doc)]
254254 #[must_use]
255255 pub fn value(&self, key: &Key) -> Option<Cow<'event, [u8]>> {
256256 let range = self.get_value_range_by_key(key);
@@ -1843,12 +1843,14 @@ impl<'a> From<Parser<'a>> for GitConfig<'a> { · 1586 unmodified lines
18431843 prev_section_header = Some(header);
18441844 section_events = SectionBody::new();
18451845 }
1846− e @ Event::Key(_)
1847− | e @ Event::Value(_)
1848− | e @ Event::ValueNotDone(_)
1849− | e @ Event::ValueDone(_)
1850− | e @ Event::KeyValueSeparator => section_events.0.push(e),
1851− e @ Event::Comment(_) | e @ Event::Newline(_) | e @ Event::Whitespace(_) => {
1846+ e
1847+ @
1848+ (Event::Key(_)
1849+ | Event::Value(_)
1850+ | Event::ValueNotDone(_)
1851+ | Event::ValueDone(_)
1852+ | Event::KeyValueSeparator) => section_events.0.push(e),
1853+ e @ (Event::Comment(_) | Event::Newline(_) | Event::Whitespace(_)) => {
18521854 section_events.0.push(e);
18531855 }
18541856 }
git-config/src/values.rs+1−1
@@ -549,7 +549,7 @@ impl Integer { · 548 unmodified lines
549549 /// non-UTF-8 sequences are present or a UTF-8 representation can't be
550550 /// guaranteed.
551551 #[must_use]
552− pub fn to_vec(&self) -> Vec<u8> {
552+ pub fn to_vec(self) -> Vec<u8> {
553553 self.into()
554554 }
555555 }
git-hash/src/owned.rs+2−2
@@ -63,7 +63,7 @@ impl ObjectId { · 62 unmodified lines
6363 /// Return ourselves as array of 40 hexadecimal bytes.
6464 ///
6565 /// Panics if this instance is not a sha1 hash.
66− pub fn to_sha1_hex(&self) -> [u8; SIZE_OF_SHA1_DIGEST * 2] {
66+ pub fn to_sha1_hex(self) -> [u8; SIZE_OF_SHA1_DIGEST * 2] {
6767 match self {
6868 Self::Sha1(b) => {
6969 let mut hex_buf = [0u8; 40];
@@ -76,7 +76,7 @@ impl ObjectId { · 6 unmodified lines
7676 /// Return ourselves as hexadecimal string with a length of 40 bytes.
7777 ///
7878 /// Panics if this instance is not a sha1 hash.
79− pub fn to_sha1_hex_string(&self) -> String {
79+ pub fn to_sha1_hex_string(self) -> String {
8080 let buf = self.to_sha1_hex();
8181 std::str::from_utf8(&buf).expect("hex is valid UTF-8").to_string()
8282 }
git-object/src/mutable/tag.rs+1−1
@@ -46,7 +46,7 @@ impl Tag { · 45 unmodified lines
4646 /// Writes the encoded tag to `out`.
4747 pub fn write_to(&self, mut out: impl io::Write) -> io::Result<()> {
4848 encode::trusted_header_id(b"object", &self.target, &mut out)?;
49− encode::trusted_header_field(b"type", self.target_kind.to_bytes(), &mut out)?;
49+ encode::trusted_header_field(b"type", self.target_kind.as_bytes(), &mut out)?;
5050 encode::header_field(b"tag", validated_name(self.name.as_ref())?, &mut out)?;
5151 if let Some(tagger) = &self.signature {
5252 encode::trusted_header_signature(b"tagger", tagger, &mut out)?;
git-object/src/types.rs+2−2
@@ -87,7 +87,7 @@ impl Kind { · 86 unmodified lines
8787 }
8888
8989 /// Return the name of `self` for use in serialized loose git objects.
90− pub fn to_bytes(&self) -> &[u8] {
90+ pub fn as_bytes(&self) -> &[u8] {
9191 match self {
9292 Kind::Tree => b"tree",
9393 Kind::Commit => b"commit",
@@ -99,7 +99,7 @@ impl Kind { · 5 unmodified lines
9999
100100 impl fmt::Display for Kind {
101101 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
102− f.write_str(std::str::from_utf8(self.to_bytes()).expect("Converting Kind name to utf8"))
102+ f.write_str(std::str::from_utf8(self.as_bytes()).expect("Converting Kind name to utf8"))
103103 }
104104 }
105105
git-pack/src/data/entry/header.rs+4−4
@@ -44,7 +44,7 @@ impl Header { · 43 unmodified lines
4444 pack_offset.checked_sub(distance)
4545 }
4646 /// Convert the header's object kind into [`git_object::Kind`] if possible
47− pub fn to_kind(&self) -> Option<git_object::Kind> {
47+ pub fn as_kind(&self) -> Option<git_object::Kind> {
4848 use git_object::Kind::*;
4949 Some(match self {
5050 Header::Tree => Tree,
@@ -55,7 +55,7 @@ impl Header { · 4 unmodified lines
5555 })
5656 }
5757 /// Convert this header's object kind into the packs internal representation
58− pub fn to_type_id(&self) -> u8 {
58+ pub fn as_type_id(&self) -> u8 {
5959 use Header::*;
6060 match self {
6161 Blob => BLOB,
@@ -81,10 +81,10 @@ impl Header { · 19 unmodified lines
8181 ///
8282 /// Returns the amount of bytes written to `out`.
8383 /// `decompressed_size_in_bytes` is the full size in bytes of the object that this header represents
84− pub fn to_write(&self, decompressed_size_in_bytes: u64, mut out: impl io::Write) -> io::Result<usize> {
84+ pub fn write_to(&self, decompressed_size_in_bytes: u64, mut out: impl io::Write) -> io::Result<usize> {
8585 let mut size = decompressed_size_in_bytes;
8686 let mut written = 1;
87− let mut c: u8 = (self.to_type_id() << 4) | (size as u8 & 0b0000_1111);
87+ let mut c: u8 = (self.as_type_id() << 4) | (size as u8 & 0b0000_1111);
8888 size >>= 4;
8989 while size != 0 {
9090 out.write_all(&[c | 0b1000_0000])?;
git-pack/src/data/entry/mod.rs+1−1
@@ -36,7 +36,7 @@ impl Entry { · 35 unmodified lines
3636 /// The amount of bytes used to describe this entry in the pack. The header starts at [`Self::pack_offset()`]
3737 pub fn header_size(&self) -> usize {
3838 self.header
39− .to_write(self.decompressed_size, io::sink())
39+ .write_to(self.decompressed_size, io::sink())
4040 .expect("io::sink() to never fail")
4141 }
4242 }
git-pack/src/data/file/decode_entry.rs+2−2
@@ -153,7 +153,7 @@ impl File { · 152 unmodified lines
153153 );
154154 self.decompress_entry(&entry, out.as_mut_slice()).map(|consumed_input| {
155155 Outcome::from_object_entry(
156− entry.header.to_kind().expect("a non-delta entry"),
156+ entry.header.as_kind().expect("a non-delta entry"),
157157 &entry,
158158 consumed_input,
159159 )
@@ -314,7 +314,7 @@ impl File { · 154 unmodified lines
314314 if base_buffer_size.is_none() {
315315 let base_entry = cursor;
316316 debug_assert!(!base_entry.header.is_delta());
317− object_kind = base_entry.header.to_kind();
317+ object_kind = base_entry.header.as_kind();
318318 let packed_size = self.decompress_entry_from_data_offset(base_entry.data_offset, out)?;
319319 cache.put(
320320 self.id,
git-pack/src/data/input/iter.rs+1−1
@@ -138,7 +138,7 @@ where · 137 unmodified lines
138138
139139 let crc32 = if self.compressed.crc32() {
140140 let mut header_buf = [0u8; 32];
141− let header_len = entry.header.to_write(bytes_copied, header_buf.as_mut())?;
141+ let header_len = entry.header.write_to(bytes_copied, header_buf.as_mut())?;
142142 let state = git_features::hash::crc32_update(0, &header_buf[..header_len]);
143143 Some(git_features::hash::crc32_update(state, &compressed))
144144 } else {
git-pack/src/data/output/bytes.rs+1−1
@@ -100,7 +100,7 @@ where · 99 unmodified lines
100100 let header = entry.to_entry_header(self.entry_version, |_index_offset| {
101101 unimplemented!("a way to calculate pack offsets from object index offsets")
102102 });
103− written += header.to_write(entry.decompressed_size as u64, &mut self.output)? as u64;
103+ written += header.write_to(entry.decompressed_size as u64, &mut self.output)? as u64;
104104 written += std::io::copy(&mut &*entry.compressed_data, &mut self.output)? as u64;
105105 }
106106 }
git-pack/src/data/output/entry/mod.rs+1−1
@@ -80,7 +80,7 @@ impl output::Entry { · 79 unmodified lines
8080 if pack_entry.header.is_base() {
8181 Some(Ok(output::Entry {
8282 id: count.id.to_owned(),
83− object_kind: pack_entry.header.to_kind().expect("valid object only"),
83+ object_kind: pack_entry.header.as_kind().expect("valid object only"),
8484 kind: output::entry::Kind::Base,
8585 decompressed_size: pack_entry.decompressed_size as usize,
8686 compressed_data: entry.data[pack_entry.data_offset as usize..].to_owned(),
git-pack/src/index/traverse/indexed.rs+1−1
@@ -86,7 +86,7 @@ impl index::File { · 85 unmodified lines
8686 state: (ref mut processor, ref mut header_buf),
8787 level,
8888 }| {
89− let object_kind = pack_entry.header.to_kind().expect("non-delta object");
89+ let object_kind = pack_entry.header.as_kind().expect("non-delta object");
9090 data.level = level;
9191 data.decompressed_size = pack_entry.decompressed_size;
9292 data.object_kind = object_kind;
git-pack/src/index/write/mod.rs+1−1
@@ -230,7 +230,7 @@ fn modify_base( · 229 unmodified lines
230230 git_hash::ObjectId::from(write.hash.digest())
231231 }
232232
233− let object_kind = pack_entry.header.to_kind().expect("base object as source of iteration");
233+ let object_kind = pack_entry.header.as_kind().expect("base object as source of iteration");
234234 let id = compute_hash(object_kind, &decompressed, hash);
235235 entry.id = id;
236236 }
git-pack/tests/pack/iter.rs+1−1
@@ -29,7 +29,7 @@ mod new_from_header { · 28 unmodified lines
2929 let entry = entry?;
3030
3131 let mut buf = Vec::<u8>::new();
32− entry.header.to_write(entry.decompressed_size, &mut buf)?;
32+ entry.header.write_to(entry.decompressed_size, &mut buf)?;
3333 let new_entry = pack::data::Entry::from_bytes(&buf, entry.pack_offset);
3434
3535 assert_eq!(
git-packetline/src/immutable/blocking_io.rs+4−4
@@ -9,7 +9,7 @@ impl<'a> Band<'a> { · 8 unmodified lines
99 /// Serialize this instance to `out`, returning the amount of bytes written.
1010 ///
1111 /// The data written to `out` can be decoded with [`Borrowed::decode_band()]`.
12− pub fn to_write(&self, out: impl io::Write) -> io::Result<usize> {
12+ pub fn write_to(&self, out: impl io::Write) -> io::Result<usize> {
1313 match self {
1414 Band::Data(d) => encode::band_to_write(Channel::Data, d, out),
1515 Band::Progress(d) => encode::band_to_write(Channel::Progress, d, out),
@@ -20,7 +20,7 @@ impl<'a> Band<'a> { · 4 unmodified lines
2020
2121 impl<'a> Text<'a> {
2222 /// Serialize this instance to `out`, appending a newline if there is none, returning the amount of bytes written.
23− pub fn to_write(&self, out: impl io::Write) -> io::Result<usize> {
23+ pub fn write_to(&self, out: impl io::Write) -> io::Result<usize> {
2424 encode::text_to_write(self.0, out)
2525 }
2626 }
@@ -29,14 +29,14 @@ impl<'a> Error<'a> { · 2 unmodified lines
2929 /// Serialize this line as error to `out`.
3030 ///
3131 /// This includes a marker to allow decoding it outside of a side-band channel, returning the amount of bytes written.
32− pub fn to_write(&self, out: impl io::Write) -> io::Result<usize> {
32+ pub fn write_to(&self, out: impl io::Write) -> io::Result<usize> {
3333 encode::error_to_write(self.0, out)
3434 }
3535 }
3636
3737 impl<'a> PacketLine<'a> {
3838 /// Serialize this instance to `out` in git `packetline` format, returning the amount of bytes written to `out`.
39− pub fn to_write(&self, out: impl io::Write) -> io::Result<usize> {
39+ pub fn write_to(&self, out: impl io::Write) -> io::Result<usize> {
4040 match self {
4141 PacketLine::Data(d) => encode::data_to_write(d, out),
4242 PacketLine::Flush => encode::flush_to_write(out),
git-packetline/src/immutable/mod.rs+3−3
@@ -33,7 +33,7 @@ impl<'a> PacketLine<'a> { · 32 unmodified lines
3333 ///
3434 /// Note that this creates an unchecked error using the slice verbatim, which is useful to [serialize it][Error::to_write()].
3535 /// See [`check_error()`][PacketLine::check_error()] for a version that assures the error information is in the expected format.
36− pub fn to_error(&self) -> Option<Error<'_>> {
36+ pub fn as_error(&self) -> Option<Error<'_>> {
3737 self.as_slice().map(Error)
3838 }
3939 /// Check this instance's [`as_slice()`][PacketLine::as_slice()] is a valid [`Error`] and return it.
@@ -49,7 +49,7 @@ impl<'a> PacketLine<'a> { · 9 unmodified lines
4949 })
5050 }
5151 /// Return this instance as text, with the trailing newline truncated if present.
52− pub fn to_text(&self) -> Option<Text<'_>> {
52+ pub fn as_text(&self) -> Option<Text<'_>> {
5353 self.as_slice().map(Into::into)
5454 }
5555
@@ -57,7 +57,7 @@ impl<'a> PacketLine<'a> { · 1 unmodified line
5757 ///
5858 /// Note that this is only relevant in a side-band channel.
5959 /// See [`decode_band()`][PacketLine::decode_band()] in case `kind` is unknown.
60− pub fn to_band(&self, kind: Channel) -> Option<Band<'_>> {
60+ pub fn as_band(&self, kind: Channel) -> Option<Band<'_>> {
6161 self.as_slice().map(|d| match kind {
6262 Channel::Data => Band::Data(d),
6363 Channel::Progress => Band::Progress(d),
git-packetline/tests/decode/mod.rs+8−8
@@ -29,11 +29,11 @@ mod streaming { · 28 unmodified lines
2929 #[maybe_async::test(feature = "blocking-io", async(feature = "async-io", async_std::test))]
3030 async fn trailing_line_feeds_are_removed_explicitly() -> crate::Result {
3131 let line = decode::all_at_once(b"0006a\n")?;
32− assert_eq!(line.to_text().expect("text").0.as_bstr(), b"a".as_bstr());
32+ assert_eq!(line.as_text().expect("text").0.as_bstr(), b"a".as_bstr());
3333 let mut out = Vec::new();
34− line.to_text()
34+ line.as_text()
3535 .expect("text")
36− .to_write(&mut out)
36+ .write_to(&mut out)
3737 .await
3838 .expect("write to memory works");
3939 assert_eq!(out, b"0006a\n", "it appends a newline in text mode");
@@ -49,7 +49,7 @@ mod streaming { · 9 unmodified lines
4949 (PacketLine::Data(b"hello there"), 15),
5050 ] {
5151 let mut out = Vec::new();
52− line.to_write(&mut out).await?;
52+ line.write_to(&mut out).await?;
5353 assert_complete(streaming(&out), *bytes, *line)?;
5454 }
5555 Ok(())
@@ -59,9 +59,9 @@ mod streaming { · 3 unmodified lines
5959 async fn error_line() -> crate::Result {
6060 let mut out = Vec::new();
6161 PacketLine::Data(b"the error")
62− .to_error()
62+ .as_error()
6363 .expect("data line")
64− .to_write(&mut out)
64+ .write_to(&mut out)
6565 .await?;
6666 let line = decode::all_at_once(&out)?;
6767 assert_eq!(line.check_error().expect("err").0, b"the error");
@@ -73,9 +73,9 @@ mod streaming { · 5 unmodified lines
7373 for channel in &[Channel::Data, Channel::Error, Channel::Progress] {
7474 let mut out = Vec::new();
7575 let band = PacketLine::Data(b"band data")
76− .to_band(*channel)
76+ .as_band(*channel)
7777 .expect("data is valid for band");
78− band.to_write(&mut out).await?;
78+ band.write_to(&mut out).await?;
7979 let line = decode::all_at_once(&out)?;
8080 assert_eq!(line.decode_band().expect("valid band"), band);
8181 }
git-transport/src/client/async_io/request.rs+4−4
@@ -60,22 +60,22 @@ impl<'a> RequestWriter<'a> { · 59 unmodified lines
6060 match message {
6161 MessageKind::Flush => {
6262 git_packetline::PacketLine::Flush
63− .to_write(self.writer.inner_mut())
63+ .write_to(self.writer.inner_mut())
6464 .await
6565 }
6666 MessageKind::Delimiter => {
6767 git_packetline::PacketLine::Delimiter
68− .to_write(self.writer.inner_mut())
68+ .write_to(self.writer.inner_mut())
6969 .await
7070 }
7171 MessageKind::ResponseEnd => {
7272 git_packetline::PacketLine::ResponseEnd
73− .to_write(self.writer.inner_mut())
73+ .write_to(self.writer.inner_mut())
7474 .await
7575 }
7676 MessageKind::Text(t) => {
7777 git_packetline::immutable::Text::from(t)
78− .to_write(self.writer.inner_mut())
78+ .write_to(self.writer.inner_mut())
7979 .await
8080 }
8181 }
git-transport/src/client/blocking_io/request.rs+4−4
@@ -46,10 +46,10 @@ impl<'a> RequestWriter<'a> { · 45 unmodified lines
4646 /// Write the given message as packet line.
4747 pub fn write_message(&mut self, message: MessageKind) -> io::Result<()> {
4848 match message {
49− MessageKind::Flush => git_packetline::PacketLine::Flush.to_write(self.writer.inner_mut()),
50− MessageKind::Delimiter => git_packetline::PacketLine::Delimiter.to_write(self.writer.inner_mut()),
51− MessageKind::ResponseEnd => git_packetline::PacketLine::ResponseEnd.to_write(self.writer.inner_mut()),
52− MessageKind::Text(t) => git_packetline::immutable::Text::from(t).to_write(self.writer.inner_mut()),
49+ MessageKind::Flush => git_packetline::PacketLine::Flush.write_to(self.writer.inner_mut()),
50+ MessageKind::Delimiter => git_packetline::PacketLine::Delimiter.write_to(self.writer.inner_mut()),
51+ MessageKind::ResponseEnd => git_packetline::PacketLine::ResponseEnd.write_to(self.writer.inner_mut()),
52+ MessageKind::Text(t) => git_packetline::immutable::Text::from(t).write_to(self.writer.inner_mut()),
5353 }
5454 .map(|_| ())
5555 }
git-transport/src/client/capabilities.rs+1−1
@@ -139,7 +139,7 @@ impl Capabilities { · 138 unmodified lines
139139 capabilities_or_version: &'a git_packetline::PacketLine<'_>,
140140 ) -> Result<(git_packetline::immutable::Text<'a>, Protocol), client::Error> {
141141 let first_line = capabilities_or_version
142− .to_text()
142+ .as_text()
143143 .ok_or(client::Error::ExpectedLine("text"))?;
144144
145145 let line = first_line.as_bstr();