diff --git a/Cargo.lock b/Cargo.lock index e46b318..479be00 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.6" -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" +version = "0.7.7-alpha.2" diff --git a/Cargo.toml b/Cargo.toml index 5855468..23efa1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gitnu" -version = "0.7.6" +version = "0.7.7-alpha.2" authors = ["Nguyen Vu Khang "] description = """ gitnu indexes your git status so you can use numbers instead of filenames. @@ -15,7 +15,6 @@ autotests = false edition = "2021" [dependencies] -atty = "0.2.14" [[bin]] bench = false diff --git a/src/cache.rs b/src/cache.rs index 38c7772..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); - files.push(0.to_string()); - files.extend(lines.take(MAX_CACHE_SIZE - 1)); + 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 }) } 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)) } 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"]); } 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"] +);