~kennylevinsen/greetd-devel

Remove no-op question mark and Ok() v1 APPLIED

Hugo Osvaldo Barrera: 5
 Remove no-op question mark and Ok()
 Remove references that are implicitly dereferenced
 Remove pointless copying of string before copying it
 Use strip_prefix to strip prefix
 Derive VtSelection::default

 10 files changed, 20 insertions(+), 25 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~kennylevinsen/greetd-devel/patches/41964/mbox | git am -3
Learn more about email & git

[PATCH 1/5] Remove no-op question mark and Ok() Export this patch

---
 agreety/src/main.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/agreety/src/main.rs b/agreety/src/main.rs
index 22ff87e..b687798 100644
--- a/agreety/src/main.rs
+++ b/agreety/src/main.rs
@@ -29,9 +29,9 @@ fn get_distro_name() -> Result<String, Box<dyn std::error::Error>> {
    let os_release = fs::read_to_string("/etc/os-release")?;
    let parsed = inish::parse(&os_release)?;
    let general = parsed.get("").ok_or("no general section")?;
    Ok(maybe_unquote(
    maybe_unquote(
        general.get("PRETTY_NAME").ok_or("no pretty name")?,
    )?)
    )
}

fn get_issue() -> Result<String, Box<dyn std::error::Error>> {
-- 
2.41.0
Applied, thanks!

[PATCH 2/5] Remove references that are implicitly dereferenced Export this patch

This are implicitly dereferenced by the compiler and a no-op.
---
 agreety/src/main.rs       | 10 +++++-----
 fakegreet/src/main.rs     |  4 ++--
 greetd/src/context.rs     |  2 +-
 greetd/src/pam/session.rs |  2 +-
 greetd/src/server.rs      |  4 ++--
 inish/src/lib.rs          |  2 +-
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/agreety/src/main.rs b/agreety/src/main.rs
index b687798..b312e56 100644
--- a/agreety/src/main.rs
+++ b/agreety/src/main.rs
@@ -46,11 +46,11 @@ fn get_issue() -> Result<String, Box<dyn std::error::Error>> {
            &get_distro_name().unwrap_or_else(|_| "Linux".to_string()),
        )
        .replace("\\l", &format!("tty{}", vtnr))
        .replace("\\s", &uts.sysname().to_str().unwrap())
        .replace("\\r", &uts.release().to_str().unwrap())
        .replace("\\v", &uts.version().to_str().unwrap())
        .replace("\\n", &uts.nodename().to_str().unwrap())
        .replace("\\m", &uts.machine().to_str().unwrap())
        .replace("\\s", uts.sysname().to_str().unwrap())
        .replace("\\r", uts.release().to_str().unwrap())
        .replace("\\v", uts.version().to_str().unwrap())
        .replace("\\n", uts.nodename().to_str().unwrap())
        .replace("\\m", uts.machine().to_str().unwrap())
        .replace("\\\\", "\\"))
}

