History

Prevent pack-index-from-data to block if stdin is a terminal

Sebastian Thiel committed 5 years ago

Commit 39dec0e1 parent 4c36f923 files · +29 −9Browse files

Showing the changes to src (2 of 3 files). Show all

Unified · Split

2 files
  1. src/plumbing/lean/main.rs +11 −1
  2. src/plumbing/pretty/main.rs +10 −2
src/plumbing/lean/main.rs+11−1
@@ -90,9 +90,19 @@ pub fn main() -> Result<()> { · 89 unmodified lines
9090 pack_path,
9191 directory,
9292 }) => {
93+ use gitoxide_core::pack::index::PathOrRead;
9394 let (_handle, progress) = prepare(verbose, "pack-explode", core::pack::index::PROGRESS_RANGE);
95+ let input = if let Some(path) = pack_path {
96+ PathOrRead::Path(path)
97+ } else {
98+ #[cfg(feature = "atty")]
99+ if atty::is(atty::Stream::Stdin) {
100+ anyhow::bail!("Refusing to read from standard input as no path is given, but it's a terminal.")
101+ }
102+ PathOrRead::Read(Box::new(std::io::stdin()))
103+ };
94104 core::pack::index::from_pack(
95− pack_path,
105+ input,
96106 directory,
97107 DoOrDiscard::from(progress),
98108 core::pack::index::Context {
src/plumbing/pretty/main.rs+10−2
@@ -31,7 +31,6 @@ pub fn main() -> Result<()> { · 30 unmodified lines
3131 } => {
3232 let has_tips = !tips.is_empty();
3333 let has_tui = progress;
34− #[cfg(feature = "atty")]
3534 if atty::is(if has_tui {
3635 atty::Stream::Stderr
3736 } else {
@@ -123,8 +122,17 @@ pub fn main() -> Result<()> { · 85 unmodified lines
123122 progress_keep_open,
124123 core::pack::index::PROGRESS_RANGE,
125124 move |progress, out, _err| {
125+ use gitoxide_core::pack::index::PathOrRead;
126+ let input = if let Some(path) = pack_path {
127+ PathOrRead::Path(path)
128+ } else {
129+ if atty::is(atty::Stream::Stdin) {
130+ anyhow::bail!("Refusing to read from standard input as no path is given, but it's a terminal.")
131+ }
132+ PathOrRead::Read(Box::new(std::io::stdin()))
133+ };
126134 core::pack::index::from_pack(
127− pack_path,
135+ input,
128136 directory,
129137 git_features::progress::DoOrDiscard::from(progress),
130138 core::pack::index::Context {