Print header information for a change diff. Displays the change hash, message, author, and timestamp before showing the actual diff content.
(
&self,
change: &Change,
change_hash: &Hash,
config: &DiffOutputConfig,
)
| 836 | /// Displays the change hash, message, author, and timestamp before |
| 837 | /// showing the actual diff content. |
| 838 | pub(super) fn print_change_header( |
| 839 | &self, |
| 840 | change: &Change, |
| 841 | change_hash: &Hash, |
| 842 | config: &DiffOutputConfig, |
| 843 | ) { |
| 844 | let header = &change.hashed.header; |
| 845 | let hash_str = change_hash.to_base32(); |
| 846 | let display_hash = hash_str[..DEFAULT_HASH_LENGTH.min(hash_str.len())].to_string(); |
| 847 | |
| 848 | // Print change identifier |
| 849 | if config.color { |
| 850 | println!("{} {}", emphasis("change"), hash(&display_hash)); |
| 851 | } else { |
| 852 | println!("change {}", display_hash); |
| 853 | } |
| 854 | |
| 855 | // Print author(s) |
| 856 | for author in header.authors.iter() { |
| 857 | let author_str = if let Some(ref email) = author.email { |
| 858 | format!("{} <{}>", author.name, email) |
| 859 | } else { |
| 860 | author.name.clone() |
| 861 | }; |
| 862 | if config.color { |
| 863 | println!("Author: {}", info(&author_str)); |
| 864 | } else { |
| 865 | println!("Author: {}", author_str); |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | // Print timestamp |
| 870 | let timestamp = header.timestamp.format("%Y-%m-%d %H:%M:%S %Z").to_string(); |
| 871 | if config.color { |
| 872 | println!("Date: {}", info(×tamp)); |
| 873 | } else { |
| 874 | println!("Date: {}", timestamp); |
| 875 | } |
| 876 | |
| 877 | // Print message |
| 878 | println!(); |
| 879 | if config.color { |
| 880 | println!(" {}", emphasis(&header.message)); |
| 881 | } else { |
| 882 | println!(" {}", header.message); |
| 883 | } |
| 884 | |
| 885 | // Print description if present |
| 886 | if let Some(ref desc) = header.description { |
| 887 | println!(); |
| 888 | for line in desc.lines() { |
| 889 | println!(" {}", line); |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | println!(); |
| 894 | } |
| 895 |