Make gh-emoji optional

gh-emoji crate includes *images* of GitHub's emoji - this is quite a big
dependency. It increases the binary size by 1 MiB; that's +25 % when
building v0.18.0 on Alpine Linux with build flags to optimize size.
I consider it an unnecessary bloat that should be optional.
This commit is contained in:
Jakub Jirutka 2021-10-21 02:34:13 +02:00 committed by Stephan Dilly
parent 0360bdf080
commit fa7cd37ca7
5 changed files with 30 additions and 21 deletions

View file

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- support merging and rebasing remote branches ([#920](https://github.com/extrawurst/gitui/issues/920)) - support merging and rebasing remote branches ([#920](https://github.com/extrawurst/gitui/issues/920))
- add highlighting matches in fuzzy finder ([#893](https://github.com/extrawurst/gitui/issues/893)) - add highlighting matches in fuzzy finder ([#893](https://github.com/extrawurst/gitui/issues/893))
- support `home` and `end` keys in branchlist ([#957](https://github.com/extrawurst/gitui/issues/957)) - support `home` and `end` keys in branchlist ([#957](https://github.com/extrawurst/gitui/issues/957))
- add `ghemoji` feature to make gh-emoji (GitHub emoji) optional ([#954](https://github.com/extrawurst/gitui/pull/954))
### Fixed ### Fixed
- honor options (for untracked files) in `stage_all` command ([#933](https://github.com/extrawurst/gitui/issues/933)) - honor options (for untracked files) in `stage_all` command ([#933](https://github.com/extrawurst/gitui/issues/933))

View file

@ -47,7 +47,7 @@ easy-cast = "0.4"
bugreport = "0.4" bugreport = "0.4"
lazy_static = "1.4" lazy_static = "1.4"
syntect = { version = "4.5", default-features = false, features = ["metadata", "default-fancy"]} syntect = { version = "4.5", default-features = false, features = ["metadata", "default-fancy"]}
gh-emoji = "1.0.6" gh-emoji = { version = "1.0.6", optional = true }
fuzzy-matcher = "0.3" fuzzy-matcher = "0.3"
[target.'cfg(all(target_family="unix",not(target_os="macos")))'.dependencies] [target.'cfg(all(target_family="unix",not(target_os="macos")))'.dependencies]
@ -64,7 +64,8 @@ pretty_assertions = "1.0"
maintenance = { status = "actively-developed" } maintenance = { status = "actively-developed" }
[features] [features]
default=["trace-libgit"] default=["ghemoji", "trace-libgit"]
ghemoji=["gh-emoji"]
timing=["scopetime/enabled"] timing=["scopetime/enabled"]
trace-libgit=["asyncgit/trace-libgit"] trace-libgit=["asyncgit/trace-libgit"]

View file

@ -0,0 +1,17 @@
use lazy_static::lazy_static;
use std::borrow::Cow;
lazy_static! {
static ref EMOJI_REPLACER: gh_emoji::Replacer =
gh_emoji::Replacer::new();
}
// Replace markdown emojis with Unicode equivalent
// :hammer: --> 🔨
#[inline]
pub fn emojifi_string(s: &mut String) {
let resulting_cow = EMOJI_REPLACER.replace_all(s);
if let Cow::Owned(altered_s) = resulting_cow {
*s = altered_s;
}
}

View file

@ -2,7 +2,8 @@ use asyncgit::sync::{CommitId, CommitInfo};
use chrono::{DateTime, Duration, Local, NaiveDateTime, Utc}; use chrono::{DateTime, Duration, Local, NaiveDateTime, Utc};
use std::slice::Iter; use std::slice::Iter;
use crate::components::utils::emojifi_string; #[cfg(feature = "ghemoji")]
use super::emoji::emojifi_string;
static SLICE_OFFSET_RELOAD_THRESHOLD: usize = 100; static SLICE_OFFSET_RELOAD_THRESHOLD: usize = 100;
@ -27,9 +28,12 @@ impl From<CommitInfo> for LogEntry {
Utc, Utc,
)); ));
// Replace markdown emojis with Unicode equivalent
let author = c.author; let author = c.author;
#[allow(unused_mut)]
let mut msg = c.message; let mut msg = c.message;
// Replace markdown emojis with Unicode equivalent
#[cfg(feature = "ghemoji")]
emojifi_string(&mut msg); emojifi_string(&mut msg);
Self { Self {
@ -113,6 +117,7 @@ impl ItemBatch {
} }
#[cfg(test)] #[cfg(test)]
#[cfg(feature = "ghemoji")]
mod tests { mod tests {
use super::*; use super::*;

View file

@ -1,8 +1,8 @@
use chrono::{DateTime, Local, NaiveDateTime, Utc}; use chrono::{DateTime, Local, NaiveDateTime, Utc};
use lazy_static::lazy_static;
use std::borrow::Cow;
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
#[cfg(feature = "ghemoji")]
pub mod emoji;
pub mod filetree; pub mod filetree;
pub mod logitems; pub mod logitems;
pub mod scroll_vertical; pub mod scroll_vertical;
@ -55,21 +55,6 @@ pub fn string_width_align(s: &str, width: usize) -> String {
} }
} }
lazy_static! {
static ref EMOJI_REPLACER: gh_emoji::Replacer =
gh_emoji::Replacer::new();
}
// Replace markdown emojis with Unicode equivalent
// :hammer: --> 🔨
#[inline]
pub fn emojifi_string(s: &mut String) {
let resulting_cow = EMOJI_REPLACER.replace_all(s);
if let Cow::Owned(altered_s) = resulting_cow {
*s = altered_s;
}
}
#[inline] #[inline]
fn find_truncate_point(s: &str, chars: usize) -> usize { fn find_truncate_point(s: &str, chars: usize) -> usize {
s.chars().take(chars).map(char::len_utf8).sum() s.chars().take(chars).map(char::len_utf8).sum()