| 420 | } |
| 421 | |
| 422 | fn format_service_compact_log( |
| 423 | entries: &[pb::ChangeLogEntry], |
| 424 | args: &crate::commands::log::command::Log, |
| 425 | ) -> String { |
| 426 | use crate::commands::log::truncate_string; |
| 427 | use crate::commands::log::types::LogFormat; |
| 428 | use crate::output::{ |
| 429 | author as style_author, hash as style_hash, hint, timestamp as style_timestamp, |
| 430 | }; |
| 431 | let oneline = matches!(args.effective_format(), LogFormat::Oneline); |
| 432 | let width = entries |
| 433 | .iter() |
| 434 | .filter_map(|entry| entry.authors.first()) |
| 435 | .map(|author| author.name.len()) |
| 436 | .max() |
| 437 | .unwrap_or(10) |
| 438 | .min(20); |
| 439 | let mut output = String::new(); |
| 440 | for entry in entries { |
| 441 | let full = wire_hash_base32(&entry.hash); |
| 442 | let hash = full |
| 443 | .get(..args.get_hash_length().min(full.len())) |
| 444 | .unwrap_or(&full); |
| 445 | let message = entry.message.as_deref().unwrap_or("(no message)"); |
| 446 | let first_line = message.lines().next().unwrap_or(message); |
| 447 | if oneline { |
| 448 | let date = entry |
| 449 | .recorded_at |
| 450 | .as_ref() |
| 451 | .and_then(|ts| chrono::DateTime::from_timestamp(ts.seconds, ts.nanos.max(0) as u32)) |
| 452 | .map(|date| date.format("%Y-%m-%d").to_string()) |
| 453 | .unwrap_or_else(|| " ".into()); |
| 454 | let author = entry |
| 455 | .authors |
| 456 | .first() |
| 457 | .map(|author| truncate_string(&author.name, width)) |
| 458 | .unwrap_or_else(|| "(unknown)".into()); |
| 459 | let marker = if entry.is_tagged { "*" } else { " " }; |
| 460 | output.push_str(&format!( |
| 461 | "{}{} {} {:width$} {}\n", |
| 462 | style_hash(hash), |
| 463 | hint(marker), |
| 464 | style_timestamp(&date), |
| 465 | style_author(&author), |
| 466 | first_line |
| 467 | )); |
| 468 | } else { |
| 469 | let marker = if entry.is_tagged { " *" } else { "" }; |
| 470 | output.push_str(&format!( |
| 471 | "{}{} {}\n", |
| 472 | style_hash(hash), |
| 473 | hint(marker), |
| 474 | first_line |
| 475 | )); |
| 476 | } |
| 477 | } |
| 478 | output |
| 479 | } |