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 gitoxide-core/src (1 of 3 files). Show all

Unified · Split

gitoxide-core/src/pack/index.rs+8−6
@@ -67,8 +67,13 @@ pub fn stream_len(mut s: impl io::Seek) -> io::Result<u64> { · 66 unmodified lines
6767
6868 pub const PROGRESS_RANGE: std::ops::RangeInclusive<u8> = 2..=3;
6969
70+pub enum PathOrRead {
71+ Path(PathBuf),
72+ Read(Box<dyn std::io::Read + Send + 'static>),
73+}
74+
7075 pub fn from_pack(
71− pack: Option<PathBuf>,
76+ pack: PathOrRead,
7277 directory: Option<PathBuf>,
7378 progress: impl Progress,
7479 ctx: Context<impl io::Write>,
@@ -82,15 +87,12 @@ pub fn from_pack( · 7 unmodified lines
8287 let out = ctx.out;
8388 let format = ctx.format;
8489 let res = match pack {
85− Some(pack) => {
90+ PathOrRead::Path(pack) => {
8691 let pack_len = pack.metadata()?.len();
8792 let pack_file = fs::File::open(pack)?;
8893 pack::Bundle::write_to_directory_eagerly(pack_file, Some(pack_len), directory, progress, options)
8994 }
90− None => {
91− let stdin = io::stdin();
92− pack::Bundle::write_to_directory_eagerly(stdin, None, directory, progress, options)
93− }
95+ PathOrRead::Read(input) => pack::Bundle::write_to_directory_eagerly(input, None, directory, progress, options),
9496 }
9597 .with_context(|| "Failed to write pack and index")?;
9698 match format {