aports/community/mcfly/regex-features.patch
2023-04-29 20:00:53 +00:00

67 lines
2.9 KiB
Diff

Patch-Source: https://github.com/cantino/mcfly/pull/352
--
From 0bb947048a5c0fd029e09e1de7020f3de61c08f6 Mon Sep 17 00:00:00 2001
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Sat, 29 Apr 2023 21:27:28 +0200
Subject: [PATCH] Remove unnecessary/unused regex features
This reduces the binary size by ~400 kiB.
---
Cargo.toml | 2 +-
src/shell_history.rs | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index 12f323a..6fdfa6f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -23,7 +23,7 @@ directories-next = "2.0"
itertools = "0.10"
libc = "0.2"
rand = "0.8"
-regex = "1"
+regex = { version = "1", default-features = false, features = ["perf", "std"] }
relative-path = "1.7"
shellexpand = "2.1"
unicode-segmentation = "1.9"
diff --git a/src/shell_history.rs b/src/shell_history.rs
index a5eb592..8fc8304 100644
--- a/src/shell_history.rs
+++ b/src/shell_history.rs
@@ -117,7 +117,7 @@ pub fn full_history(path: &Path, history_format: HistoryFormat) -> Vec<HistoryCo
match history_format {
HistoryFormat::Bash => {
let history_contents = read_ignoring_utf_errors(path);
- let zsh_timestamp_and_duration_regex = Regex::new(r"^: \d+:\d+;").unwrap();
+ let zsh_timestamp_and_duration_regex = Regex::new(r"^: [0-9]+:[0-9]+;").unwrap();
let when = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_else(|err| panic!("McFly error: Time went backwards ({})", err))
@@ -131,7 +131,7 @@ pub fn full_history(path: &Path, history_format: HistoryFormat) -> Vec<HistoryCo
}
HistoryFormat::Zsh { .. } => {
let history_contents = read_and_unmetafy(path);
- let zsh_timestamp_and_duration_regex = Regex::new(r"^: \d+:\d+;").unwrap();
+ let zsh_timestamp_and_duration_regex = Regex::new(r"^: [0-9]+:[0-9]+;").unwrap();
let when = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_else(|err| panic!("McFly error: Time went backwards ({})", err))
@@ -192,7 +192,7 @@ pub fn delete_last_history_entry_if_search(
commands.pop();
}
- let starts_with_mcfly = Regex::new(r"^(: \d+:\d+;)?#mcfly:").unwrap();
+ let starts_with_mcfly = Regex::new(r"^(: [0-9]+:[0-9]+;)?#mcfly:").unwrap();
if commands.is_empty() || !starts_with_mcfly.is_match(&commands[commands.len() - 1].command) {
return; // Abort if empty or the last line isn't a comment.
@@ -226,7 +226,7 @@ pub fn delete_last_history_entry_if_search(
pub fn delete_lines(path: &Path, history_format: HistoryFormat, command: &str) {
let commands = full_history(path, history_format);
- let zsh_timestamp_and_duration_regex = Regex::new(r"^: \d+:\d+;").unwrap();
+ let zsh_timestamp_and_duration_regex = Regex::new(r"^: [0-9]+:[0-9]+;").unwrap();
let lines = commands
.into_iter()