Skip to content

Commit 4dec3ea

Browse files
committed
git-ref uses memmap2 (#293)
1 parent b481f13 commit 4dec3ea

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

Cargo.lock

+10-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-ref/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ serde = { version = "1.0.114", optional = true, default-features = false, featur
3838
os_str_bytes = "6.0.0"
3939

4040
# packed refs
41-
filebuffer = "0.4.0"
41+
memmap2 = "0.5.0"
4242

4343
[dev-dependencies]
4444
git-testtools = { path = "../tests/tools" }

git-ref/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
//! * references are stored in a single human-readable file, along with their targets if they are symbolic.
1717
//! * **ref-table**
1818
//! * supersedes all of the above to allow handling hundreds of thousands of references.
19-
#![forbid(unsafe_code)]
20-
#![deny(missing_docs, rust_2018_idioms)]
19+
#![deny(unsafe_code, missing_docs, rust_2018_idioms)]
2120

2221
use std::borrow::Cow;
2322

git-ref/src/store/packed/buffer.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl AsRef<[u8]> for packed::Backing {
1919
pub mod open {
2020
use std::path::PathBuf;
2121

22-
use filebuffer::FileBuffer;
22+
use memmap2::Mmap;
2323

2424
use crate::store_impl::packed;
2525

@@ -35,7 +35,13 @@ pub mod open {
3535
let backing = if std::fs::metadata(&path)?.len() <= use_memory_map_if_larger_than_bytes {
3636
packed::Backing::InMemory(std::fs::read(&path)?)
3737
} else {
38-
packed::Backing::Mapped(FileBuffer::open(&path)?)
38+
packed::Backing::Mapped(
39+
// SAFETY: we have to take the risk of somebody changing the file underneath. Git never writes into the same file.
40+
#[allow(unsafe_code)]
41+
unsafe {
42+
Mmap::map(&std::fs::File::open(&path)?)?
43+
},
44+
)
3945
};
4046

4147
let (offset, sorted) = {

git-ref/src/store/packed/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::path::PathBuf;
22

3-
use filebuffer::FileBuffer;
43
use git_features::threading::OwnShared;
54
use git_hash::ObjectId;
65
use git_object::bstr::{BStr, BString};
6+
use memmap2::Mmap;
77

88
use crate::{transaction::RefEdit, FullNameRef};
99

@@ -12,7 +12,7 @@ enum Backing {
1212
/// The buffer is loaded entirely in memory, along with the `offset` to the first record past the header.
1313
InMemory(Vec<u8>),
1414
/// The buffer is mapping the file on disk, along with the offset to the first record past the header
15-
Mapped(FileBuffer),
15+
Mapped(Mmap),
1616
}
1717

1818
/// A buffer containing a packed-ref file that is either memory mapped or fully in-memory depending on a cutoff.

0 commit comments

Comments
 (0)