Skip to content

Commit 55382c0

Browse files
committed
feat!: make xz2 optional to write uncompressed tar files by default.
Previously, compression was beneficial due to storage in `git-lfs`. Now, storing (mostly) non-binary files is actually better moving forward.
1 parent f6eaba3 commit 55382c0

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/tools/Cargo.toml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ path = "src/main.rs"
1414
[lib]
1515
doctest = false
1616

17+
[features]
18+
default = []
19+
## Use instead of plain `tar` files, compress these to produce `tar.xz` files instead.
20+
## This is useful if archives are uploaded into `git-lfs`, which doesn't have built-in compression
21+
## and metering counts towards uncompressed bytes transferred.
22+
xz = ["dep:xz2"]
23+
1724
[dependencies]
1825
gix-lock = "14.0.0"
1926
gix-discover = "0.32.0"
@@ -35,4 +42,10 @@ parking_lot = { version = "0.12.0" }
3542
is_ci = "1.1.1"
3643
io-close = "0.3.7"
3744
tar = { version = "0.4.38", default-features = false }
38-
xz2 = "0.1.6"
45+
xz2 = { version = "0.1.6", optional = true }
46+
47+
document-features = { version = "0.2.1", optional = true }
48+
49+
[package.metadata.docs.rs]
50+
all-features = true
51+
features = ["document-features"]

tests/tools/src/lib.rs

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
//! Utilities for testing `gitoxide` crates, many of which might be useful for testing programs that use `git` in general.
2+
//!
3+
//! ## Feature Flags
4+
#![cfg_attr(
5+
all(doc, feature = "document-features"),
6+
doc = ::document_features::document_features!()
7+
)]
8+
#![cfg_attr(all(doc, feature = "document-features"), feature(doc_cfg, doc_auto_cfg))]
29
#![deny(missing_docs)]
310

411
use std::{
@@ -269,7 +276,7 @@ fn fixture_bytes_inner(path: impl AsRef<Path>, root: DirectoryRoot) -> Vec<u8> {
269276
/// #### Disable Archive Creation
270277
///
271278
/// If archives aren't useful, they can be disabled by using `.gitignore` specifications.
272-
/// That way it's trivial to prevent creation of all archives with `generated-archives/*.tar.xz` in the root
279+
/// That way it's trivial to prevent creation of all archives with `generated-archives/*.tar{.xz}` in the root
273280
/// or more specific `.gitignore` configurations in lower levels of the work tree.
274281
///
275282
/// The latter is useful if the script's output is platform specific.
@@ -407,7 +414,11 @@ fn scripted_fixture_read_only_with_args_inner(
407414

408415
let script_basename = script_location.file_stem().unwrap_or(script_location.as_os_str());
409416
let archive_file_path = fixture_path_inner(
410-
Path::new("generated-archives").join(format!("{}.tar.xz", script_basename.to_str().expect("valid UTF-8"))),
417+
Path::new("generated-archives").join(format!(
418+
"{}.tar{}",
419+
script_basename.to_str().expect("valid UTF-8"),
420+
if cfg!(feature = "xz") { ".xz" } else { "" }
421+
)),
411422
root,
412423
);
413424
let (force_run, script_result_directory) = destination_dir.map_or_else(
@@ -566,14 +577,24 @@ fn create_archive_if_not_on_ci(source_dir: &Path, archive: &Path, script_identit
566577
ar.append_dir_all(".", source_dir)?;
567578
ar.finish()?;
568579
}
569-
let archive = std::fs::OpenOptions::new()
580+
#[cfg_attr(feature = "xz", allow(unused_mut))]
581+
let mut archive = std::fs::OpenOptions::new()
570582
.write(true)
571583
.create(true)
572584
.truncate(true)
573585
.open(archive)?;
574-
let mut xz_write = xz2::write::XzEncoder::new(archive, 3);
575-
std::io::copy(&mut &*buf, &mut xz_write)?;
576-
xz_write.finish()?.close()
586+
#[cfg(feature = "xz")]
587+
{
588+
let mut xz_write = xz2::write::XzEncoder::new(archive, 3);
589+
std::io::copy(&mut &*buf, &mut xz_write)?;
590+
xz_write.finish()?.close()
591+
}
592+
#[cfg(not(feature = "xz"))]
593+
{
594+
use std::io::Write;
595+
archive.write_all(&buf)?;
596+
archive.close()
597+
}
577598
})();
578599
#[cfg(not(windows))]
579600
std::fs::remove_dir_all(meta_dir)?;
@@ -629,7 +650,8 @@ fn extract_archive(
629650
) -> std::io::Result<(u32, Option<String>)> {
630651
let archive_buf: Vec<u8> = {
631652
let mut buf = Vec::new();
632-
let input_archive = std::fs::File::open(archive)?;
653+
#[cfg_attr(feature = "xz", allow(unused_mut))]
654+
let mut input_archive = std::fs::File::open(archive)?;
633655
if std::env::var_os("GIX_TEST_IGNORE_ARCHIVES").is_some() {
634656
return Err(std::io::Error::new(
635657
std::io::ErrorKind::Other,
@@ -639,8 +661,16 @@ fn extract_archive(
639661
),
640662
));
641663
}
642-
let mut decoder = xz2::bufread::XzDecoder::new(std::io::BufReader::new(input_archive));
643-
std::io::copy(&mut decoder, &mut buf)?;
664+
#[cfg(feature = "xz")]
665+
{
666+
let mut decoder = xz2::bufread::XzDecoder::new(std::io::BufReader::new(input_archive));
667+
std::io::copy(&mut decoder, &mut buf)?;
668+
}
669+
#[cfg(not(feature = "xz"))]
670+
{
671+
use std::io::Read;
672+
input_archive.read_to_end(&mut buf)?;
673+
}
644674
buf
645675
};
646676

0 commit comments

Comments
 (0)