1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use super::Repository;
use crate::{Error, ErrorKind};
use std::path::Path;
#[cfg_attr(docsrs, doc(cfg(feature = "osv-export")))]
pub struct GitPath<'a> {
repo: &'a Repository,
path: &'a Path,
}
impl<'a> GitPath<'a> {
pub fn new(repo: &'a Repository, path: &'a Path) -> Result<Self, Error> {
if path.has_root() {
fail!(
ErrorKind::BadParam,
"{} is not a relative path",
path.display()
);
}
let commit_id = repo.repo.refname_to_id("HEAD")?;
let commit = repo.repo.find_commit(commit_id)?;
commit.tree()?.get_path(path)?;
Ok(GitPath { repo, path })
}
pub fn path(&self) -> &'a Path {
self.path
}
pub fn repository(&self) -> &'a Repository {
self.repo
}
}