Skip to content

Commit 1c22d76

Browse files
committed
feat: Repsitory::load_index() (#293)
This method makes the index of the default workspace available.
1 parent 421d1ba commit 1c22d76

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

git-repository/src/repository.rs

+18
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@ mod access {
1414
pub fn to_easy(&self) -> easy::Handle {
1515
self.into()
1616
}
17+
18+
// TODO: tests
19+
/// Load the index file of this repository's workspace, if present.
20+
///
21+
/// Note that it is loaded into memory each time this method is called, but also is independent of the workspace.
22+
pub fn load_index(&self) -> Option<Result<git_index::File, git_index::file::init::Error>> {
23+
// TODO: choose better/correct options
24+
let opts = git_index::decode::Options {
25+
object_hash: self.object_hash,
26+
thread_limit: None,
27+
min_extension_block_in_bytes_for_threading: 1024 * 256,
28+
};
29+
match git_index::File::at(self.git_dir().join("index"), opts) {
30+
Ok(index) => Some(Ok(index)),
31+
Err(git_index::file::init::Error::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => None,
32+
Err(err) => Some(Err(err)),
33+
}
34+
}
1735
}
1836
}
1937

0 commit comments

Comments
 (0)