Skip to content

Commit fa7cd37

Browse files
jirutkaStephan Dilly
authored and
Stephan Dilly
committed
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.
1 parent 0360bdf commit fa7cd37

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- support merging and rebasing remote branches ([#920](https://github.com/extrawurst/gitui/issues/920))
1313
- add highlighting matches in fuzzy finder ([#893](https://github.com/extrawurst/gitui/issues/893))
1414
- support `home` and `end` keys in branchlist ([#957](https://github.com/extrawurst/gitui/issues/957))
15+
- add `ghemoji` feature to make gh-emoji (GitHub emoji) optional ([#954](https://github.com/extrawurst/gitui/pull/954))
1516

1617
### Fixed
1718
- honor options (for untracked files) in `stage_all` command ([#933](https://github.com/extrawurst/gitui/issues/933))

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ easy-cast = "0.4"
4747
bugreport = "0.4"
4848
lazy_static = "1.4"
4949
syntect = { version = "4.5", default-features = false, features = ["metadata", "default-fancy"]}
50-
gh-emoji = "1.0.6"
50+
gh-emoji = { version = "1.0.6", optional = true }
5151
fuzzy-matcher = "0.3"
5252

5353
[target.'cfg(all(target_family="unix",not(target_os="macos")))'.dependencies]
@@ -64,7 +64,8 @@ pretty_assertions = "1.0"
6464
maintenance = { status = "actively-developed" }
6565

6666
[features]
67-
default=["trace-libgit"]
67+
default=["ghemoji", "trace-libgit"]
68+
ghemoji=["gh-emoji"]
6869
timing=["scopetime/enabled"]
6970
trace-libgit=["asyncgit/trace-libgit"]
7071

src/components/utils/emoji.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use lazy_static::lazy_static;
2+
use std::borrow::Cow;
3+
4+
lazy_static! {
5+
static ref EMOJI_REPLACER: gh_emoji::Replacer =
6+
gh_emoji::Replacer::new();
7+
}
8+
9+
// Replace markdown emojis with Unicode equivalent
10+
// :hammer: --> 🔨
11+
#[inline]
12+
pub fn emojifi_string(s: &mut String) {
13+
let resulting_cow = EMOJI_REPLACER.replace_all(s);
14+
if let Cow::Owned(altered_s) = resulting_cow {
15+
*s = altered_s;
16+
}
17+
}

src/components/utils/logitems.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use asyncgit::sync::{CommitId, CommitInfo};
22
use chrono::{DateTime, Duration, Local, NaiveDateTime, Utc};
33
use std::slice::Iter;
44

5-
use crate::components::utils::emojifi_string;
5+
#[cfg(feature = "ghemoji")]
6+
use super::emoji::emojifi_string;
67

78
static SLICE_OFFSET_RELOAD_THRESHOLD: usize = 100;
89

@@ -27,9 +28,12 @@ impl From<CommitInfo> for LogEntry {
2728
Utc,
2829
));
2930

30-
// Replace markdown emojis with Unicode equivalent
3131
let author = c.author;
32+
#[allow(unused_mut)]
3233
let mut msg = c.message;
34+
35+
// Replace markdown emojis with Unicode equivalent
36+
#[cfg(feature = "ghemoji")]
3337
emojifi_string(&mut msg);
3438

3539
Self {
@@ -113,6 +117,7 @@ impl ItemBatch {
113117
}
114118

115119
#[cfg(test)]
120+
#[cfg(feature = "ghemoji")]
116121
mod tests {
117122
use super::*;
118123

src/components/utils/mod.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use chrono::{DateTime, Local, NaiveDateTime, Utc};
2-
use lazy_static::lazy_static;
3-
use std::borrow::Cow;
42
use unicode_width::UnicodeWidthStr;
53

4+
#[cfg(feature = "ghemoji")]
5+
pub mod emoji;
66
pub mod filetree;
77
pub mod logitems;
88
pub mod scroll_vertical;
@@ -55,21 +55,6 @@ pub fn string_width_align(s: &str, width: usize) -> String {
5555
}
5656
}
5757

58-
lazy_static! {
59-
static ref EMOJI_REPLACER: gh_emoji::Replacer =
60-
gh_emoji::Replacer::new();
61-
}
62-
63-
// Replace markdown emojis with Unicode equivalent
64-
// :hammer: --> 🔨
65-
#[inline]
66-
pub fn emojifi_string(s: &mut String) {
67-
let resulting_cow = EMOJI_REPLACER.replace_all(s);
68-
if let Cow::Owned(altered_s) = resulting_cow {
69-
*s = altered_s;
70-
}
71-
}
72-
7358
#[inline]
7459
fn find_truncate_point(s: &str, chars: usize) -> usize {
7560
s.chars().take(chars).map(char::len_utf8).sum()

0 commit comments

Comments
 (0)