MCPcopy Create free account
hub / github.com/douglance/devsql / read_file_at_commit

Function read_file_at_commit

crates/devsql/src/tools/semantic_diff.rs:22–35  ·  view source on GitHub ↗

Read file content at a specific git commit.

(
    repo: &git2::Repository,
    oid: git2::Oid,
    path: &str,
)

Source from the content-addressed store, hash-verified

20
21/// Read file content at a specific git commit.
22pub 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.

Callers 1

runMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected