summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2022-01-18 11:34:41 +0100
committerDan Davison <dandavison7@gmail.com>2022-01-25 09:12:04 -0500
commit019752a664690e244fe41907147feeacd3c95a06 (patch)
tree7779bfa7b7eee00680d625807df883d01d504468
parent29a963143c10685548dcd1f75fb3ca0eb7663b62 (diff)
Update sysinfo version to 0.23
-rw-r--r--Cargo.lock4
-rw-r--r--Cargo.toml2
-rw-r--r--src/config.rs3
-rw-r--r--src/handlers/blame.rs2
-rw-r--r--src/handlers/grep.rs5
-rw-r--r--src/subcommands/show_config.rs2
-rw-r--r--src/utils/process.rs256
7 files changed, 195 insertions, 79 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d729f139..7a460881 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1041,9 +1041,9 @@ dependencies = [
[[package]]
name = "sysinfo"
-version = "0.22.4"
+version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ccb37aa4af23791c584202d286ed9420e023e9d27e49d5a76215623f4bcc2502"
+checksum = "9e757000a4bed2b1be9be65a3f418b9696adf30bb419214c73997422de73a591"
dependencies = [
"cfg-if 1.0.0",
"core-foundation-sys",
diff --git a/Cargo.toml b/Cargo.toml
index fb634097..9201f41e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -53,7 +53,7 @@ default-features = false
features = ["parsing", "assets", "yaml-load", "dump-load", "regex-onig"]
[dependencies.sysinfo]
-version = "0.22.4"
+version = "0.23.0"
# no default features to disable the use of threads
default-features = false
features = []
diff --git a/src/config.rs b/src/config.rs
index 67e435b1..62edb3b3 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -281,8 +281,7 @@ impl From<cli::Opt> for Config {
file_regex_replacement: opt
.file_regex_replacement
.as_deref()
- .map(RegexReplacement::from_sed_command)
- .flatten(),
+ .and_then(RegexReplacement::from_sed_command),
right_arrow,
hunk_label,
file_style: styles["file-style"],
diff --git a/src/handlers/blame.rs b/src/handlers/blame.rs
index 41b1c42b..5ec7e9ff 100644
--- a/src/handlers/blame.rs
+++ b/src/handlers/blame.rs
@@ -78,7 +78,7 @@ impl<'a> StateMachine<'a> {
if matches!(self.state, State::Unknown) {
if let Some(lang) = utils::process::git_blame_filename_extension()
.as_ref()
- .or_else(|| self.config.default_language.as_ref())
+ .or(self.config.default_language.as_ref())
{
self.painter.set_syntax(Some(lang));
self.painter.set_highlighter();
diff --git a/src/handlers/grep.rs b/src/handlers/grep.rs
index 877f198f..f49e3472 100644
--- a/src/handlers/grep.rs
+++ b/src/handlers/grep.rs
@@ -58,7 +58,7 @@ impl<'a> StateMachine<'a> {
// Emit syntax-highlighted code
// TODO: Determine the language less frequently, e.g. only when the file changes.
if let Some(lang) = handlers::diff_header::get_extension(&grep_line.path)
- .or_else(|| self.config.default_language.as_deref())
+ .or(self.config.default_language.as_deref())
{
self.painter.set_syntax(Some(lang));
self.painter.set_highlighter();
@@ -454,8 +454,7 @@ pub fn _parse_grep_line<'b>(regex: &Regex, line: &'b str) -> Option<GrepLine<'b>
.iter()
.find_map(|(i, line_type)| {
if caps.get(*i).is_some() {
- let line_number: Option<usize> =
- caps.get(i + 1).map(|m| m.as_str().parse().ok()).flatten();
+ let line_number: Option<usize> = caps.get(i + 1).and_then(|m| m.as_str().parse().ok());
Some((*line_type, line_number))
} else {
None
diff --git a/src/subcommands/show_config.rs b/src/subcommands/show_config.rs
index d99ccdba..26dc0db0 100644
--- a/src/subcommands/show_config.rs
+++ b/src/subcommands/show_config.rs
@@ -136,7 +136,7 @@ pub fn show_config(config: &config::Config, writer: &mut dyn Write) -> std::io::
navigate = config.navigate,
navigate_regex = match &config.navigate_regex {
None => "".to_string(),
- Some(s) => format_option_value(s.to_string()),
+ Some(s) => format_option_value(s),
},
pager = config.pager.clone().unwrap_or_else(|| "none".to_string()),
paging_mode = match config.paging_mode {
diff --git a/src/utils/process.rs b/src/utils/process.rs
index 224eab87..a43ea77b 100644
--- a/src/utils/process.rs
+++ b/src/utils/process.rs
@@ -3,7 +3,7 @@ use std::path::Path;
use std::sync::{Arc, Condvar, Mutex, MutexGuard};
use lazy_static::lazy_static;
-use sysinfo::{Pid, Process, ProcessExt, ProcessRefreshKind, SystemExt};
+use sysinfo::{Pid, PidExt, Process, ProcessExt, ProcessRefreshKind, SystemExt};
#[derive(Clone, Debug, PartialEq)]
pub enum CallingProcess {
@@ -320,7 +320,7 @@ trait ProcessInterface {
self.process(parent_pid)
}
fn naive_sibling_process(&mut self, pid: Pid) -> Option<&Self::Out> {
- let sibling_pid = pid - 1;
+ let sibling_pid = Pid::from_u32(pid.as_u32() - 1);
self.refresh_process(sibling_pid).then(|| ())?;
self.process(sibling_pid)
}
@@ -397,7 +397,7 @@ impl ProcessInterface for ProcInfo {
type Out = Process;
fn my_pid(&self) -> Pid {
- std::process::id() as Pid
+ Pid::from_u32(std::process::id() as _)
}
fn refresh_process(&mut self, pid: Pid) -> bool {
self.info
@@ -480,12 +480,13 @@ where
*/
- let pid_range = my_pid.saturating_sub(10)..my_pid.saturating_add(20);
+ let my_pid_u32 = my_pid.as_u32();
+ let pid_range = my_pid_u32.saturating_sub(10)..my_pid_u32.saturating_add(20);
for p in pid_range {
// Processes which were not refreshed do not exist for sysinfo, so by selectively
// letting it know about processes the `find_sibling..` function will only
// consider these.
- info.refresh_process(p);
+ info.refresh_process(Pid::from_u32(p));
}
match info.find_sibling_in_refreshed_processes(my_pid, &extract_args) {
@@ -696,7 +697,7 @@ pub mod tests {
assert_eq!(guess_git_blame_filename_extension(&args), Args("".into()));
}
- #[derive(Debug, Default)]
+ #[derive(Debug)]
struct FakeProc {
#[allow(dead_code)]
pid: Pid,
@@ -704,6 +705,16 @@ pub mod tests {
cmd: Vec<String>,
ppid: Option<Pid>,
}
+ impl Default for FakeProc {
+ fn default() -> Self {
+ Self {
+ pid: Pid::from_u32(0),
+ start_time: 0,
+ cmd: Vec::new(),
+ ppid: None,
+ }
+ }
+ }
impl FakeProc {
fn new(pid: Pid, start_time: u64, cmd: Vec<String>, ppid: Option<Pid>) -> Self {
FakeProc {
@@ -727,15 +738,23 @@ pub mod tests {
}
}
- #[derive(Debug, Default)]
+ #[derive(Debug)]
struct MockProcInfo {
delta_pid: Pid,
info: HashMap<Pid, FakeProc>,
}
+ impl Default for MockProcInfo {
+ fn default() -> Self {
+ Self {
+ delta_pid: Pid::from_u32(0),
+ info: HashMap::new(),
+ }
+ }
+ }
impl MockProcInfo {
fn with(processes: &[(Pid, u64, &str, Option<Pid>)]) -> Self {
MockProcInfo {
- delta_pid: processes.last().map(|p| p.0).unwrap_or(1),
+ delta_pid: processes.last().map(|p| p.0).unwrap_or(Pid::from_u32(1)),
info: processes
.iter()
.map(|(pid, start_time, cmd, ppid)| {
@@ -872,10 +891,15 @@ pub mod tests {
#[test]
fn test_process_blame_no_parent_found() {
let two_trees = MockProcInfo::with(&[
- (2, 100, "-shell", None),
- (3, 100, "git blame src/main.rs", Some(2)),
- (4, 100, "call_delta.sh", None),
- (5, 100, "delta", Some(4)),
+ (Pid::from_u32(2), 100, "-shell", None),
+ (
+ Pid::from_u32(3),
+ 100,
+ "git blame src/main.rs",
+ Some(Pid::from_u32(2)),
+ ),
+ (Pid::from_u32(4), 100, "call_delta.sh", None),
+ (Pid::from_u32(5), 100, "delta", Some(Pid::from_u32(4))),
]);
assert_eq!(
calling_process_cmdline(two_trees, guess_git_blame_filename_extension),
@@ -892,9 +916,14 @@ pub mod tests {
);
let parent = MockProcInfo::with(&[
- (2, 100, "-shell", None),
- (3, 100, "git blame hello.txt", Some(2)),
- (4, 100, "delta", Some(3)),
+ (Pid::from_u32(2), 100, "-shell", None),
+ (
+ Pid::from_u32(3),
+ 100,
+ "git blame hello.txt",
+ Some(Pid::from_u32(2)),
+ ),
+ (Pid::from_u32(4), 100, "delta", Some(Pid::from_u32(3))),
]);
assert_eq!(
calling_process_cmdline(parent, guess_git_blame_filename_extension),
@@ -902,10 +931,20 @@ pub mod tests {
);
let grandparent = MockProcInfo::with(&[
- (2, 100, "-shell", None),
- (3, 100, "git blame src/main.rs", Some(2)),
- (4, 100, "call_delta.sh", Some(3)),
- (5, 100, "delta", Some(4)),
+ (Pid::from_u32(2), 100, "-shell", None),
+ (
+ Pid::from_u32(3),
+ 100,
+ "git blame src/main.rs",
+ Some(Pid::from_u32(2)),
+ ),
+ (
+ Pid::from_u32(4),
+ 100,
+ "call_delta.sh",
+ Some(Pid::from_u32(3)),
+ ),
+ (Pid::from_u32(5), 100, "delta", Some(Pid::from_u32(4))),
]);
assert_eq!(
calling_process_cmdline(grandparent, guess_git_blame_filename_extension),
@@ -916,10 +955,15 @@ pub mod tests {
#[test]
fn test_process_blame_info_with_sibling() {
let sibling = MockProcInfo::with(&[
- (2, 100, "-xterm", None),
- (3, 100, "-shell", Some(2)),
- (4, 100, "git blame src/main.rs", Some(3)),
- (5, 100, "delta", Some(3)),
+ (Pid::from_u32(2), 100, "-xterm", None),
+ (Pid::from_u32(3), 100, "-shell", Some(Pid::from_u32(2))),
+ (
+ Pid::from_u32(4),
+ 100,
+ "git blame src/main.rs",
+ Some(Pid::from_u32(3)),
+ ),
+ (Pid::from_u32(5), 100, "delta", Some(Pid::from_u32(3))),
]);
assert_eq!(
calling_process_cmdline(sibling, guess_git_blame_filename_extension),
@@ -927,17 +971,22 @@ pub mod tests {
);
let indirect_sibling = MockProcInfo::with(&[
- (2, 100, "-xterm", None),
- (3, 100, "-shell", Some(2)),
- (4, 100, "Git.exe blame --correct src/main.abc", Some(3)),
+ (Pid::from_u32(2), 100, "-xterm", None),
+ (Pid::from_u32(3), 100, "-shell", Some(Pid::from_u32(2))),
(
- 10,
+ Pid::from_u32(4),
+ 100,
+ "Git.exe blame --correct src/main.abc",
+ Some(Pid::from_u32(3)),
+ ),
+ (
+ Pid::from_u32(10),
100,
"Git.exe blame --ignored-child src/main.def",
- Some(4),
+ Some(Pid::from_u32(4)),
),
- (5, 100, "delta.sh", Some(3)),
- (20, 100, "delta", Some(5)),
+ (Pid::from_u32(5), 100, "delta.sh", Some(Pid::from_u32(3))),
+ (Pid::from_u32(20), 100, "delta", Some(Pid::from_u32(5))),
]);
assert_eq!(
calling_process_cmdline(indirect_sibling, guess_git_blame_filename_extension),
@@ -945,12 +994,22 @@ pub mod tests {
);
let indirect_sibling2 = MockProcInfo::with(&[
- (2, 100, "-xterm", None),
- (3, 100, "-shell", Some(2)),
- (4, 100, "git wrap src/main.abc", Some(3)),
- (10, 100, "git blame src/main.def", Some(4)),
- (5, 100, "delta.sh", Some(3)),
- (20, 100, "delta", Some(5)),
+ (Pid::from_u32(2), 100, "-xterm", None),
+ (Pid::from_u32(3), 100, "-shell", Some(Pid::from_u32(2))),
+ (
+ Pid::from_u32(4),
+ 100,
+ "git wrap src/main.abc",
+ Some(Pid::from_u32(3)),
+ ),
+ (
+ Pid::from_u32(10),
+ 100,
+ "git blame src/main.def",
+ Some(Pid::from_u32(4)),
+ ),
+ (Pid::from_u32(5), 100, "delta.sh", Some(Pid::from_u32(3))),
+ (Pid::from_u32(20), 100, "delta", Some(Pid::from_u32(5))),
]);
assert_eq!(
calling_process_cmdline(indirect_sibling2, guess_git_blame_filename_extension),
@@ -960,16 +1019,46 @@ pub mod tests {
// 3 blame processes, 2 with matching start times, pick the one with lower
// distance but larger start time difference.
let indirect_sibling_start_times = MockProcInfo::with(&[
- (2, 100, "-xterm", None),
- (3, 100, "-shell", Some(2)),
- (4, 109, "git wrap src/main.abc", Some(3)),
- (10, 109, "git blame src/main.def", Some(4)),
- (20, 100, "git wrap1 src/main.abc", Some(3)),
- (21, 100, "git wrap2 src/main.def", Some(20)),
- (22, 101, "git blame src/main.not", Some(21)),
- (23, 102, "git blame src/main.this", Some(20)),
- (5, 100, "delta.sh", Some(3)),
- (20, 100, "delta", Some(5)),
+ (Pid::from_u32(2), 100, "-xterm", None),
+ (Pid::from_u32(3), 100, "-shell", Some(Pid::from_u32(2))),
+ (
+ Pid::from_u32(4),
+ 109,
+ "git wrap src/main.abc",
+ Some(Pid::from_u32(3)),
+ ),
+ (
+ Pid::from_u32(10),
+ 109,
+ "git blame src/main.def",
+ Some(Pid::from_u32(4)),
+ ),
+ (
+ Pid::from_u32(20),
+ 100,
+ "git wrap1 src/main.abc",
+ Some(Pid::from_u32(3)),
+ ),
+ (
+ Pid::from_u32(21),
+ 100,
+ "git wrap2 src/main.def",
+ Some(Pid::from_u32(20)),
+ ),
+ (
+ Pid::from_u32(22),
+ 101,
+ "git blame src/main.not",
+ Some(Pid::from_u32(21)),
+ ),
+ (
+ Pid::from_u32(23),
+ 102,
+ "git blame src/main.this",
+ Some(Pid::from_u32(20)),
+ ),
+ (Pid::from_u32(5), 100, "delta.sh", Some(Pid::from_u32(3))),
+ (Pid::from_u32(20), 100, "delta", Some(Pid::from_u32(5))),
]);
assert_eq!(
calling_process_cmdline(
@@ -994,9 +1083,14 @@ pub mod tests {
last_arg: Some("hello.txt".to_string()),
};
let parent = MockProcInfo::with(&[
- (2, 100, "-shell", None),
- (3, 100, "git grep pattern hello.txt", Some(2)),
- (4, 100, "delta", Some(3)),
+ (Pid::from_u32(2), 100, "-shell", None),
+ (
+ Pid::from_u32(3),
+ 100,
+ "git grep pattern hello.txt",
+ Some(Pid::from_u32(2)),
+ ),
+ (Pid::from_u32(4), 100, "delta", Some(Pid::from_u32(3))),
]);
assert_eq!(
calling_process_cmdline(parent, describe_calling_process),
@@ -1004,9 +1098,14 @@ pub mod tests {
);
let parent = MockProcInfo::with(&[
- (2, 100, "-shell", None),
- (3, 100, "Git.exe grep pattern hello.txt", Some(2)),
- (4, 100, "delta", Some(3)),
+ (Pid::from_u32(2), 100, "-shell", None),
+ (
+ Pid::from_u32(3),
+ 100,
+ "Git.exe grep pattern hello.txt",
+ Some(Pid::from_u32(2)),
+ ),
+ (Pid::from_u32(4), 100, "delta", Some(Pid::from_u32(3))),
]);
assert_eq!(
calling_process_cmdline(parent, describe_calling_process),
@@ -1020,9 +1119,9 @@ pub mod tests {
"ack.exe pattern hello.txt",
] {
let parent = MockProcInfo::with(&[
- (2, 100, "-shell", None),
- (3, 100, grep_command, Some(2)),
- (4, 100, "delta", Some(3)),
+ (Pid::from_u32(2), 100, "-shell", None),
+ (Pid::from_u32(3), 100, grep_command, Some(Pid::from_u32(2))),
+ (Pid::from_u32(4), 100, "delta", Some(Pid::from_u32(3))),
]);
assert_eq!(
calling_process_cmdline(parent, describe_calling_process),
@@ -1040,9 +1139,14 @@ pub mod tests {
}));
let parent = MockProcInfo::with(&[
- (2, 100, "-shell", None),
- (3, 100, git_grep_command, Some(2)),
- (4, 100, "delta", Some(3)),
+ (Pid::from_u32(2), 100, "-shell", None),
+ (
+ Pid::from_u32(3),
+ 100,
+ git_grep_command,
+ Some(Pid::from_u32(2)),
+ ),
+ (Pid::from_u32(4), 100, "delta", Some(Pid::from_u32(3))),
]);
assert_eq!(
calling_process_cmdline(parent, describe_calling_process),
@@ -1050,10 +1154,20 @@ pub mod tests {
);
let grandparent = MockProcInfo::with(&[
- (2, 100, "-shell", None),
- (3, 100, git_grep_command, Some(2)),
- (4, 100, "call_delta.sh", Some(3)),
- (5, 100, "delta", Some(4)),
+ (Pid::from_u32(2), 100, "-shell", None),
+ (
+ Pid::from_u32(3),
+ 100,
+ git_grep_command,
+ Some(Pid::from_u32(2)),
+ ),
+ (
+ Pid::from_u32(4),
+ 100,
+ "call_delta.sh",
+ Some(Pid::from_u32(3)),
+ ),
+ (Pid::from_u32(5), 100, "delta", Some(Pid::from_u32(4))),
]);
assert_eq!(
calling_process_cmdline(grandparent, describe_calling_process),
@@ -1078,9 +1192,9 @@ pub mod tests {
),
] {
let parent = MockProcInfo::with(&[
- (2, 100, "-shell", None),
- (3, 100, command, Some(2)),
- (4, 100, "delta", Some(3)),
+ (Pid::from_u32(2), 100, "-shell", None),
+ (Pid::from_u32(3), 100, command, Some(Pid::from_u32(2))),
+ (Pid::from_u32(4), 100, "delta", Some(Pid::from_u32(3))),
]);
if let Some(CallingProcess::GitShow(cmd_line, ext)) =
calling_process_cmdline(parent, describe_calling_process)
@@ -1105,10 +1219,14 @@ pub mod tests {
info.refresh_processes();
let mut ppid_distance = Vec::new();
- iter_parents(&info, std::process::id() as Pid, |pid, distance| {
- ppid_distance.push(pid as i32);
- ppid_distance.push(distance as i32)
- });
+ iter_parents(
+ &info,
+ Pid::from_u32(std::process::id() as _),
+ |pid, distance| {
+ ppid_distance.push(pid.as_u32() as i32);
+ ppid_distance.push(distance as i32)
+ },
+ );
assert!(ppid_distance[1] == 1);