Skip to content

Commit 3ff5ac0

Browse files
committed
feat: gix free index from-list and gix index from-tree gain --skip-hash.
This flag can be derived from options, but thus far we have no higher-level writing of the index so this has to do to see the difference in performance.
1 parent 2f42132 commit 3ff5ac0

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

Diff for: gitoxide-core/src/repository/index/mod.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
use std::{ffi::OsString, path::PathBuf};
22

33
use anyhow::bail;
4-
use gix::prelude::FindExt;
54

65
pub fn from_tree(
6+
repo: gix::Repository,
77
mut spec: OsString,
88
index_path: Option<PathBuf>,
99
force: bool,
10-
repo: gix::Repository,
10+
skip_hash: bool,
1111
) -> anyhow::Result<()> {
1212
spec.push("^{tree}");
1313
let spec = gix::path::os_str_into_bstr(&spec)?;
1414
let tree = repo.rev_parse_single(spec)?;
15-
let index = gix::index::State::from_tree(&tree, |oid, buf| repo.objects.find_tree_iter(oid, buf).ok())?;
16-
let options = gix::index::write::Options::default();
15+
16+
let mut index = repo.index_from_tree(&tree)?;
17+
let options = gix::index::write::Options {
18+
skip_hash,
19+
..Default::default()
20+
};
1721

1822
match index_path {
1923
Some(index_path) => {
@@ -23,11 +27,10 @@ pub fn from_tree(
2327
index_path.display()
2428
);
2529
}
26-
let mut index = gix::index::File::from_state(index, index_path);
30+
index.set_path(index_path);
2731
index.write(options)?;
2832
}
2933
None => {
30-
let index = gix::index::File::from_state(index, std::path::PathBuf::new());
3134
let mut out = Vec::with_capacity(512 * 1024);
3235
index.write_to(&mut out, options)?;
3336
}
@@ -36,7 +39,12 @@ pub fn from_tree(
3639
Ok(())
3740
}
3841

39-
pub fn from_list(entries_file: PathBuf, index_path: Option<PathBuf>, force: bool) -> anyhow::Result<()> {
42+
pub fn from_list(
43+
entries_file: PathBuf,
44+
index_path: Option<PathBuf>,
45+
force: bool,
46+
skip_hash: bool,
47+
) -> anyhow::Result<()> {
4048
use std::io::BufRead;
4149
let object_hash = gix::hash::Kind::Sha1;
4250

@@ -57,7 +65,10 @@ pub fn from_list(entries_file: PathBuf, index_path: Option<PathBuf>, force: bool
5765
}
5866
index.sort_entries();
5967

60-
let options = gix::index::write::Options::default();
68+
let options = gix::index::write::Options {
69+
skip_hash,
70+
..Default::default()
71+
};
6172
match index_path {
6273
Some(index_path) => {
6374
if index_path.is_file() && !force {

Diff for: src/plumbing/main.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ pub fn main() -> Result<()> {
447447
free::index::Subcommands::FromList {
448448
force,
449449
index_output_path,
450+
skip_hash,
450451
file,
451452
} => prepare_and_run(
452453
"index-from-list",
@@ -455,7 +456,9 @@ pub fn main() -> Result<()> {
455456
progress,
456457
progress_keep_open,
457458
None,
458-
move |_progress, _out, _err| core::repository::index::from_list(file, index_output_path, force),
459+
move |_progress, _out, _err| {
460+
core::repository::index::from_list(file, index_output_path, force, skip_hash)
461+
},
459462
),
460463
free::index::Subcommands::CheckoutExclusive {
461464
directory,
@@ -1164,6 +1167,7 @@ pub fn main() -> Result<()> {
11641167
index::Subcommands::FromTree {
11651168
force,
11661169
index_output_path,
1170+
skip_hash,
11671171
spec,
11681172
} => prepare_and_run(
11691173
"index-from-tree",
@@ -1173,7 +1177,13 @@ pub fn main() -> Result<()> {
11731177
progress_keep_open,
11741178
None,
11751179
move |_progress, _out, _err| {
1176-
core::repository::index::from_tree(spec, index_output_path, force, repository(Mode::Strict)?)
1180+
core::repository::index::from_tree(
1181+
repository(Mode::Strict)?,
1182+
spec,
1183+
index_output_path,
1184+
force,
1185+
skip_hash,
1186+
)
11771187
},
11781188
),
11791189
},

Diff for: src/plumbing/options/free.rs

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ pub mod index {
6363
/// back by default, but that requires us to write more of the index to work.
6464
#[clap(long, short = 'i')]
6565
index_output_path: Option<PathBuf>,
66+
/// Don't write the trailing hash for a performance gain.
67+
#[clap(long, short = 's')]
68+
skip_hash: bool,
6669
/// The file to read the index entries from, one path per line.
6770
file: PathBuf,
6871
},

Diff for: src/plumbing/options/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,9 @@ pub mod index {
705705
/// back by default, but that requires us to write more of the index to work.
706706
#[clap(long, short = 'i')]
707707
index_output_path: Option<PathBuf>,
708+
/// Don't write the trailing hash for a performance gain.
709+
#[clap(long, short = 's')]
710+
skip_hash: bool,
708711
/// A revspec that points to the to generate the index from.
709712
spec: std::ffi::OsString,
710713
},

0 commit comments

Comments
 (0)