consolidate shared helpers into utils crate
This commit is contained in:
@@ -1418,7 +1418,7 @@ impl PushOutcome {
|
||||
self.failing()
|
||||
.map(|server| {
|
||||
let reason =
|
||||
flatten_whitespace(server.reason.as_deref().unwrap_or("unknown error"));
|
||||
utils::flatten_whitespace(server.reason.as_deref().unwrap_or("unknown error"));
|
||||
format!("{}: {reason}", server.relay)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
@@ -1441,18 +1441,6 @@ impl PushOutcome {
|
||||
}
|
||||
}
|
||||
|
||||
fn flatten_whitespace(text: &str) -> String {
|
||||
const MAX_CHARS: usize = 200;
|
||||
let flat: String = text.split_whitespace().collect::<Vec<_>>().join(" ");
|
||||
if flat.chars().count() <= MAX_CHARS {
|
||||
flat
|
||||
} else {
|
||||
let mut clipped: String = flat.chars().take(MAX_CHARS).collect();
|
||||
clipped.push('…');
|
||||
clipped
|
||||
}
|
||||
}
|
||||
|
||||
/// Reasons a push attempt should be retried with a freshly staged state
|
||||
/// event and a fresh git advertisement.
|
||||
///
|
||||
|
||||
@@ -7,6 +7,7 @@ use gpui::{App, AppContext, Context, Entity, Global, Subscription};
|
||||
use nostr::prelude::*;
|
||||
use settings::{CheckoutRecord, SettingsStore};
|
||||
use signed_core::{Announcement, RepoAddr};
|
||||
use utils::same_repo_url;
|
||||
|
||||
use crate::backend::{Backend, BackendEvent};
|
||||
use crate::git_store::repo_mirror_root;
|
||||
@@ -511,23 +512,6 @@ impl CheckoutsStore {
|
||||
}
|
||||
}
|
||||
|
||||
fn url_identity(url: &str) -> Option<(String, Option<u16>, String)> {
|
||||
let parsed = Url::parse(url).ok()?;
|
||||
let host = parsed.host_str()?.to_ascii_lowercase();
|
||||
let mut path = parsed.path().trim_matches('/').to_owned();
|
||||
if let Some(stripped) = path.strip_suffix(".git") {
|
||||
path = stripped.to_owned();
|
||||
}
|
||||
Some((host, parsed.port(), path))
|
||||
}
|
||||
|
||||
fn same_repo_url(a: &str, b: &str) -> bool {
|
||||
match (url_identity(a), url_identity(b)) {
|
||||
(Some(a), Some(b)) => a == b,
|
||||
_ => a == b,
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_associations<'a>(
|
||||
remembered: &[Remembered],
|
||||
scanned: &[(PathBuf, Option<String>, Option<String>)],
|
||||
|
||||
@@ -392,12 +392,12 @@ impl RepoStore {
|
||||
.into_iter()
|
||||
.filter(|e| !deletions.is_deleted(e));
|
||||
|
||||
let announcement = latest(all_announcements)
|
||||
let announcement = utils::latest(all_announcements)
|
||||
.as_ref()
|
||||
.and_then(Announcement::from_event);
|
||||
|
||||
let all_states = states.into_iter().filter(|e| !deletions.is_deleted(e));
|
||||
let state = latest(all_states).map(|state| parse_state(&state));
|
||||
let state = utils::latest(all_states).map(|state| parse_state(&state));
|
||||
|
||||
let (mut issues, mut patches, mut pull_requests, mut statuses, mut comments) =
|
||||
(Vec::new(), Vec::new(), Vec::new(), Vec::new(), Vec::new());
|
||||
@@ -450,10 +450,10 @@ impl RepoStore {
|
||||
}
|
||||
}
|
||||
|
||||
sort_newest_first(&mut issues);
|
||||
sort_newest_first(&mut patches);
|
||||
sort_newest_first(&mut pull_requests);
|
||||
sort_oldest_first(&mut comments);
|
||||
utils::sort_newest_first(&mut issues);
|
||||
utils::sort_newest_first(&mut patches);
|
||||
utils::sort_newest_first(&mut pull_requests);
|
||||
utils::sort_oldest_first(&mut comments);
|
||||
|
||||
let maintainers = announcement
|
||||
.as_ref()
|
||||
@@ -1447,13 +1447,6 @@ impl RepoStore {
|
||||
}
|
||||
}
|
||||
|
||||
fn latest<I>(events: I) -> Option<Event>
|
||||
where
|
||||
I: IntoIterator<Item = Event>,
|
||||
{
|
||||
events.into_iter().max_by_key(|e| e.created_at)
|
||||
}
|
||||
|
||||
fn status_of(status_by_root: &HashMap<EventId, RepoStatus>, root: &Event) -> RepoStatus {
|
||||
status_by_root
|
||||
.get(&root.id)
|
||||
@@ -1492,14 +1485,6 @@ fn resolve_statuses(
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn sort_newest_first(events: &mut [Event]) {
|
||||
events.sort_by_key(|e| std::cmp::Reverse(e.created_at));
|
||||
}
|
||||
|
||||
fn sort_oldest_first(events: &mut [Event]) {
|
||||
events.sort_by_key(|e| e.created_at);
|
||||
}
|
||||
|
||||
/// The proposed commit of a `git format-patch` output.
|
||||
/// It is the `From <commit>` header on the first line.
|
||||
fn patch_current_commit(patch: &str) -> Option<&str> {
|
||||
|
||||
Reference in New Issue
Block a user