From c77d2eb73fa0d64b7373213807a96dbc078238b9 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Tue, 7 May 2024 11:10:44 -0400 Subject: [PATCH] Increase short SHA length to 7 characters (#11492) This PR increases the length of a shortened Git SHA from 6 to 7 characters. This matches what GitHub uses. I also took the opportunity to factor out a common method for computing a short SHA so that we have a single source of truth for the length that we're using. Release Notes: - Increased the short commit SHA length used by git blame from 6 to 7 characters. --- crates/editor/src/blame_entry_tooltip.rs | 3 +-- crates/editor/src/element.rs | 3 +-- crates/git/src/git.rs | 5 +++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/editor/src/blame_entry_tooltip.rs b/crates/editor/src/blame_entry_tooltip.rs index fc728a6d3283837c1e31ed4b8b77f39e58489634..7864338550d31ed791acd337dede85b76d9e7486 100644 --- a/crates/editor/src/blame_entry_tooltip.rs +++ b/crates/editor/src/blame_entry_tooltip.rs @@ -128,8 +128,7 @@ impl Render for BlameEntryTooltip { let author_email = self.blame_entry.author_mail.clone(); - let pretty_commit_id = format!("{}", self.blame_entry.sha); - let short_commit_id = pretty_commit_id.chars().take(6).collect::(); + let short_commit_id = self.blame_entry.sha.display_short(); let absolute_timestamp = blame_entry_absolute_timestamp(&self.blame_entry, cx); let message = self diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 8f7eeea3e865d78f8f69c50416cbc0759fec980e..2c54a03ed9a687cd1093fcda249a9901ce9ba783 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -3360,8 +3360,7 @@ fn render_blame_entry( let relative_timestamp = blame_entry_relative_timestamp(&blame_entry, cx); - let pretty_commit_id = format!("{}", blame_entry.sha); - let short_commit_id = pretty_commit_id.chars().take(6).collect::(); + let short_commit_id = blame_entry.sha.display_short(); let author_name = blame_entry.author.as_deref().unwrap_or(""); let name = util::truncate_and_trailoff(author_name, 20); diff --git a/crates/git/src/git.rs b/crates/git/src/git.rs index 3664a065a1a75f77dc37a0d198af961b17b49686..92fb6ad8432f21a02b5d0c722a93d46bd50139ca 100644 --- a/crates/git/src/git.rs +++ b/crates/git/src/git.rs @@ -37,6 +37,11 @@ impl Oid { pub(crate) fn is_zero(&self) -> bool { self.0.is_zero() } + + /// Returns this [`Oid`] as a short SHA. + pub fn display_short(&self) -> String { + self.to_string().chars().take(7).collect() + } } impl FromStr for Oid {