don't
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(knot): merge and rename {std,tokio}::process::Command extension traits

Signed-off-by: tjh <x@tjh.dev>

tjh 2f446cfe 08a2f4dc

+47 -84
+39 -75
crates/gordian-knot/src/command.rs
··· 1 1 use std::ffi::OsStr; 2 2 3 + pub trait CommandExt { 4 + /// Insert or update an environment variable mapping if, and only if, 5 + /// `val` is [`Some`]. 6 + fn option_env<K, V>(&mut self, key: K, val: Option<V>) -> &mut Self 7 + where 8 + K: AsRef<OsStr>, 9 + V: AsRef<OsStr>; 10 + 11 + /// Append an argument if, and only if, `arg` is [`Some`]. 12 + fn option_arg<V>(&mut self, arg: Option<V>) -> &mut Self 13 + where 14 + V: AsRef<OsStr>; 15 + } 16 + 17 + impl<T: SetEnv + SetArg> CommandExt for T { 18 + fn option_env<K, V>(&mut self, key: K, val: Option<V>) -> &mut Self 19 + where 20 + K: AsRef<OsStr>, 21 + V: AsRef<OsStr>, 22 + { 23 + if let Some(val) = val { 24 + self.env(key, val); 25 + } 26 + self 27 + } 28 + 29 + fn option_arg<V>(&mut self, arg: Option<V>) -> &mut Self 30 + where 31 + V: AsRef<OsStr>, 32 + { 33 + if let Some(arg) = arg { 34 + self.arg(arg); 35 + } 36 + self 37 + } 38 + } 39 + 3 40 trait SetEnv { 4 41 fn env<K, V>(&mut self, key: K, val: V) -> &mut Self 5 42 where ··· 61 24 impl_set_env!(std::process::Command); 62 25 impl_set_env!(tokio::process::Command); 63 26 64 - pub trait SetOptionEnv { 65 - /// Inserts or updates an environment variable mapping if, and only if, 66 - /// `val` is [`Some`]. 67 - fn option_env<K, V>(&mut self, key: K, val: Option<V>) -> &mut Self 68 - where 69 - K: AsRef<OsStr>, 70 - V: AsRef<OsStr>; 71 - } 72 - 73 - impl<T: SetEnv> SetOptionEnv for T { 74 - fn option_env<K, V>(&mut self, key: K, val: Option<V>) -> &mut Self 75 - where 76 - K: AsRef<OsStr>, 77 - V: AsRef<OsStr>, 78 - { 79 - if let Some(val) = val { 80 - self.env(key, val); 81 - } 82 - self 83 - } 84 - } 85 - 86 27 trait SetArg { 87 28 fn arg<V>(&mut self, arg: V) -> &mut Self 88 29 where ··· 83 68 impl_set_arg!(std::process::Command); 84 69 impl_set_arg!(tokio::process::Command); 85 70 86 - pub trait SetOptionArg { 87 - fn option_arg<V>(&mut self, arg: Option<V>) -> &mut Self 88 - where 89 - V: AsRef<OsStr>; 90 - } 91 - 92 - impl<T: SetArg> SetOptionArg for T { 93 - fn option_arg<V>(&mut self, arg: Option<V>) -> &mut Self 94 - where 95 - V: AsRef<OsStr>, 96 - { 97 - if let Some(arg) = arg { 98 - self.arg(arg); 99 - } 100 - self 101 - } 102 - } 103 - 104 - pub trait TraceProcessCompletion { 71 + pub trait ChildExt { 105 72 fn wait_with_completion_trace(self) -> impl Future<Output = ()>; 106 73 } 107 74 108 - impl TraceProcessCompletion for tokio::process::Child { 75 + impl ChildExt for tokio::process::Child { 109 76 async fn wait_with_completion_trace(self) { 110 77 use std::process::Output; 111 78 ··· 116 119 Err(error) => { 117 120 tracing::error!(?error); 118 121 } 119 - } 120 - } 121 - } 122 - 123 - pub async fn await_child(child: tokio::process::Child) -> bool { 124 - match child.wait_with_output().await { 125 - Ok(output) if output.status.success() => { 126 - if !output.stderr.is_empty() { 127 - let stderr = std::str::from_utf8(&output.stderr).unwrap_or("non-utf8 in stderr"); 128 - tracing::warn!("git child process completed with errors. stderr:\n{stderr}"); 129 - } 130 - true 131 - } 132 - Ok(output) => { 133 - let status = output.status; 134 - if let Ok(stderr) = std::str::from_utf8(&output.stderr) { 135 - tracing::error!( 136 - ?status, 137 - "error waiting for git child process. stderr:\n{stderr}" 138 - ) 139 - } else { 140 - tracing::error!( 141 - ?status, 142 - "error waiting for git child process. stderr:\n{:?}\n{}", 143 - &output.stderr, 144 - String::from_utf8_lossy(&output.stderr) 145 - ) 146 - } 147 - false 148 - } 149 - Err(error) => { 150 - tracing::error!(?error); 151 - false 152 122 } 153 123 } 154 124 }
+1 -2
crates/gordian-knot/src/model/repository.rs
··· 29 29 use serde::Deserialize; 30 30 31 31 use super::Knot; 32 - use crate::command::SetOptionArg as _; 33 - use crate::command::SetOptionEnv as _; 32 + use crate::command::CommandExt as _; 34 33 use crate::model::convert; 35 34 use crate::model::errors; 36 35 use crate::model::nicediff;
+2 -2
crates/gordian-knot/src/public/git/receive_pack.rs
··· 12 12 use tokio::net::unix::pipe::Sender; 13 13 use tokio::net::unix::pipe::pipe as async_pipe; 14 14 15 - use crate::command::SetOptionEnv as _; 16 - use crate::command::TraceProcessCompletion as _; 15 + use crate::command::ChildExt as _; 16 + use crate::command::CommandExt as _; 17 17 use crate::extractors::GitProtocol; 18 18 use crate::extractors::request_id::RequestId; 19 19 use crate::model::Knot;
+2 -2
crates/gordian-knot/src/public/git/upload_archive.rs
··· 8 8 use tokio::io::AsyncWriteExt as _; 9 9 use tokio::net::unix::pipe::Sender; 10 10 11 - use crate::command::SetOptionEnv as _; 12 - use crate::command::TraceProcessCompletion as _; 11 + use crate::command::ChildExt as _; 12 + use crate::command::CommandExt as _; 13 13 use crate::extractors::GitProtocol; 14 14 use crate::extractors::request_id::RequestId; 15 15 use crate::model::Knot;
+2 -2
crates/gordian-knot/src/public/git/upload_pack.rs
··· 11 11 use tokio::net::unix::pipe::Sender; 12 12 use tokio::net::unix::pipe::pipe as async_pipe; 13 13 14 - use crate::command::SetOptionEnv as _; 15 - use crate::command::TraceProcessCompletion; 14 + use crate::command::ChildExt; 15 + use crate::command::CommandExt as _; 16 16 use crate::extractors::GitProtocol; 17 17 use crate::extractors::request_id::RequestId; 18 18 use crate::model::Knot;
+1 -1
crates/gordian-knot/src/public/xrpc/sh_tangled/repo/impl_archive.rs
··· 10 10 use gordian_lexicon::sh_tangled::repo::archive::Format; 11 11 use gordian_lexicon::sh_tangled::repo::archive::Input; 12 12 13 - use crate::command::SetOptionArg as _; 13 + use crate::command::CommandExt as _; 14 14 use crate::model::Knot; 15 15 use crate::model::errors; 16 16 use crate::model::repository::ResolvedRevspec;