Skip to content

Commit

Permalink
allow writing empty files during checkout but also query the odb (#301)
Browse files Browse the repository at this point in the history
This should tell us how much time it really takes to do the ODB part,
and see how much we could save by optimizing disk access, for instance
by using an lstat cache.
  • Loading branch information
Byron committed Mar 4, 2022
1 parent 5494fb3 commit 5388d80
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
2 changes: 1 addition & 1 deletion etc/check-package-size.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ echo "in root: gitoxide CLI"
(enter git-packetline && indent cargo diet -n --package-size-limit 35KB)
(enter git-repository && indent cargo diet -n --package-size-limit 80KB)
(enter git-transport && indent cargo diet -n --package-size-limit 50KB)
(enter gitoxide-core && indent cargo diet -n --package-size-limit 50KB)
(enter gitoxide-core && indent cargo diet -n --package-size-limit 60KB)
9 changes: 8 additions & 1 deletion git-worktree/tests/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,14 @@ mod checkout {
let odb = git_odb::at(git_dir.join("objects"))?;
let destination = tempfile::tempdir()?;

let outcome = index::checkout(&mut index)?;
let outcome = index::checkout(
&mut index,
&destination,
move |oid, buf| odb.find_blob(oid, buf).ok(),
&mut progress::Discard,
&mut progress::Discard,
opts,
)?;
Ok((source_tree, destination, index, outcome))
}

Expand Down
28 changes: 25 additions & 3 deletions gitoxide-core/src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,23 @@ fn parse_file(index_path: impl AsRef<Path>, object_hash: git::hash::Kind) -> any
.map_err(Into::into)
}

pub mod checkout_exclusive {
pub struct Options {
pub index: super::Options,
/// If true, all files will be written with zero bytes despite having made an ODB lookup.
pub empty_files: bool,
}
}

pub fn checkout_exclusive(
index_path: impl AsRef<Path>,
dest_directory: impl AsRef<Path>,
repo: Option<PathBuf>,
mut progress: impl Progress,
Options { object_hash, .. }: Options,
checkout_exclusive::Options {
index: Options { object_hash, .. },
empty_files,
}: checkout_exclusive::Options,
) -> anyhow::Result<()> {
let repo = repo
.map(|dir| git_repository::discover(dir).map(|r| r.apply_environment()))
Expand All @@ -124,7 +135,7 @@ pub fn checkout_exclusive(
let mut index = parse_file(index_path, object_hash)?;

let mut num_skipped = 0;
let maybe_symlink_mode = if repo.is_some() {
let maybe_symlink_mode = if !empty_files && repo.is_some() {
git::index::entry::Mode::DIR
} else {
git::index::entry::Mode::SYMLINK
Expand Down Expand Up @@ -161,7 +172,18 @@ pub fn checkout_exclusive(
Some(repo) => git::worktree::index::checkout(
&mut index,
dest_directory,
|oid, buf| repo.objects.find_blob(oid, buf).ok(),
|oid, buf| {
repo.objects.find_blob(oid, buf).ok();
if empty_files {
// We always want to query the ODB here…
repo.objects.find_blob(oid, buf).ok();
buf.clear();
// …but write nothing
Some(git::objs::BlobRef { data: buf })
} else {
repo.objects.find_blob(oid, buf).ok()
}
},
&mut files,
&mut bytes,
opts,
Expand Down
11 changes: 9 additions & 2 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ pub fn main() -> Result<()> {
index_path,
cmd,
}) => match cmd {
index::Subcommands::CheckoutExclusive { directory, repository } => prepare_and_run(
index::Subcommands::CheckoutExclusive {
directory,
empty_files,
repository,
} => prepare_and_run(
"index-checkout",
verbose,
progress,
Expand All @@ -90,7 +94,10 @@ pub fn main() -> Result<()> {
directory,
repository,
progress,
core::index::Options { object_hash, format },
core::index::checkout_exclusive::Options {
index: core::index::Options { object_hash, format },
empty_files,
},
)
},
),
Expand Down
4 changes: 4 additions & 0 deletions src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ pub mod index {
/// in the index. Use this measure the impact on extracting objects on overall performance.
#[clap(long, short = 'r')]
repository: Option<PathBuf>,
/// Enable to query the object database yet write only empty files. This is useful to measure the overhead of ODB query
/// compared to writing the bytes to disk.
#[clap(long, short = 'e', requires = "repository")]
empty_files: bool,
/// The directory into which to write all index entries.
directory: PathBuf,
},
Expand Down

0 comments on commit 5388d80

Please sign in to comment.