diff --git a/fakegreet/src/main.rs b/fakegreet/src/main.rs
index 89aa05b..c915d93 100644
--- a/fakegreet/src/main.rs
+++ b/fakegreet/src/main.rs
@@ -128,12 +128,12 @@ async fn client_handler(ctx: &Context, mut s: UnixStream) -> Result<(), Error> {
        println!("req: {:?}", req);
        let resp = match req {
            Request::CreateSession { username } => match ctx.create_session(username).await {
                Ok(()) => client_get_question(&ctx).await,
                Ok(()) => client_get_question(ctx).await,
                res => wrap_result(res),
            },
            Request::PostAuthMessageResponse { response } => {
                match ctx.post_response(response).await {
                    Ok(()) => client_get_question(&ctx).await,
                    Ok(()) => client_get_question(ctx).await,
                    res => wrap_result(res),
                }
            }
diff --git a/greetd/src/context.rs b/greetd/src/context.rs
index 1f32ad5..fda8e52 100644
--- a/greetd/src/context.rs
+++ b/greetd/src/context.rs
@@ -87,7 +87,7 @@ impl Context {
        let mut scheduled_session = Session::new_external()?;
        scheduled_session
            .initiate(
                &service,
                service,
                class,
                user,
                false,
diff --git a/greetd/src/pam/session.rs b/greetd/src/pam/session.rs
index 9235336..4bbb39a 100644
--- a/greetd/src/pam/session.rs
+++ b/greetd/src/pam/session.rs
@@ -29,7 +29,7 @@ impl<'a> PamSession<'a> {
        pam_conv: Pin<Box<dyn Converse + 'a>>,
    ) -> Result<PamSession<'a>, PamError> {
        let mut pch = Box::pin(PamConvHandlerWrapper { handler: pam_conv });
        let conv = make_conversation(&mut *pch);
        let conv = make_conversation(&mut pch);
        let mut pam_handle: *mut PamHandle = ptr::null_mut();

        match pam_sys::start(service, Some(user), &conv, &mut pam_handle) {
diff --git a/greetd/src/server.rs b/greetd/src/server.rs
index f9adf26..27c3ad1 100644
--- a/greetd/src/server.rs
+++ b/greetd/src/server.rs
@@ -76,12 +76,12 @@ async fn client_handler(ctx: &Context, mut s: UnixStream) -> Result<(), Error> {

        let resp = match req {
            Request::CreateSession { username } => match ctx.create_session(username).await {
                Ok(()) => client_get_question(&ctx).await,
                Ok(()) => client_get_question(ctx).await,
                res => wrap_result(res),
            },
            Request::PostAuthMessageResponse { response } => {
                match ctx.post_response(response).await {
                    Ok(()) => client_get_question(&ctx).await,
                    Ok(()) => client_get_question(ctx).await,
                    res => wrap_result(res),
                }
            }
diff --git a/inish/src/lib.rs b/inish/src/lib.rs
index 13bb056..131c941 100644
--- a/inish/src/lib.rs
+++ b/inish/src/lib.rs
@@ -31,7 +31,7 @@ pub fn parse<'a>(s: &'a str) -> Result<Inish<'a>, Box<dyn Error>> {
                sections.insert(current_section_name, current_section);
                current_section = HashMap::new();
                let len = line.bytes().count();
                current_section_name = &line[1..len - 1].trim();
                current_section_name = line[1..len - 1].trim();
            }
            (Some('['), v) => {
                return Err(format!(
-- 
2.41.0

[PATCH 3/5] Remove pointless copying of string before copying it Export this patch

---
 agreety/src/main.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/agreety/src/main.rs b/agreety/src/main.rs
index b312e56..2db4e2e 100644
--- a/agreety/src/main.rs
+++ b/agreety/src/main.rs
@@ -148,7 +148,7 @@ fn main() {
    let matches = match opts.parse(&args[1..]) {
        Ok(m) => m,
        Err(f) => {
            println!("{}", f.to_string());
            println!("{}", f);
            print_usage(&program, opts);
            std::process::exit(1);
        }
-- 
2.41.0

[PATCH 4/5] Use strip_prefix to strip prefix Export this patch

No need to do it manually.
---
 agreety/src/main.rs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/agreety/src/main.rs b/agreety/src/main.rs
index 2db4e2e..73295a9 100644
--- a/agreety/src/main.rs
+++ b/agreety/src/main.rs
@@ -62,9 +62,9 @@ enum LoginResult {
fn login(node: &str, cmd: &mut Option<String>) -> Result<LoginResult, Box<dyn std::error::Error>> {
    let username = loop {
        let username = prompt_stderr(&format!("{} login: ", node))?;
        if username.starts_with('!') {
            *cmd = Some(username[1..].to_string());
            eprintln!("Login command changed to: {}", &username[1..]);
        if let Some(u) = username.strip_prefix('!') {
            *cmd = Some(u.to_string());
            eprintln!("Login command changed to: {u}");
            continue;
        }
        break username;
-- 
2.41.0

[PATCH 5/5] Derive VtSelection::default Export this patch

---
 greetd/src/config/mod.rs | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/greetd/src/config/mod.rs b/greetd/src/config/mod.rs
index 642feec..e77a155 100644
--- a/greetd/src/config/mod.rs
+++ b/greetd/src/config/mod.rs
@@ -9,20 +9,15 @@ const RUNFILE: &str = "/run/greetd.run";
const GENERAL_SERVICE: &str = "greetd";
const GREETER_SERVICE: &str = "greetd-greeter";

#[derive(Debug, Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq, Default)]
pub enum VtSelection {
    Next,
    Current,
    #[default]
    None,
    Specific(usize),
}

impl Default for VtSelection {
    fn default() -> Self {
        VtSelection::None
    }
}

#[derive(Debug, Eq, PartialEq, Default)]
pub struct ConfigSession {
    pub command: String,
-- 
2.41.0