Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 16, 2020
1 parent 7c3c80a commit ba1d883
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions git-ref/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![forbid(unsafe_code)]
#![deny(rust_2018_idioms)]

pub mod validated;
1 change: 1 addition & 0 deletions git-repository/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![forbid(unsafe_code)]
#![deny(rust_2018_idioms)]

pub mod init;
8 changes: 5 additions & 3 deletions git-transport/src/client/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ impl Capabilities {
self.capability(feature).is_some()
}

pub fn capability(&self, name: &str) -> Option<Capability> {
pub fn capability(&self, name: &str) -> Option<Capability<'_>> {
self.iter().find(|c| c.name() == name.as_bytes().as_bstr())
}

pub fn iter(&self) -> impl Iterator<Item = Capability> {
pub fn iter(&self) -> impl Iterator<Item = Capability<'_>> {
self.data
.split(move |b| *b == self.value_sep)
.map(|c| Capability(c.as_bstr()))
Expand All @@ -125,7 +125,9 @@ pub(crate) mod recv {
pub protocol: Protocol,
}

pub fn v1_or_v2_as_detected<T: io::Read>(rd: &mut git_packetline::Provider<T>) -> Result<Outcome, client::Error> {
pub fn v1_or_v2_as_detected<T: io::Read>(
rd: &mut git_packetline::Provider<T>,
) -> Result<Outcome<'_>, client::Error> {
// NOTE that this is vitally important - it is turned on and stays on for all following requests so
// we automatically abort if the server sends an ERR line anywhere.
// We are sure this can't clash with binary data when sent due to the way the PACK
Expand Down
4 changes: 2 additions & 2 deletions git-transport/src/client/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ mod box_impl {
use std::ops::{Deref, DerefMut};

impl<T: client::Transport + ?Sized> client::Transport for Box<T> {
fn handshake(&mut self, service: Service) -> Result<SetServiceResponse, Error> {
fn handshake(&mut self, service: Service) -> Result<SetServiceResponse<'_>, Error> {
self.deref_mut().handshake(service)
}

fn set_identity(&mut self, identity: Identity) -> Result<(), Error> {
self.deref_mut().set_identity(identity)
}

fn request(&mut self, write_mode: WriteMode, on_into_read: MessageKind) -> Result<RequestWriter, Error> {
fn request(&mut self, write_mode: WriteMode, on_into_read: MessageKind) -> Result<RequestWriter<'_>, Error> {
self.deref_mut().request(write_mode, on_into_read)
}

Expand Down
8 changes: 6 additions & 2 deletions git-transport/src/client/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl SpawnProcessOnDemand {
}

impl client::Transport for SpawnProcessOnDemand {
fn handshake(&mut self, service: Service) -> Result<SetServiceResponse, client::Error> {
fn handshake(&mut self, service: Service) -> Result<SetServiceResponse<'_>, client::Error> {
assert!(
self.connection.is_none(),
"cannot handshake twice with the same connection"
Expand Down Expand Up @@ -119,7 +119,11 @@ impl client::Transport for SpawnProcessOnDemand {
c.handshake(service)
}

fn request(&mut self, write_mode: WriteMode, on_into_read: MessageKind) -> Result<RequestWriter, client::Error> {
fn request(
&mut self,
write_mode: WriteMode,
on_into_read: MessageKind,
) -> Result<RequestWriter<'_>, client::Error> {
self.connection
.as_mut()
.expect("handshake() to have been called first")
Expand Down
4 changes: 2 additions & 2 deletions git-transport/src/client/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ where
R: io::Read,
W: io::Write,
{
fn handshake(&mut self, service: Service) -> Result<SetServiceResponse, client::Error> {
fn handshake(&mut self, service: Service) -> Result<SetServiceResponse<'_>, client::Error> {
if self.mode == ConnectMode::Daemon {
let mut line_writer = git_packetline::Writer::new(&mut self.writer).binary_mode();
line_writer.write_all(&message::connect(
Expand Down Expand Up @@ -94,7 +94,7 @@ where
&mut self,
write_mode: client::WriteMode,
on_into_read: client::MessageKind,
) -> Result<client::RequestWriter, client::Error> {
) -> Result<client::RequestWriter<'_>, client::Error> {
Ok(client::RequestWriter::new_from_bufread(
&mut self.writer,
Box::new(self.line_provider.as_read_without_sidebands()),
Expand Down
8 changes: 4 additions & 4 deletions git-transport/src/client/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<H: Http> Transport<H> {
Ok(())
}

fn add_basic_auth_if_present(&self, headers: &mut Vec<Cow<str>>) -> Result<(), client::Error> {
fn add_basic_auth_if_present(&self, headers: &mut Vec<Cow<'_, str>>) -> Result<(), client::Error> {
if let Some(identity) = &self.identity {
match identity {
client::Identity::Account { username, password } => {
Expand Down Expand Up @@ -92,10 +92,10 @@ fn append_url(base: &str, suffix: &str) -> String {
}

impl<H: Http> client::Transport for Transport<H> {
fn handshake(&mut self, service: Service) -> Result<client::SetServiceResponse, client::Error> {
fn handshake(&mut self, service: Service) -> Result<client::SetServiceResponse<'_>, client::Error> {
let url = append_url(&self.url, &format!("info/refs?service={}", service.as_str()));
let static_headers = [Cow::Borrowed(self.user_agent_header)];
let mut dynamic_headers = Vec::<Cow<str>>::new();
let mut dynamic_headers = Vec::<Cow<'_, str>>::new();
if self.desired_version != Protocol::V1 {
dynamic_headers.push(Cow::Owned(format!(
"Git-Protocol: version={}",
Expand Down Expand Up @@ -144,7 +144,7 @@ impl<H: Http> client::Transport for Transport<H> {
&mut self,
write_mode: client::WriteMode,
on_into_read: client::MessageKind,
) -> Result<client::RequestWriter, client::Error> {
) -> Result<client::RequestWriter<'_>, client::Error> {
let service = self.service.expect("handshake() must have been called first");
let url = append_url(&self.url, service.as_str());
let static_headers = &[
Expand Down
4 changes: 2 additions & 2 deletions git-transport/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ pub trait Transport {
/// This means that asking for an unsupported protocol will result in a protocol downgrade to the given one.
/// using the `read_line(…)` function of the given BufReader. It must be exhausted, that is, read to the end,
/// before the next method can be invoked.
fn handshake(&mut self, service: Service) -> Result<SetServiceResponse, Error>;
fn handshake(&mut self, service: Service) -> Result<SetServiceResponse<'_>, Error>;

/// If the handshake or subsequent reads failed with io::ErrorKind::PermissionDenied, use this method to
/// inform the transport layer about the identity to use for subsequent calls.
Expand All @@ -235,7 +235,7 @@ pub trait Transport {
/// `send_mode` determines how calls to the `write(…)` method are interpreted, and `on_into_read` determines
/// which message to write when the writer is turned into the response reader using `into_read()`.
/// If `handle_progress` is not None, it's function passed a text line without trailing LF from which progress information can be parsed.
fn request(&mut self, write_mode: WriteMode, on_into_read: MessageKind) -> Result<RequestWriter, Error>;
fn request(&mut self, write_mode: WriteMode, on_into_read: MessageKind) -> Result<RequestWriter<'_>, Error>;

/// Closes the connection to indicate no further requests will be made.
fn close(&mut self) -> Result<(), Error>;
Expand Down
2 changes: 1 addition & 1 deletion git-transport/src/client/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn connect(
let ssh_cmd = ssh_cmd_line.next().expect("there is always a single item");

type EnvVar = (&'static str, String);
let args_and_env: Option<(Vec<Cow<str>>, Vec<EnvVar>)> = match ssh_cmd {
let args_and_env: Option<(Vec<Cow<'_, str>>, Vec<EnvVar>)> = match ssh_cmd {
"ssh" | "ssh.exe" => {
if version != Protocol::V1 {
let mut args = vec![Cow::from("-o"), "SendEnv=GIT_PROTOCOL".into()];
Expand Down
1 change: 1 addition & 0 deletions git-transport/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![forbid(unsafe_code)]
#![deny(rust_2018_idioms)]

#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
Expand Down

0 comments on commit ba1d883

Please sign in to comment.