Skip to content

Commit 30de988

Browse files
committed
prepare decode options for better control of threads (#293)
1 parent 99d7224 commit 30de988

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

git-index/src/decode/mod.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,28 @@ mod error {
2929
}
3030
pub use error::Error;
3131

32+
#[derive(Default)]
33+
pub struct Options {
34+
pub object_hash: git_hash::Kind,
35+
/// If Some(_), we are allowed to use more than one thread. If Some(N), use no more than N threads. If Some(0)|None, use as many threads
36+
/// as there are physical cores.
37+
///
38+
/// This applies to loading extensions in parallel to entries if the common EOIE extension is available.
39+
/// It also allows to use multiple threads for loading entries if the IEOT extension is present.
40+
pub num_threads: Option<usize>,
41+
/// The minimum size in bytes to load extensions in their own thread, assuming there is enough `num_threads` available.
42+
pub min_extension_block_in_bytes_for_threading: usize,
43+
}
44+
3245
impl State {
3346
pub fn from_bytes(
3447
data: &[u8],
3548
timestamp: FileTime,
36-
object_hash: git_hash::Kind,
49+
Options {
50+
object_hash,
51+
num_threads: _,
52+
min_extension_block_in_bytes_for_threading: _,
53+
}: Options,
3754
) -> Result<(Self, git_hash::ObjectId), Error> {
3855
let (version, num_entries, post_header_data) = header::decode(data, object_hash)?;
3956
let start_of_extensions = extension::end_of_index_entry::decode(data, object_hash);

git-index/src/file.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub mod init {
2525

2626
use memmap2::Mmap;
2727

28-
use crate::{extension, File, State};
28+
use crate::{decode, extension, File, State};
2929

3030
mod error {
3131
use quick_error::quick_error;
@@ -49,7 +49,7 @@ pub mod init {
4949
pub use error::Error;
5050

5151
impl File {
52-
pub fn at(path: impl Into<PathBuf>, object_hash: git_hash::Kind) -> Result<Self, Error> {
52+
pub fn at(path: impl Into<PathBuf>, options: decode::Options) -> Result<Self, Error> {
5353
let path = path.into();
5454
let (data, mtime) = {
5555
// SAFETY: we have to take the risk of somebody changing the file underneath. Git never writes into the same file.
@@ -59,7 +59,7 @@ pub mod init {
5959
(data, filetime::FileTime::from_last_modification_time(&file.metadata()?))
6060
};
6161

62-
let (state, checksum) = State::from_bytes(&data, mtime, object_hash)?;
62+
let (state, checksum) = State::from_bytes(&data, mtime, options)?;
6363
Ok(File { state, path, checksum })
6464
}
6565
}

git-index/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ pub mod decode;
3030
/// All known versions of a git index file.
3131
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
3232
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
33-
#[allow(missing_docs)]
3433
pub enum Version {
34+
/// Supports entries and various extensions.
3535
V2 = 2,
36+
/// Adds support for additional flags for each entry.
3637
V3 = 3,
38+
/// Supports deltified entry paths.
3739
V4 = 4,
3840
}
3941

git-index/tests/file/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod init {
33
use git_testtools::hex_to_id;
44

55
fn file(name: &str) -> git_index::File {
6-
git_index::File::at(crate::index_fixture_path(name), git_hash::Kind::Sha1).unwrap()
6+
git_index::File::at(crate::index_fixture_path(name), git_index::decode::Options::default()).unwrap()
77
}
88

99
#[test]

0 commit comments

Comments
 (0)