| 205 | } |
| 206 | |
| 207 | fn file_content_at_commit(repo: &Repository, commit_id: &str, file_path: &Path) -> Result<Vec<u8>, Error> { |
| 208 | let obj = repo.revparse_single(commit_id).map_err(|err| { |
| 209 | let repo_url = repo |
| 210 | .find_remote("origin") |
| 211 | .map(|remote| remote.url().unwrap_or_default().to_string()) |
| 212 | .unwrap_or_default(); |
| 213 | let msg = format!( |
| 214 | "Unable to use git object commit ID {} on repository {}: {}", |
| 215 | commit_id, repo_url, err |
| 216 | ); |
| 217 | Error::from_str(&msg) |
| 218 | })?; |
| 219 | let commit = obj.peel_to_commit()?; |
| 220 | let tree = commit.tree()?; |
| 221 | let entry = tree.get_path(file_path).map_err(|err| { |
| 222 | Error::from_str(&format!( |
| 223 | "Unable to find file {} in commit {}: {}", |
| 224 | file_path.display(), |
| 225 | commit_id, |
| 226 | err |
| 227 | )) |
| 228 | })?; |
| 229 | let blob = repo.find_blob(entry.id()).map_err(|err| { |
| 230 | Error::from_str(&format!( |
| 231 | "Unable to read blob for file {} in commit {}: {}", |
| 232 | file_path.display(), |
| 233 | commit_id, |
| 234 | err |
| 235 | )) |
| 236 | })?; |
| 237 | |
| 238 | Ok(blob.content().to_vec()) |
| 239 | } |
| 240 | |
| 241 | fn fetch<P>( |
| 242 | repository_url: &Url, |