Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenvukhang committed Jun 1, 2024
2 parents 6578831 + fc9c23c commit b7c1c8b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 66 deletions.
53 changes: 1 addition & 52 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gitnu"
version = "0.7.6"
version = "0.7.7-alpha.2"
authors = ["Nguyen Vu Khang <[email protected]>"]
description = """
gitnu indexes your git status so you can use numbers instead of filenames.
Expand All @@ -15,7 +15,6 @@ autotests = false
edition = "2021"

[dependencies]
atty = "0.2.14"

[[bin]]
bench = false
Expand Down
17 changes: 12 additions & 5 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
files: Vec<String>,
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 {
Expand Down Expand Up @@ -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 })
}
Expand Down
8 changes: 2 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
4 changes: 3 additions & 1 deletion src/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::collections::HashMap;
#[cfg(not(test))]
use std::io::IsTerminal;

use crate::prelude::*;

Expand Down Expand Up @@ -29,7 +31,7 @@ pub fn parse<A: ArgHolder>(
let mut git_cmd = None::<GitCommand>;

#[cfg(not(test))]
if atty::is(atty::Stream::Stdout) {
if std::io::stdout().is_terminal() {
argh.add_args(["-c", "color.ui=always"]);
}

Expand Down
11 changes: 11 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
);

0 comments on commit b7c1c8b

Please sign in to comment.