Read file content at a specific git commit.
(
repo: &git2::Repository,
oid: git2::Oid,
path: &str,
)
| 20 | |
| 21 | /// Read file content at a specific git commit. |
| 22 | pub fn read_file_at_commit( |
| 23 | repo: &git2::Repository, |
| 24 | oid: git2::Oid, |
| 25 | path: &str, |
| 26 | ) -> Option<String> { |
| 27 | let commit = repo.find_commit(oid).ok()?; |
| 28 | let tree = commit.tree().ok()?; |
| 29 | let entry = tree.get_path(std::path::Path::new(path)).ok()?; |
| 30 | let blob = repo.find_blob(entry.id()).ok()?; |
| 31 | if blob.is_binary() { |
| 32 | return None; |
| 33 | } |
| 34 | String::from_utf8(blob.content().to_vec()).ok() |
| 35 | } |
| 36 | |
| 37 | /// Compute semantic diff for a single file by comparing symbols between two |
| 38 | /// versions and checking which symbols overlap with changed hunks. |