From da0bd3e7f7095a319f9cddbde5944132c39d85d9 Mon Sep 17 00:00:00 2001 From: nguyenvukhang Date: Tue, 7 May 2024 16:01:45 +0800 Subject: [PATCH 1/7] Drop unnecessary multithreading --- src/main.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8506b94..5deb906 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,17 +15,13 @@ use prelude::*; use std::env::{args, current_dir}; use std::path::PathBuf; use std::process::{Command, ExitCode, ExitStatus}; -use std::thread; /// Returning `Err` here means the failure comes from factors outside /// of `gitnu`. This means we should execute a full bypass to `git` to /// let it reflect the errors. fn prefetch(cwd: PathBuf) -> Result<(PathBuf, PathBuf, Aliases)> { - let h_git_dir = thread::spawn(move || git::dir(&cwd).map(|gd| (gd, cwd))); - let h_git_aliases = thread::spawn(git::aliases); - - let (git_dir, cwd) = h_git_dir.join()??; - let git_aliases = h_git_aliases.join()?; + let git_dir = git::dir(&cwd)?; + let git_aliases = git::aliases(); Ok((cwd, git_dir, git_aliases)) } From 792b8f90dbe59b7bf3ee6552e4fbe8122b49b499 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 7 May 2024 08:03:12 +0000 Subject: [PATCH 2/7] ver: bump to 0.7.7-alpha.0 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e46b318..289ae3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,7 +15,7 @@ dependencies = [ [[package]] name = "gitnu" -version = "0.7.6" +version = "0.7.7-alpha.0" dependencies = [ "atty", ] diff --git a/Cargo.toml b/Cargo.toml index 5855468..7e1aa6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gitnu" -version = "0.7.6" +version = "0.7.7-alpha.0" authors = ["Nguyen Vu Khang "] description = """ gitnu indexes your git status so you can use numbers instead of filenames. From eb378663744c7cf91a29471cbf479f97595fcf59 Mon Sep 17 00:00:00 2001 From: nguyenvukhang Date: Sat, 11 May 2024 10:26:56 +0800 Subject: [PATCH 3/7] Drop dependency on atty --- Cargo.lock | 51 --------------------------------------------------- Cargo.toml | 1 - src/parse.rs | 4 +++- 3 files changed, 3 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 289ae3c..1a2a564 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,57 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - [[package]] name = "gitnu" version = "0.7.7-alpha.0" -dependencies = [ - "atty", -] - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "libc" -version = "0.2.147" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 7e1aa6b..06c361c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ autotests = false edition = "2021" [dependencies] -atty = "0.2.14" [[bin]] bench = false diff --git a/src/parse.rs b/src/parse.rs index 5952d78..4005598 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -1,4 +1,6 @@ use std::collections::HashMap; +#[cfg(not(test))] +use std::io::IsTerminal; use crate::prelude::*; @@ -29,7 +31,7 @@ pub fn parse( let mut git_cmd = None::; #[cfg(not(test))] - if atty::is(atty::Stream::Stdout) { + if std::io::stdout().is_terminal() { argh.add_args(["-c", "color.ui=always"]); } From 3bf4dc31c885a7d075a2e4d89227bcfceaabbebc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 11 May 2024 02:28:36 +0000 Subject: [PATCH 4/7] ver: bump to 0.7.7-alpha.1 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1a2a564..84e36f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,4 +4,4 @@ version = 3 [[package]] name = "gitnu" -version = "0.7.7-alpha.0" +version = "0.7.7-alpha.1" diff --git a/Cargo.toml b/Cargo.toml index 06c361c..8534bf8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gitnu" -version = "0.7.7-alpha.0" +version = "0.7.7-alpha.1" authors = ["Nguyen Vu Khang "] description = """ gitnu indexes your git status so you can use numbers instead of filenames. From 9d02dd72a2655536bb389fb5ffc80d2628538214 Mon Sep 17 00:00:00 2001 From: nguyenvukhang Date: Sat, 1 Jun 2024 21:27:39 +0800 Subject: [PATCH 5/7] Fix: using last index (MAX_CACHE_SIZE) --- src/cache.rs | 4 ++-- src/tests.rs | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/cache.rs b/src/cache.rs index 38c7772..d1d7f27 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -40,9 +40,9 @@ impl Cache { } }; - let mut files = Vec::with_capacity(MAX_CACHE_SIZE); + let mut files = Vec::with_capacity(MAX_CACHE_SIZE + 1); files.push(0.to_string()); - files.extend(lines.take(MAX_CACHE_SIZE - 1)); + files.extend(lines.take(MAX_CACHE_SIZE)); Ok(Self { prefix, files }) } diff --git a/src/tests.rs b/src/tests.rs index 3cf7041..0186575 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -643,3 +643,14 @@ Untracked files: nothing added to commit but untracked files present\n" ); + +test!( + max_cache_add_by_number, + |t| { + t.sh("", "git init -b main"); + t.sh("", "touch A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 C0 C1 C2"); + let _ = t.gitnu("", ["status"]); + }, + ["add", "17-20"], + ["add", "B6", "B7", "B8", "B9"] +); From 7f783f5f73e79b6991b83083a1963e2506642cba Mon Sep 17 00:00:00 2001 From: nguyenvukhang Date: Sat, 1 Jun 2024 21:35:28 +0800 Subject: [PATCH 6/7] Use array for cache --- src/cache.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/cache.rs b/src/cache.rs index d1d7f27..a004b1d 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -4,10 +4,16 @@ use std::fs::File; use std::io::{BufRead, BufReader}; use std::path::{Path, PathBuf}; -#[derive(Debug, Default)] +#[derive(Debug)] pub struct Cache { prefix: Option, - files: Vec, + files: [String; MAX_CACHE_SIZE + 1], +} + +impl Default for Cache { + fn default() -> Self { + Self { prefix: None, files: std::array::from_fn(|i| i.to_string()) } + } } impl Cache { @@ -40,9 +46,10 @@ impl Cache { } }; - let mut files = Vec::with_capacity(MAX_CACHE_SIZE + 1); - files.push(0.to_string()); - files.extend(lines.take(MAX_CACHE_SIZE)); + let files = std::array::from_fn(|i| match i { + 0 => "0".to_string(), + i => lines.next().unwrap_or_else(|| i.to_string()), + }); Ok(Self { prefix, files }) } From fc9c23c28dacc9814c480d342c625f07cb3ae2ce Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 1 Jun 2024 13:36:47 +0000 Subject: [PATCH 7/7] ver: bump to 0.7.7-alpha.2 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 84e36f4..479be00 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,4 +4,4 @@ version = 3 [[package]] name = "gitnu" -version = "0.7.7-alpha.1" +version = "0.7.7-alpha.2" diff --git a/Cargo.toml b/Cargo.toml index 8534bf8..23efa1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gitnu" -version = "0.7.7-alpha.1" +version = "0.7.7-alpha.2" authors = ["Nguyen Vu Khang "] description = """ gitnu indexes your git status so you can use numbers instead of filenames.