Skip to main content

clgit/
cat_file_reader.rs

1use std::io::{self, Read};
2use std::process::{Child, ChildStdout};
3
4
5
6pub(crate) struct CatFileReader {
7    pub(crate) child:  Child,
8    pub(crate) stdout: ChildStdout,
9}
10
11impl Read for CatFileReader {
12    fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
13        let read = self.stdout.read(buf)?;
14        if read != 0 { return Ok(read); }
15
16        let exit = self.child.wait()?;
17        match exit.code() {
18            Some(0) => Ok(0),
19            Some(_) => Err(io::Error::new(io::ErrorKind::Other, "git cat-file exited non-zero")),
20            None    => Err(io::Error::new(io::ErrorKind::Other, "git cat-file died by signal")),
21        }
22    }
23}