1use std::path::Path;
2
3use ropey::Rope;
4
5use crate::{Repository, Result};
6
7pub struct GitBlob;
9
10impl GitBlob {
11 pub fn read(repo: &Repository, oid: &gix::ObjectId) -> Result<Rope> {
14 let oid_str = oid.to_string();
15 let text = repo.run_git_str(["cat-file", "-p", &oid_str])?;
16 Ok(Rope::from(text))
17 }
18
19 pub fn read_path(repo: &Repository, rev: &str, path: impl AsRef<Path>) -> Result<Rope> {
22 let spec = format!("{}:{}", rev, path.as_ref().display());
23 let text = repo.run_git_str(["show", &spec])?;
24 Ok(Rope::from(text))
25 }
26}