diff options
Diffstat (limited to 'crates/shirabe')
31 files changed, 182 insertions, 251 deletions
diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs index 6757d94..99118cd 100644 --- a/crates/shirabe/src/command/diagnose_command.rs +++ b/crates/shirabe/src/command/diagnose_command.rs @@ -532,7 +532,7 @@ impl DiagnoseCommand { "color.ui".to_string(), ], &mut output, - (), + None, ); if strtolower(&trim(&output, Some(" \t\n\r\0\u{0B}"))) == "always" { return "<comment>Your git color.ui setting is set to always, this is known to create issues. Use \"git config --global color.ui true\" to set it correctly.</comment>".to_string(); diff --git a/crates/shirabe/src/command/home_command.rs b/crates/shirabe/src/command/home_command.rs index b3bb3ff..081ce2d 100644 --- a/crates/shirabe/src/command/home_command.rs +++ b/crates/shirabe/src/command/home_command.rs @@ -92,22 +92,22 @@ impl HomeCommand { let _ = process.execute( PhpMixed::from(vec!["start", "\"web\"", "explorer", url]), (), - (), + None, ); return; } let linux = process - .execute(PhpMixed::from(vec!["which", "xdg-open"]), (), ()) + .execute(PhpMixed::from(vec!["which", "xdg-open"]), (), None) .unwrap_or(1); let osx = process - .execute(PhpMixed::from(vec!["which", "open"]), (), ()) + .execute(PhpMixed::from(vec!["which", "open"]), (), None) .unwrap_or(1); if linux == 0 { - let _ = process.execute(PhpMixed::from(vec!["xdg-open", url]), (), ()); + let _ = process.execute(PhpMixed::from(vec!["xdg-open", url]), (), None); } else if osx == 0 { - let _ = process.execute(PhpMixed::from(vec!["open", url]), (), ()); + let _ = process.execute(PhpMixed::from(vec!["open", url]), (), None); } else { self.get_io().write_error(&format!( "No suitable browser opening command found, open yourself: {}", diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs index d98793a..9683b89 100644 --- a/crates/shirabe/src/command/init_command.rs +++ b/crates/shirabe/src/command/init_command.rs @@ -1010,7 +1010,7 @@ impl InitCommand { if process.execute_args( &["git".to_string(), "config".to_string(), "-l".to_string()], &mut output, - (), + None, ) == 0 { *self.git_config.borrow_mut() = Some(IndexMap::new()); diff --git a/crates/shirabe/src/downloader/fossil_downloader.rs b/crates/shirabe/src/downloader/fossil_downloader.rs index ab98168..26a0987 100644 --- a/crates/shirabe/src/downloader/fossil_downloader.rs +++ b/crates/shirabe/src/downloader/fossil_downloader.rs @@ -43,7 +43,7 @@ impl FossilDownloader { .inner .process .borrow_mut() - .execute(&command, output, cwd)? + .execute(&command, output, cwd.as_deref())? != 0 { return Err(RuntimeException { @@ -271,7 +271,7 @@ impl ChangeReportInterface for FossilDownloader { self.inner.process.borrow_mut().execute_args( &["fossil".to_string(), "changes".to_string()], &mut output, - shirabe_php_shim::realpath(path), + shirabe_php_shim::realpath(path).as_deref(), ); let output = output.trim().to_string(); diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs index fa7fd16..a3666d0 100644 --- a/crates/shirabe/src/downloader/git_downloader.rs +++ b/crates/shirabe/src/downloader/git_downloader.rs @@ -83,7 +83,7 @@ impl GitDownloader { .inner .process .borrow_mut() - .execute_args(&command, &mut output, Some(path.clone())) + .execute_args(&command, &mut output, Some(&path)) != 0 { return Err(RuntimeException { @@ -179,7 +179,7 @@ impl GitDownloader { if self.inner.process.borrow_mut().execute_args( &command, &mut output, - Some(path.clone()), + Some(&path), ) != 0 { return Err(RuntimeException { @@ -210,7 +210,7 @@ impl GitDownloader { self.inner.process.borrow_mut().execute_args( &["git".to_string(), "fetch".to_string(), "--all".to_string()], &mut output, - Some(path.clone()), + Some(&path), ); // update list of refs after fetching @@ -221,11 +221,12 @@ impl GitDownloader { "-d".to_string(), ]; let mut output = String::new(); - if self.inner.process.borrow_mut().execute_args( - &command, - &mut output, - Some(path.clone()), - ) != 0 + if self + .inner + .process + .borrow_mut() + .execute_args(&command, &mut output, Some(&path)) + != 0 { return Err(RuntimeException { message: format!( @@ -289,7 +290,7 @@ impl GitDownloader { if self.inner.process.borrow_mut().execute_args( &["git".to_string(), "branch".to_string(), "-r".to_string()], &mut output, - Some(path.to_string()), + Some(path), ) == 0 { branches = Some(output); @@ -322,18 +323,19 @@ impl GitDownloader { ]; let mut output = String::new(); - let ok1 = self.inner.process.borrow_mut().execute_args( - &command1, - &mut output, - Some(path.to_string()), - ) == 0; + let ok1 = + self.inner + .process + .borrow_mut() + .execute_args(&command1, &mut output, Some(path)) + == 0; let ok2 = if ok1 { let mut output = String::new(); - self.inner.process.borrow_mut().execute_args( - &command2, - &mut output, - Some(path.to_string()), - ) == 0 + self.inner + .process + .borrow_mut() + .execute_args(&command2, &mut output, Some(path)) + == 0 } else { false }; @@ -381,17 +383,18 @@ impl GitDownloader { ]; let mut output = String::new(); - let ok_command = self.inner.process.borrow_mut().execute_args( - &command, - &mut output, - Some(path.to_string()), - ) == 0; + let ok_command = + self.inner + .process + .borrow_mut() + .execute_args(&command, &mut output, Some(path)) + == 0; let ok_fallback = if !ok_command { let mut output = String::new(); self.inner.process.borrow_mut().execute_args( &fallback_command, &mut output, - Some(path.to_string()), + Some(path), ) == 0 } else { false @@ -401,7 +404,7 @@ impl GitDownloader { self.inner.process.borrow_mut().execute_args( &reset_command, &mut output, - Some(path.to_string()), + Some(path), ) == 0 } else { false @@ -423,18 +426,19 @@ impl GitDownloader { ]; { let mut output = String::new(); - let ok1 = self.inner.process.borrow_mut().execute_args( - &command1, - &mut output, - Some(path.to_string()), - ) == 0; + let ok1 = + self.inner + .process + .borrow_mut() + .execute_args(&command1, &mut output, Some(path)) + == 0; let ok2 = if ok1 { let mut output = String::new(); - self.inner.process.borrow_mut().execute_args( - &command2, - &mut output, - Some(path.to_string()), - ) == 0 + self.inner + .process + .borrow_mut() + .execute_args(&command2, &mut output, Some(path)) + == 0 } else { false }; @@ -492,7 +496,7 @@ impl GitDownloader { url.to_string(), ], &mut output, - Some(path.to_string()), + Some(path), ); self.set_push_url(path, url); } @@ -535,11 +539,10 @@ impl GitDownloader { push_url, ]; let mut ignored_output = String::new(); - self.inner.process.borrow_mut().execute_args( - &cmd, - &mut ignored_output, - Some(path.to_string()), - ); + self.inner + .process + .borrow_mut() + .execute_args(&cmd, &mut ignored_output, Some(path)); } } @@ -551,7 +554,7 @@ impl GitDownloader { if self.inner.process.borrow_mut().execute_args( &["git".to_string(), "clean".to_string(), "-df".to_string()], &mut output, - Some(path.clone()), + Some(&path), ) != 0 { return Err(RuntimeException { @@ -564,7 +567,7 @@ impl GitDownloader { if self.inner.process.borrow_mut().execute_args( &["git".to_string(), "reset".to_string(), "--hard".to_string()], &mut output, - Some(path.clone()), + Some(&path), ) != 0 { return Err(RuntimeException { @@ -591,7 +594,7 @@ impl GitDownloader { "--include-untracked".to_string(), ], &mut output, - Some(path.clone()), + Some(&path), ) != 0 { return Err(RuntimeException { @@ -613,7 +616,7 @@ impl GitDownloader { if self.inner.process.borrow_mut().execute_args( &["git".to_string(), "diff".to_string(), "HEAD".to_string()], &mut output, - Some(path.clone()), + Some(&path), ) != 0 { return Err(RuntimeException { @@ -711,11 +714,12 @@ impl ChangeReportInterface for GitDownloader { "--untracked-files=no".to_string(), ]; let mut output = String::new(); - if self.inner.process.borrow_mut().execute_args( - &command, - &mut output, - Some(path.to_string()), - ) != 0 + if self + .inner + .process + .borrow_mut() + .execute_args(&command, &mut output, Some(path)) + != 0 { return Err(RuntimeException { message: format!( @@ -1061,7 +1065,7 @@ impl VcsDownloader for GitDownloader { format!("{}^{{commit}}", r#ref), ], &mut output, - Some(path.clone()), + Some(&path), ) != 0 { let commands = vec![ @@ -1116,7 +1120,7 @@ impl VcsDownloader for GitDownloader { if self.inner.process.borrow_mut().execute_args( &["git".to_string(), "remote".to_string(), "-v".to_string()], &mut output, - Some(path.clone()), + Some(&path), ) == 0 { let mut origin_match: IndexMap<CaptureKey, String> = IndexMap::new(); @@ -1334,7 +1338,7 @@ impl VcsDownloader for GitDownloader { if self.inner.process.borrow_mut().execute_args( &["git".to_string(), "stash".to_string(), "pop".to_string()], &mut output, - Some(path.clone()), + Some(&path), ) != 0 { return Err(RuntimeException { @@ -1371,7 +1375,7 @@ impl VcsDownloader for GitDownloader { .inner .process .borrow_mut() - .execute_args(&command, &mut output, Some(path.clone())) + .execute_args(&command, &mut output, Some(&path)) != 0 { return Err(RuntimeException { diff --git a/crates/shirabe/src/downloader/gzip_downloader.rs b/crates/shirabe/src/downloader/gzip_downloader.rs index aefc6f9..8146145 100644 --- a/crates/shirabe/src/downloader/gzip_downloader.rs +++ b/crates/shirabe/src/downloader/gzip_downloader.rs @@ -120,7 +120,7 @@ impl ArchiveDownloader for GzipDownloader { .collect(), ), Some(&mut process_output), - (), + None, )? == 0 { return Ok(None); diff --git a/crates/shirabe/src/downloader/hg_downloader.rs b/crates/shirabe/src/downloader/hg_downloader.rs index 16a78a0..650746b 100644 --- a/crates/shirabe/src/downloader/hg_downloader.rs +++ b/crates/shirabe/src/downloader/hg_downloader.rs @@ -114,7 +114,7 @@ impl VcsDownloader for HgDownloader { if self.inner.process.borrow_mut().execute_args( &command, &mut ignored_output, - shirabe_php_shim::realpath(path), + shirabe_php_shim::realpath(path).as_deref(), ) != 0 { return Err(RuntimeException { @@ -201,7 +201,7 @@ impl VcsDownloader for HgDownloader { if self.inner.process.borrow_mut().execute_args( &command, &mut output, - shirabe_php_shim::realpath(path), + shirabe_php_shim::realpath(path).as_deref(), ) != 0 { return Err(RuntimeException { @@ -237,7 +237,7 @@ impl ChangeReportInterface for HgDownloader { self.inner.process.borrow_mut().execute_args( &["hg".to_string(), "st".to_string()], &mut output, - shirabe_php_shim::realpath(path), + shirabe_php_shim::realpath(path).as_deref(), ); let output = output.trim().to_string(); diff --git a/crates/shirabe/src/downloader/rar_downloader.rs b/crates/shirabe/src/downloader/rar_downloader.rs index 29ea491..73d5fdf 100644 --- a/crates/shirabe/src/downloader/rar_downloader.rs +++ b/crates/shirabe/src/downloader/rar_downloader.rs @@ -93,7 +93,7 @@ impl ArchiveDownloader for RarDownloader { .collect(), ), Some(&mut process_output), - (), + None, )? == 0 { return Ok(None); diff --git a/crates/shirabe/src/downloader/svn_downloader.rs b/crates/shirabe/src/downloader/svn_downloader.rs index 6aed27a..1a7d81d 100644 --- a/crates/shirabe/src/downloader/svn_downloader.rs +++ b/crates/shirabe/src/downloader/svn_downloader.rs @@ -69,7 +69,7 @@ impl SvnDownloader { if self.inner.process.borrow_mut().execute_args( ["svn", "revert", "-R", "."].map(|s| s.to_string()).as_ref(), &mut output, - Some(path.to_string()), + Some(path), ) != 0 { return Err(RuntimeException { @@ -378,11 +378,12 @@ impl VcsDownloader for SvnDownloader { path.to_string(), ]; let mut output = String::new(); - if self.inner.process.borrow_mut().execute_args( - &command, - &mut output, - Some(path.to_string()), - ) != 0 + if self + .inner + .process + .borrow_mut() + .execute_args(&command, &mut output, Some(path)) + != 0 { return Err(RuntimeException { message: format!( @@ -466,7 +467,7 @@ impl ChangeReportInterface for SvnDownloader { .map(|s| s.to_string()) .as_ref(), &mut output, - Some(path.to_string()), + Some(path), ); Ok(if Preg::is_match("{^ *[^X ] +}m", &output) { diff --git a/crates/shirabe/src/downloader/xz_downloader.rs b/crates/shirabe/src/downloader/xz_downloader.rs index d79f9bc..d7f94c3 100644 --- a/crates/shirabe/src/downloader/xz_downloader.rs +++ b/crates/shirabe/src/downloader/xz_downloader.rs @@ -80,7 +80,7 @@ impl ArchiveDownloader for XzDownloader { .collect(), ), Some(&mut ignored_output), - (), + None, )? == 0 { return Ok(None); diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs index d7508a6..bea2b20 100644 --- a/crates/shirabe/src/downloader/zip_downloader.rs +++ b/crates/shirabe/src/downloader/zip_downloader.rs @@ -132,7 +132,7 @@ impl ZipDownloader { .inner .process .borrow_mut() - .execute_async(&command, ()) + .execute_async(&command, None) .await; match process_result { Ok(mut process) => { diff --git a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs index 3ef7661..acc3138 100644 --- a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs +++ b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs @@ -782,10 +782,10 @@ impl EventDispatcher { fn execute_tty(&self, exec: &str) -> anyhow::Result<i64> { if self.io.is_interactive() { - return self.process.borrow_mut().execute_tty(exec, ()); + return self.process.borrow_mut().execute_tty(exec, None); } - self.process.borrow_mut().execute(exec, (), ()) + self.process.borrow_mut().execute(exec, (), None) } fn get_php_exec_command(&self) -> anyhow::Result<String> { diff --git a/crates/shirabe/src/package/version/version_guesser.rs b/crates/shirabe/src/package/version/version_guesser.rs index e13eb5d..5745d68 100644 --- a/crates/shirabe/src/package/version/version_guesser.rs +++ b/crates/shirabe/src/package/version/version_guesser.rs @@ -193,7 +193,7 @@ impl VersionGuesser { "-v".to_string(), ], &mut output, - Some(path.to_string()), + Some(path), ) { let mut branches: Vec<String> = vec![]; let mut is_feature_branch = false; @@ -306,7 +306,7 @@ impl VersionGuesser { if 0 == self.process.borrow_mut().execute_args( &command, &mut command_output, - Some(path.to_string()), + Some(path), ) { let parsed = trim( &GitUtil::parse_rev_list_output(&command_output, &self.process), @@ -341,7 +341,7 @@ impl VersionGuesser { "--tags".to_string(), ], &mut output, - Some(path.to_string()), + Some(path), ) { match self.version_parser.normalize(&trim(&output, None), None) { Ok(version) => return Ok(Some((version, trim(&output, None)))), @@ -365,7 +365,7 @@ impl VersionGuesser { if 0 == self.process.borrow_mut().execute_args( &["hg".to_string(), "branch".to_string()], &mut output, - Some(path.to_string()), + Some(path), ) { let branch = trim(&output, None); let version = self.version_parser.normalize_branch(&branch)?; @@ -533,9 +533,11 @@ impl VersionGuesser { }, &scm_cmdline, ); - let mut process = tokio::runtime::Runtime::new() - .unwrap() - .block_on(self.process.borrow_mut().execute_async(&cmd_line, path))?; + let mut process = tokio::runtime::Runtime::new().unwrap().block_on( + self.process + .borrow_mut() + .execute_async(&cmd_line, Some(path)), + )?; if !process.is_successful() { continue; } @@ -611,7 +613,7 @@ impl VersionGuesser { "list".to_string(), ], &mut output, - Some(path.to_string()), + Some(path), ) { let branch = trim(&output, None); version = Some(self.version_parser.normalize_branch(&branch)?); @@ -623,7 +625,7 @@ impl VersionGuesser { if 0 == self.process.borrow_mut().execute_args( &["fossil".to_string(), "tag".to_string(), "list".to_string()], &mut output, - Some(path.to_string()), + Some(path), ) { match self.version_parser.normalize(&trim(&output, None), None) { Ok(v) => { @@ -658,7 +660,7 @@ impl VersionGuesser { if 0 == self.process.borrow_mut().execute_args( &["svn".to_string(), "info".to_string(), "--xml".to_string()], &mut output, - Some(path.to_string()), + Some(path), ) { let trunk_path = package_config .get("trunk-path") diff --git a/crates/shirabe/src/platform/hhvm_detector.rs b/crates/shirabe/src/platform/hhvm_detector.rs index 99da3b7..152e29a 100644 --- a/crates/shirabe/src/platform/hhvm_detector.rs +++ b/crates/shirabe/src/platform/hhvm_detector.rs @@ -69,7 +69,7 @@ impl HhvmDetector { ); let exit_code = executor .borrow_mut() - .execute(cmd, Some(&mut version_output), ()) + .execute(cmd, Some(&mut version_output), None) .unwrap_or(1); if exit_code == 0 { *cache = Some(version_output.as_string().map(|s| s.to_string())); diff --git a/crates/shirabe/src/repository/path_repository.rs b/crates/shirabe/src/repository/path_repository.rs index b8c106a..1a4cf6f 100644 --- a/crates/shirabe/src/repository/path_repository.rs +++ b/crates/shirabe/src/repository/path_repository.rs @@ -255,7 +255,7 @@ impl PathRepository { let code2 = self .process .borrow_mut() - .execute(cmd, Some(&mut ref2), ()) + .execute(cmd, Some(&mut ref2), None) .unwrap_or(1); if code1 == 0 && code2 == 0 && ref1.as_string() == ref2.as_string() { package.insert( diff --git a/crates/shirabe/src/repository/vcs/fossil_driver.rs b/crates/shirabe/src/repository/vcs/fossil_driver.rs index 1da7a2a..ebc0ac4 100644 --- a/crates/shirabe/src/repository/vcs/fossil_driver.rs +++ b/crates/shirabe/src/repository/vcs/fossil_driver.rs @@ -103,7 +103,7 @@ impl FossilDriver { if self.inner.process.borrow_mut().execute_args( ["fossil", "version"].map(|s| s.to_string()).as_ref(), &mut ignored_output, - (), + None, ) != 0 { return Err(RuntimeException { @@ -143,13 +143,13 @@ impl FossilDriver { && self.inner.process.borrow_mut().execute_args( ["fossil", "info"].map(|s| s.to_string()).as_ref(), &mut String::new(), - Some(self.checkout_dir.clone()), + Some(&self.checkout_dir), ) == 0 { if self.inner.process.borrow_mut().execute_args( ["fossil", "pull"].map(|s| s.to_string()).as_ref(), &mut String::new(), - Some(self.checkout_dir.clone()), + Some(&self.checkout_dir), ) != 0 { self.inner.io.write_error3(&format!( @@ -170,7 +170,7 @@ impl FossilDriver { .map(|s| s.to_string()) .as_ref(), &mut output, - (), + None, ) != 0 { let output = self.inner.process.borrow().get_error_output().to_string(); @@ -189,7 +189,7 @@ impl FossilDriver { .map(|s| s.to_string()) .as_ref(), &mut output, - Some(self.checkout_dir.clone()), + Some(&self.checkout_dir), ) != 0 { let output = self.inner.process.borrow().get_error_output().to_string(); @@ -248,7 +248,7 @@ impl FossilDriver { .map(|s| s.to_string()) .as_ref(), &mut content, - Some(self.checkout_dir.clone()), + Some(&self.checkout_dir), ); if content.trim().is_empty() { @@ -268,7 +268,7 @@ impl FossilDriver { .map(|s| s.to_string()) .as_ref(), &mut output, - Some(self.checkout_dir.clone()), + Some(&self.checkout_dir), ); let parts: Vec<&str> = output.trim().splitn(3, ' ').collect(); let date = parts.get(1).copied().unwrap_or(""); @@ -284,7 +284,7 @@ impl FossilDriver { self.inner.process.borrow_mut().execute_args( ["fossil", "tag", "list"].map(|s| s.to_string()).as_ref(), &mut output, - Some(self.checkout_dir.clone()), + Some(&self.checkout_dir), ); for tag in self.inner.process.borrow().split_lines(&output) { tags.insert(tag.clone(), tag); @@ -301,7 +301,7 @@ impl FossilDriver { self.inner.process.borrow_mut().execute_args( ["fossil", "branch", "list"].map(|s| s.to_string()).as_ref(), &mut output, - Some(self.checkout_dir.clone()), + Some(&self.checkout_dir), ); for branch in self.inner.process.borrow().split_lines(&output) { let branch = Preg::replace(r"/^\*/", "", branch.trim()); @@ -342,7 +342,7 @@ impl FossilDriver { if process.execute_args( ["fossil", "info"].map(|s| s.to_string()).as_ref(), &mut output, - Some(url), + Some(&url), ) == 0 { return Ok(true); diff --git a/crates/shirabe/src/repository/vcs/git_driver.rs b/crates/shirabe/src/repository/vcs/git_driver.rs index e639649..37f393c 100644 --- a/crates/shirabe/src/repository/vcs/git_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_driver.rs @@ -208,7 +208,7 @@ impl GitDriver { "--no-color".to_string(), ], &mut output, - Some(self.repo_dir.clone()), + Some(&self.repo_dir), ); let branches = self.inner.process.borrow().split_lines(&output); if !branches.contains(&"* master".to_string()) { @@ -269,7 +269,7 @@ impl GitDriver { format!("{}:{}", identifier, file), ], &mut content, - Some(self.repo_dir.clone()), + Some(&self.repo_dir), ); if content.trim().is_empty() { @@ -303,11 +303,10 @@ impl GitDriver { ], ); let mut output = String::new(); - self.inner.process.borrow_mut().execute_args( - &command, - &mut output, - Some(self.repo_dir.clone()), - ); + self.inner + .process + .borrow_mut() + .execute_args(&command, &mut output, Some(&self.repo_dir)); let timestamp_str = GitUtil::parse_rev_list_output(&output, &self.inner.process); let timestamp: i64 = timestamp_str.trim().parse().unwrap_or(0); @@ -329,7 +328,7 @@ impl GitDriver { "--dereference".to_string(), ], &mut output, - Some(self.repo_dir.clone()), + Some(&self.repo_dir), ); for tag in self.inner.process.borrow().split_lines(&output) { if !tag.is_empty() { @@ -368,7 +367,7 @@ impl GitDriver { "-v".to_string(), ], &mut output, - Some(self.repo_dir.clone()), + Some(&self.repo_dir), ); for branch in self.inner.process.borrow().split_lines(&output) { if !branch.is_empty() && !Preg::is_match(r"{^ *[^/]+/HEAD }", &branch) { @@ -419,7 +418,7 @@ impl GitDriver { if process.borrow_mut().execute_args( &["git".to_string(), "tag".to_string()], &mut output, - Some(url.clone()), + Some(&url), ) == 0 { return Ok(true); diff --git a/crates/shirabe/src/repository/vcs/hg_driver.rs b/crates/shirabe/src/repository/vcs/hg_driver.rs index 737443c..3ae87d1 100644 --- a/crates/shirabe/src/repository/vcs/hg_driver.rs +++ b/crates/shirabe/src/repository/vcs/hg_driver.rs @@ -93,13 +93,13 @@ impl HgDriver { && self.inner.process.borrow_mut().execute_args( ["hg", "summary"].map(|s| s.to_string()).as_ref(), &mut String::new(), - Some(self.repo_dir.clone()), + Some(&self.repo_dir), ) == 0 { if self.inner.process.borrow_mut().execute_args( ["hg", "pull"].map(|s| s.to_string()).as_ref(), &mut String::new(), - Some(self.repo_dir.clone()), + Some(&self.repo_dir), ) != 0 { self.inner.io.write_error3(&format!("<error>Failed to update {}, package information from this repository may be outdated ({})</error>", self.inner.url, self.inner.process.borrow().get_error_output()), true, crate::io::NORMAL); @@ -138,7 +138,7 @@ impl HgDriver { .map(|s| s.to_string()) .as_ref(), &mut output, - Some(self.repo_dir.clone()), + Some(&self.repo_dir), ); let lines = self.inner.process.borrow().split_lines(&output); self.root_identifier = lines.into_iter().next(); @@ -184,11 +184,10 @@ impl HgDriver { file.to_string(), ]; let mut content = String::new(); - self.inner.process.borrow_mut().execute_args( - &resource, - &mut content, - Some(self.repo_dir.clone()), - ); + self.inner + .process + .borrow_mut() + .execute_args(&resource, &mut content, Some(&self.repo_dir)); if content.trim().is_empty() { return Ok(None); @@ -225,7 +224,7 @@ impl HgDriver { .map(|s| s.to_string()) .as_ref(), &mut output, - Some(self.repo_dir.clone()), + Some(&self.repo_dir), ); let date: DateTime<Utc> = shirabe_php_shim::date_create(output.trim())?; @@ -239,7 +238,7 @@ impl HgDriver { self.inner.process.borrow_mut().execute_args( ["hg", "tags"].map(|s| s.to_string()).as_ref(), &mut output, - Some(self.repo_dir.clone()), + Some(&self.repo_dir), ); for tag in self.inner.process.borrow().split_lines(&output) { if !tag.is_empty() { @@ -269,7 +268,7 @@ impl HgDriver { self.inner.process.borrow_mut().execute_args( ["hg", "branches"].map(|s| s.to_string()).as_ref(), &mut output, - Some(self.repo_dir.clone()), + Some(&self.repo_dir), ); for branch in self.inner.process.borrow().split_lines(&output) { if !branch.is_empty() { @@ -290,7 +289,7 @@ impl HgDriver { self.inner.process.borrow_mut().execute_args( ["hg", "bookmarks"].map(|s| s.to_string()).as_ref(), &mut output, - Some(self.repo_dir.clone()), + Some(&self.repo_dir), ); for branch in self.inner.process.borrow().split_lines(&output) { if !branch.is_empty() { @@ -339,7 +338,7 @@ impl HgDriver { if process.execute_args( ["hg", "summary"].map(|s| s.to_string()).as_ref(), &mut output, - Some(url), + Some(&url), ) == 0 { return Ok(true); @@ -357,7 +356,7 @@ impl HgDriver { .map(|s| s.to_string()) .as_ref(), &mut ignored, - (), + None, ); Ok(exit == 0) diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs index e68beb6..19aec03 100644 --- a/crates/shirabe/src/repository/vcs/svn_driver.rs +++ b/crates/shirabe/src/repository/vcs/svn_driver.rs @@ -495,7 +495,7 @@ impl SvnDriver { url.clone(), ], &mut ignored_output, - (), + None, ); if exit == 0 { diff --git a/crates/shirabe/src/util/bitbucket.rs b/crates/shirabe/src/util/bitbucket.rs index 26a9e65..3fc698b 100644 --- a/crates/shirabe/src/util/bitbucket.rs +++ b/crates/shirabe/src/util/bitbucket.rs @@ -83,7 +83,7 @@ impl Bitbucket { .execute( PhpMixed::from(vec!["git", "config", "bitbucket.accesstoken"]), Some(&mut output), - (), + None, ) .unwrap_or(1) == 0 diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs index 90deba1..6510638 100644 --- a/crates/shirabe/src/util/filesystem.rs +++ b/crates/shirabe/src/util/filesystem.rs @@ -121,7 +121,7 @@ impl Filesystem { .execute( PhpMixed::List(cmd.iter().map(|s| PhpMixed::String(s.clone())).collect()), Some(&mut output), - (), + None, ) .map(|n| n == 0) .unwrap_or(false); @@ -161,7 +161,7 @@ impl Filesystem { .get_process() .execute_async( PhpMixed::List(cmd.iter().map(|s| PhpMixed::String(s.clone())).collect()), - (), + None, ) .await?; @@ -499,7 +499,7 @@ impl Filesystem { "/Y".to_string(), ], &mut output, - (), + None, ); // clear stat cache because external processes aren't tracked by the php stat cache @@ -517,7 +517,7 @@ impl Filesystem { let result = self.get_process().execute_args( &["mv".to_string(), source.to_string(), target.to_string()], &mut output, - (), + None, ); // clear stat cache because external processes aren't tracked by the php stat cache @@ -951,7 +951,7 @@ impl Filesystem { Platform::realpath(target), ]; let mut output = String::new(); - if self.get_process().execute_args(&cmd, &mut output, ()) != 0 { + if self.get_process().execute_args(&cmd, &mut output, None) != 0 { return Err(IOException::new( format!( "Failed to create junction to \"{}\" at \"{}\".", diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs index d66751c..f031157 100644 --- a/crates/shirabe/src/util/git.rs +++ b/crates/shirabe/src/util/git.rs @@ -184,7 +184,7 @@ impl Git { } else { cwd_string.clone() }; - status = this_process.execute_args(&cmd, &mut local_output, exec_cwd); + status = this_process.execute_args(&cmd, &mut local_output, exec_cwd.as_deref()); if collect_outputs { outputs.push(local_output); } @@ -217,7 +217,7 @@ impl Git { self.process.borrow_mut().execute_args( &["git".to_string(), "remote".to_string(), "-v".to_string()], &mut output, - cwd.map(|s| s.to_string()), + cwd, ); let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::is_match3( @@ -807,7 +807,7 @@ impl Git { "--git-dir".to_string(), ], &mut output, - Some(dir.to_string()), + Some(dir), ) == 0 && trim(&output, None) == "." { @@ -919,7 +919,7 @@ impl Git { if self.process.borrow_mut().execute_args( &["git".to_string(), "branch".to_string()], &mut output, - Some(dir.to_string()), + Some(dir), ) == 0 { branches = Some(output); @@ -928,7 +928,7 @@ impl Git { if self.process.borrow_mut().execute_args( &["git".to_string(), "tag".to_string()], &mut output, - Some(dir.to_string()), + Some(dir), ) == 0 { tags = Some(output); @@ -1048,7 +1048,7 @@ impl Git { "--git-dir".to_string(), ], &mut output, - Some(dir.to_string()), + Some(dir), ) == 0 && trim(&output, None) == "." { @@ -1062,7 +1062,7 @@ impl Git { format!("{}^{{commit}}", r#ref), ], &mut ignored_output, - Some(dir.to_string()), + Some(dir), ); if exit_code == 0 { return Ok(true); @@ -1123,7 +1123,7 @@ impl Git { "origin".to_string(), ], &mut output, - Some(dir.to_string()), + Some(dir), ); output_mixed = PhpMixed::String(output); } else { diff --git a/crates/shirabe/src/util/github.rs b/crates/shirabe/src/util/github.rs index 204d95e..ab5efea 100644 --- a/crates/shirabe/src/util/github.rs +++ b/crates/shirabe/src/util/github.rs @@ -71,7 +71,7 @@ impl GitHub { "github.accesstoken".to_string(), ], &mut output, - (), + None, ) == 0 { self.io.borrow_mut().set_authentication( @@ -106,7 +106,7 @@ impl GitHub { if self .process .borrow_mut() - .execute_args(&["hostname".to_string()], &mut output, ()) + .execute_args(&["hostname".to_string()], &mut output, None) == 0 { note += &format!(" on {}", output.trim()); diff --git a/crates/shirabe/src/util/gitlab.rs b/crates/shirabe/src/util/gitlab.rs index 71ff7e3..a71c231 100644 --- a/crates/shirabe/src/util/gitlab.rs +++ b/crates/shirabe/src/util/gitlab.rs @@ -75,7 +75,7 @@ impl GitLab { "gitlab.accesstoken".to_string(), ], &mut output, - (), + None, ) == 0 { self.io.borrow_mut().set_authentication( @@ -96,7 +96,7 @@ impl GitLab { "gitlab.deploytoken.user".to_string(), ], &mut token_user, - (), + None, ) == 0 && self.process.borrow_mut().execute_args( &[ @@ -105,7 +105,7 @@ impl GitLab { "gitlab.deploytoken.token".to_string(), ], &mut token_password, - (), + None, ) == 0 { self.io.borrow_mut().set_authentication( diff --git a/crates/shirabe/src/util/hg.rs b/crates/shirabe/src/util/hg.rs index 7fbf125..0caf3ab 100644 --- a/crates/shirabe/src/util/hg.rs +++ b/crates/shirabe/src/util/hg.rs @@ -50,7 +50,7 @@ impl Hg { if self .process .borrow_mut() - .execute_args(&command, &mut ignored_output, cwd.clone()) + .execute_args(&command, &mut ignored_output, cwd.as_deref()) == 0 { return Ok(()); @@ -109,7 +109,7 @@ impl Hg { if self .process .borrow_mut() - .execute_args(&command, &mut ignored_output, cwd) + .execute_args(&command, &mut ignored_output, cwd.as_deref()) == 0 { return Ok(()); @@ -150,7 +150,7 @@ impl Hg { if process.borrow_mut().execute_args( &["hg".to_string(), "--version".to_string()], &mut output, - (), + None, ) == 0 && let Some(matches) = Preg::is_match_with_indexed_captures( r"/^.+? (\d+(?:\.\d+)+)(?:\+.*?)?\)?\r?\n/", diff --git a/crates/shirabe/src/util/perforce.rs b/crates/shirabe/src/util/perforce.rs index 7ca3f26..11d8cc5 100644 --- a/crates/shirabe/src/util/perforce.rs +++ b/crates/shirabe/src/util/perforce.rs @@ -167,7 +167,7 @@ impl Perforce { }; self.process .borrow_mut() - .execute_args(&cmd_vec, &mut self.command_result, ()) + .execute_args(&cmd_vec, &mut self.command_result, None) } pub fn get_client(&mut self) -> String { diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs index 442b4d9..72fe5f9 100644 --- a/crates/shirabe/src/util/platform.rs +++ b/crates/shirabe/src/util/platform.rs @@ -381,7 +381,7 @@ impl Platform { let mut process = ProcessExecutor::new(None); let mut output = String::new(); let result: Result<()> = (|| { - if process.execute_args(&["lsmod".to_string()], &mut output, ()) == 0 + if process.execute_args(&["lsmod".to_string()], &mut output, None) == 0 && shirabe_php_shim::str_contains(&output, "vboxguest") { *cached = Some(true); diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs index 1f15795..842e934 100644 --- a/crates/shirabe/src/util/process_executor.rs +++ b/crates/shirabe/src/util/process_executor.rs @@ -110,31 +110,22 @@ impl ProcessExecutor { /// if a callable is passed it will be used as output handler /// @param null|string $cwd the working directory /// @return int statuscode - pub fn execute<'o, C, O, W>(&mut self, command: C, output: O, cwd: W) -> Result<i64> + pub fn execute<'o, C, O>(&mut self, command: C, output: O, cwd: Option<&str>) -> Result<i64> where C: IntoExecCommand, O: IntoExecOutput<'o>, - W: IntoExecCwd, { let command = command.into_exec_command(); let mut output = output.into_exec_output(); - let cwd_storage; - let cwd_ref: Option<&str> = match cwd.into_exec_cwd() { - Some(s) => { - cwd_storage = s; - Some(cwd_storage.as_str()) - } - None => None, - }; // PHP: func_num_args() > 1 let has_output_arg = output.has_output(); let rc = if has_output_arg { let mut buf = PhpMixed::Null; - let result = self.do_execute(command, cwd_ref, false, Some(&mut buf))?; + let result = self.do_execute(command, cwd, false, Some(&mut buf))?; output.write_back(buf); result } else { - self.do_execute(command, cwd_ref, false, None)? + self.do_execute(command, cwd, false, None)? }; Ok(rc) } @@ -142,10 +133,12 @@ impl ProcessExecutor { /// Convenience wrapper used by phase-A code that calls /// `process.execute(&[String], &mut String, Option<&str>) == 0`. /// Forwards to `execute`, returning the status code (0 on Err for compatibility). - pub fn execute_args<W>(&mut self, command: &[String], output: &mut String, cwd: W) -> i64 - where - W: IntoExecCwd, - { + pub fn execute_args( + &mut self, + command: &[String], + output: &mut String, + cwd: Option<&str>, + ) -> i64 { let cmd = PhpMixed::List( command .iter() @@ -153,39 +146,22 @@ impl ProcessExecutor { .collect(), ); let mut buf = PhpMixed::String(String::new()); - let cwd_storage; - let cwd_ref: Option<&str> = match cwd.into_exec_cwd() { - Some(s) => { - cwd_storage = s; - Some(cwd_storage.as_str()) - } - None => None, - }; - let rc = self.execute(cmd, Some(&mut buf), cwd_ref).unwrap_or(1); + let rc = self.execute(cmd, Some(&mut buf), cwd).unwrap_or(1); *output = buf.as_string().unwrap_or("").to_string(); rc } /// runs a process on the commandline in TTY mode - pub fn execute_tty<C, W>(&mut self, command: C, cwd: W) -> Result<i64> + pub fn execute_tty<C>(&mut self, command: C, cwd: Option<&str>) -> Result<i64> where C: IntoExecCommand, - W: IntoExecCwd, { let command = command.into_exec_command(); - let cwd_storage; - let cwd_ref: Option<&str> = match cwd.into_exec_cwd() { - Some(s) => { - cwd_storage = s; - Some(cwd_storage.as_str()) - } - None => None, - }; if Platform::is_tty(None) { - return self.do_execute(command, cwd_ref, true, None); + return self.do_execute(command, cwd, true, None); } - self.do_execute(command, cwd_ref, false, None) + self.do_execute(command, cwd, false, None) } /// @param string|non-empty-list<string> $command @@ -377,13 +353,11 @@ impl ProcessExecutor { } /// starts a process on the commandline in async mode - pub async fn execute_async<C, W>(&mut self, command: C, cwd: W) -> Result<Process> + pub async fn execute_async<C>(&mut self, command: C, cwd: Option<&str>) -> Result<Process> where C: IntoExecCommand, - W: IntoExecCwd, { let command = command.into_exec_command(); - let cwd_opt = cwd.into_exec_cwd(); if !self.allow_async { return Err(LogicException { message: "You must use the ProcessExecutor instance which is part of a Composer\\Loop instance to be able to run async processes".to_string(), @@ -398,7 +372,7 @@ impl ProcessExecutor { id, status: Self::STATUS_QUEUED, command, - cwd: cwd_opt, + cwd: cwd.map(ToOwned::to_owned), process: None, exception: None, }; @@ -987,53 +961,6 @@ impl<'a> IntoExecOutput<'a> for &'a mut String { } } -/// Phase B helper trait: convert various cwd argument forms into `Option<String>`. -pub trait IntoExecCwd { - fn into_exec_cwd(self) -> Option<String>; -} - -impl IntoExecCwd for () { - fn into_exec_cwd(self) -> Option<String> { - None - } -} - -impl IntoExecCwd for Option<&str> { - fn into_exec_cwd(self) -> Option<String> { - self.map(|s| s.to_string()) - } -} - -impl IntoExecCwd for Option<String> { - fn into_exec_cwd(self) -> Option<String> { - self - } -} - -impl IntoExecCwd for Option<&String> { - fn into_exec_cwd(self) -> Option<String> { - self.cloned() - } -} - -impl IntoExecCwd for &str { - fn into_exec_cwd(self) -> Option<String> { - Some(self.to_string()) - } -} - -impl IntoExecCwd for String { - fn into_exec_cwd(self) -> Option<String> { - Some(self) - } -} - -impl IntoExecCwd for &String { - fn into_exec_cwd(self) -> Option<String> { - Some(self.clone()) - } -} - /// Phase B helper: accept either `i64` or `PhpMixed` for `set_timeout`. pub trait ToTimeoutSeconds { fn to_timeout_seconds(self) -> i64; diff --git a/crates/shirabe/src/util/svn.rs b/crates/shirabe/src/util/svn.rs index 0a3daf3..84e5760 100644 --- a/crates/shirabe/src/util/svn.rs +++ b/crates/shirabe/src/util/svn.rs @@ -165,11 +165,10 @@ impl Svn { // TODO(phase-c): pass the filtering handler above to process.execute once the callback // model lands; for now a plain buffer is used and the output filtering is skipped. let mut handler_output = String::new(); - let status = self.process.borrow_mut().execute_args( - &command, - &mut handler_output, - cwd.map(String::from), - ); + let status = self + .process + .borrow_mut() + .execute_args(&command, &mut handler_output, cwd); if 0 == status { return Ok(output); } @@ -455,7 +454,7 @@ impl Svn { if 0 == self.process.borrow_mut().execute_args( &["svn".to_string(), "--version".to_string()], &mut output, - (), + None, ) { let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::is_match3(r"{(\d+(?:\.\d+)+)}", &output, Some(&mut matches)) { diff --git a/crates/shirabe/tests/platform/hhvm_detector_test.rs b/crates/shirabe/tests/platform/hhvm_detector_test.rs index 49804e3..72fd68d 100644 --- a/crates/shirabe/tests/platform/hhvm_detector_test.rs +++ b/crates/shirabe/tests/platform/hhvm_detector_test.rs @@ -58,7 +58,7 @@ fn test_hhvm_version_when_executing_in_php() { ProcessExecutor::escape(&hhvm) ); let exit_code = process - .execute(cmd.as_str(), Some(&mut version), ()) + .execute(cmd.as_str(), Some(&mut version), None) .unwrap(); assert_eq!(0, exit_code); diff --git a/crates/shirabe/tests/util/process_executor_test.rs b/crates/shirabe/tests/util/process_executor_test.rs index 0416a34..3ee4912 100644 --- a/crates/shirabe/tests/util/process_executor_test.rs +++ b/crates/shirabe/tests/util/process_executor_test.rs @@ -25,7 +25,7 @@ use shirabe_php_shim::{PHP_EOL, trim}; fn test_execute_captures_output() { let mut process = ProcessExecutor::new(None); let mut output = String::new(); - process.execute("echo foo", &mut output, ()).unwrap(); + process.execute("echo foo", &mut output, None).unwrap(); assert_eq!(format!("foo{}", PHP_EOL), output); } @@ -46,7 +46,7 @@ fn test_use_io_is_not_null_and_if_not_captured() { fn test_execute_captures_stderr() { let mut process = ProcessExecutor::new(None); let mut output = String::new(); - process.execute("cat foo", &mut output, ()).unwrap(); + process.execute("cat foo", &mut output, None).unwrap(); assert!( process .get_error_output() @@ -99,7 +99,7 @@ fn test_hide_passwords() { let mut process = ProcessExecutor::new(Some(buffer.clone() as Rc<RefCell<dyn IOInterface>>)); let mut output = String::new(); - process.execute(command, &mut output, ()).unwrap(); + process.execute(command, &mut output, None).unwrap(); assert_eq!( format!("Executing command (CWD): {}", expected_command_output), trim(&buffer.borrow().get_output(), None) @@ -116,7 +116,7 @@ fn test_doesnt_hide_ports() { let mut process = ProcessExecutor::new(Some(buffer.clone() as Rc<RefCell<dyn IOInterface>>)); let mut output = String::new(); process - .execute("echo https://localhost:1234/", &mut output, ()) + .execute("echo https://localhost:1234/", &mut output, None) .unwrap(); assert_eq!( "Executing command (CWD): echo https://localhost:1234/", @@ -153,7 +153,7 @@ fn test_console_io_does_not_format_symfony_console_style() { .execute( r#"php -ddisplay_errors=0 -derror_reporting=0 -r "echo '<error>foo</error>'.PHP_EOL;""#, (), - (), + None, ) .unwrap(); assert_eq!( |
