| 65 | } |
| 66 | |
| 67 | pub(super) fn render( |
| 68 | cmd: &ChangeCmd, |
| 69 | change: &Change, |
| 70 | hash: &Hash, |
| 71 | sequence: Option<u64>, |
| 72 | data: &ChangeRenderData, |
| 73 | ) -> String { |
| 74 | let hash_len = cmd.get_hash_length(); |
| 75 | let seq = sequence.map(|seq| format!(" (#{seq})")).unwrap_or_default(); |
| 76 | let mut root = Tree::new(format!( |
| 77 | "change {}{seq}", |
| 78 | format_hash_with_length(hash, hash_len) |
| 79 | )); |
| 80 | let mut metadata = Tree::new("Metadata"); |
| 81 | for author in &change.hashed.header.authors { |
| 82 | metadata.push(format!("Author: {}", format_author(author))); |
| 83 | } |
| 84 | metadata.push(format!( |
| 85 | "Date: {}", |
| 86 | format_timestamp(&change.hashed.header.timestamp) |
| 87 | )); |
| 88 | root.section(metadata); |
| 89 | root.section(text_section("Message", &change.hashed.header.message)); |
| 90 | if let Some(description) = &change.hashed.header.description { |
| 91 | root.section(text_section("Description", description)); |
| 92 | } |
| 93 | |
| 94 | let mut dependencies = Tree::new(format!( |
| 95 | "Dependencies ({})", |
| 96 | change.hashed.dependencies.len() |
| 97 | )); |
| 98 | for hash in &change.hashed.dependencies { |
| 99 | let id = format_hash_with_length(hash, hash_len); |
| 100 | let message = if cmd.show_deps { |
| 101 | format!( |
| 102 | " — {}", |
| 103 | data.dep_messages |
| 104 | .get(hash) |
| 105 | .map(String::as_str) |
| 106 | .unwrap_or("[unable to load]") |
| 107 | ) |
| 108 | } else { |
| 109 | String::new() |
| 110 | }; |
| 111 | dependencies.push(format!("{id}{message}")); |
| 112 | } |
| 113 | root.section(dependencies); |
| 114 | |
| 115 | if let Some(git) = change |
| 116 | .unhashed |
| 117 | .as_ref() |
| 118 | .and_then(|metadata| metadata.get("git")) |
| 119 | { |
| 120 | let mut section = Tree::new("Git Import"); |
| 121 | if let Some(repository) = git.get("repository").and_then(|v| v.as_str()) { |
| 122 | section.push(format!("Repository: {repository}")); |
| 123 | } |
| 124 | if let Some(sha) = git.get("sha").and_then(|v| v.as_str()) { |