Skip to content

Commit

Permalink
Upgrade Rust to 1.84 and upgrade dependencies (#161)
Browse files Browse the repository at this point in the history
* Cargo update

* Upgrade rust to 1.84 and upgrade dependencies

* Fix snapshot

* Sort filenames in test

* fmt

* Debug

* Use ordered buffer concurrent

* Rollback debug
  • Loading branch information
j178 authored Feb 6, 2025
1 parent 7f883a9 commit 586186b
Show file tree
Hide file tree
Showing 14 changed files with 407 additions and 194 deletions.
517 changes: 358 additions & 159 deletions Cargo.lock

Large diffs are not rendered by default.

21 changes: 9 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,34 @@ ctrlc = "3.4.5"
dunce = "1.0.5"
etcetera = "0.8.0"
fancy-regex = "0.14.0"
fs-err = "2.11.0"
fs-err = "3.1.0"
fs2 = "0.4.3"
futures = "0.3.31"
http = "1.1.0"
indicatif = "0.17.8"
indoc = "2.0.5"
itertools = "0.13.0"
md5 = "0.7.0"
miette = { version = "7.2.0", features = ["owo-colors", "textwrap"] }
itertools = "0.14.0"
md-5 = "0.10.6"
miette = { version = "7.5.0", features = ["fancy-no-backtrace"] }
owo-colors = "4.1.0"
rand = "0.8.5"
rand = "0.9.0"
rayon = "1.10.0"
reqwest = { version = "0.12.9", default-features = false }
rusqlite = { version = "0.32.1", features = ["bundled"] }
rusqlite = { version = "0.33.0", features = ["bundled"] }
same-file = "1.0.6"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.132"
serde_yaml = "0.9.34"
shlex = "1.3.0"
tempfile = "3.13.0"
textwrap = "0.16.1"
thiserror = "1.0.64"
thiserror = "2.0.11"
tokio = { version = "1.40.0", features = ["fs", "process", "rt", "sync", "macros"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
unicode-width = "0.2.0"
url = { version = "2.5.2", features = ["serde"] }
which = "6.0.3"
which = "7.0.1"

[target.'cfg(unix)'.dependencies]
libc = "0.2.164"
Expand All @@ -70,7 +70,7 @@ predicates = "3.1.2"
regex = "1.11.0"

[build-dependencies]
fs-err = "2.11.0"
fs-err = "3.1.0"

[lints.rust]
dead_code = "allow"
Expand Down Expand Up @@ -113,6 +113,3 @@ strip = false # keep symbols for the profiler
[profile.dist]
inherits = "release"
lto = "thin"

[package.metadata.dist]
dist = true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ cargo binstall prefligit

## Usage

This tool is designed to be a drop-in replacement for the original pre-commit tool, so you can use it with your existing configurations and hooks.
This tool is designed to be a drop-in alternative for the original pre-commit tool, so you can use it with your existing configurations and hooks.

Please refer to the [official documentation](https://pre-commit.com/) for more information on how to configure and use pre-commit.

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.83"
channel = "1.84"
5 changes: 3 additions & 2 deletions src/builtin/pre_commit_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ pub(crate) async fn fix_trailing_whitespace(
.and_then(|ext| ext.to_str())
.map(|ext| format!(".{}", ext.to_ascii_lowercase()));
let is_markdown =
force_markdown || ext.map_or(false, |ext| markdown_exts.contains(&ext));
force_markdown || ext.is_some_and(|ext| markdown_exts.contains(&ext));

// TODO: read file in chunks
let content = tokio::fs::read(filename).await?;

let mut modified = false;
Expand Down Expand Up @@ -162,7 +163,7 @@ pub(crate) async fn fix_trailing_whitespace(
}
}
})
.buffer_unordered(*CONCURRENCY);
.buffered(*CONCURRENCY);

let mut code = 0;
let mut output = Vec::new();
Expand Down
26 changes: 18 additions & 8 deletions src/cli/run/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterato
use tracing::{debug, error};

use crate::config::Stage;
use crate::env_vars::EnvVars;
use crate::fs::normalize_path;
use crate::git;
use crate::hook::Hook;
Expand Down Expand Up @@ -200,6 +201,11 @@ pub async fn get_filenames(opts: FileOptions) -> Result<Vec<String>> {
)
.await?;

// Sort filenames if in tests to make the order consistent.
if std::env::var_os(EnvVars::PREFLIGIT_INTERNAL__SORT_FILENAMES).is_some() {
filenames.sort_unstable();
}

for filename in &mut filenames {
normalize_path(filename);
}
Expand All @@ -215,15 +221,18 @@ async fn filenames_for_args(
files: Vec<PathBuf>,
commit_msg_filename: Option<PathBuf>,
) -> Result<Vec<String>> {
if hook_stage.is_some_and(|stage| !stage.operate_on_files()) {
return Ok(vec![]);
}
if hook_stage.is_some_and(|stage| matches!(stage, Stage::PrepareCommitMsg | Stage::CommitMsg)) {
return Ok(vec![commit_msg_filename
.unwrap()
.to_string_lossy()
.to_string()]);
if let Some(hook_stage) = hook_stage {
if !hook_stage.operate_on_files() {
return Ok(vec![]);
}
if hook_stage == Stage::PrepareCommitMsg || hook_stage == Stage::CommitMsg {
return Ok(vec![commit_msg_filename
.expect("commit message filename is required")
.to_string_lossy()
.to_string()]);
}
}

if let (Some(from_ref), Some(to_ref)) = (from_ref, to_ref) {
let files = git::get_changed_files(&from_ref, &to_ref).await?;
debug!(
Expand Down Expand Up @@ -253,6 +262,7 @@ async fn filenames_for_args(
debug!("Conflicted files: {}", files.len());
return Ok(files);
}

let files = git::get_staged_files().await?;
debug!("Staged files: {}", files.len());
Ok(files)
Expand Down
3 changes: 3 additions & 0 deletions src/env_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ impl EnvVars {

pub const PREFLIGIT_HOME: &'static str = "PREFLIGIT_HOME";

pub const PREFLIGIT_INTERNAL__SORT_FILENAMES: &'static str =
"PREFLIGIT_INTERNAL__SORT_FILENAMES";

// Pre-commit specific environment variables
pub const PRE_COMMIT_HOME: &'static str = "PRE_COMMIT_HOME";
pub const PRE_COMMIT_ALLOW_NO_CONFIG: &'static str = "PRE_COMMIT_ALLOW_NO_CONFIG";
Expand Down
2 changes: 1 addition & 1 deletion src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl LockedFile {

impl Drop for LockedFile {
fn drop(&mut self) {
if let Err(err) = self.0.file().unlock() {
if let Err(err) = FileExt::unlock(self.0.file()) {
error!(
"Failed to unlock {}; program may be stuck: {}",
self.0.path().display(),
Expand Down
2 changes: 1 addition & 1 deletion src/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ pub fn tags_from_path(path: &Path) -> Result<Vec<&str>> {
#[cfg(not(unix))]
let executable = {
let ext = path.extension().and_then(|ext| ext.to_str());
ext.map_or(false, |ext| ext == "exe" || ext == "bat" || ext == "cmd")
ext.is_some_and(|ext| ext == "exe" || ext == "bat" || ext == "cmd")
};

if executable {
Expand Down
3 changes: 2 additions & 1 deletion src/languages/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::sync::Arc;
use anstream::ColorChoice;
use anyhow::Result;
use fancy_regex::Regex;
use md5::Digest;
use tracing::trace;

use crate::fs::CWD;
Expand All @@ -25,7 +26,7 @@ impl Docker {
hook.path()
.file_name()
.and_then(OsStr::to_str)
.map(|s| format!("pre-commit-{:x}", md5::compute(s)))
.map(|s| format!("pre-commit-{:x}", md5::Md5::digest(s)))
}

async fn build_docker_image(hook: &Hook, pull: bool) -> Result<()> {
Expand Down
3 changes: 2 additions & 1 deletion src/languages/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::collections::HashMap;
use std::sync::Arc;

use anyhow::Result;

use crate::builtin;
use crate::config::Language;
use crate::hook::Hook;
use anyhow::Result;

mod docker;
mod docker_image;
Expand Down
2 changes: 1 addition & 1 deletion src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ where
let batch: Vec<_> = batch.into_iter().map(ToString::to_string).collect();
run(batch)
})
.buffer_unordered(concurrency);
.buffered(concurrency);

let mut results = Vec::new();
while let Some(result) = tasks.next().await {
Expand Down
1 change: 1 addition & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl TestContext {
let mut cmd = Command::new(bin);
cmd.current_dir(self.workdir());
cmd.env("PREFLIGIT_HOME", &*self.home_dir);
cmd.env("PREFLIGIT_INTERNAL__SORT_FILENAMES", "1");
cmd
}

Expand Down
12 changes: 6 additions & 6 deletions tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ fn run_basic() -> Result<()> {
- hook id: end-of-file-fixer
- exit code: 1
- files were modified by this hook
Fixing invalid.json
Fixing valid.json
Fixing invalid.json
Fixing main.py
check json...............................................................Passed
Expand Down Expand Up @@ -231,11 +231,11 @@ fn meta_hooks() -> Result<()> {
identity.................................................................Passed
- hook id: identity
- duration: [TIME]
invalid.json
file.txt
.pre-commit-config.yaml
valid.json
invalid.json
main.py
.pre-commit-config.yaml
file.txt
match no files.......................................(no files to check)Skipped
useless exclude..........................................................Passed
Expand Down Expand Up @@ -545,11 +545,11 @@ fn file_types() -> Result<()> {
trailing-whitespace......................................................Failed
- hook id: trailing-whitespace
- exit code: 1
['json.json', 'main.py']
['main.py', 'json.json']
trailing-whitespace......................................................Failed
- hook id: trailing-whitespace
- exit code: 1
['.pre-commit-config.yaml', 'file.txt', 'main.py']
['file.txt', '.pre-commit-config.yaml', 'main.py']
trailing-whitespace..................................(no files to check)Skipped
----- stderr -----
Expand Down

0 comments on commit 586186b

Please sign in to comment.