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,
)
| 774 | /// Displays the change hash, message, author, and timestamp before |
| 775 | /// showing the actual diff content. |
| 776 | pub(super) fn print_change_header( |
| 777 | &self, |
| 778 | change: &Change, |
| 779 | change_hash: &Hash, |
| 780 | config: &DiffOutputConfig, |
| 781 | ) { |
| 782 | let header = &change.hashed.header; |
| 783 | let hash_str = change_hash.to_base32(); |
| 784 | let display_hash = hash_str[..DEFAULT_HASH_LENGTH.min(hash_str.len())].to_string(); |
| 785 | |
| 786 | // Print change identifier |
| 787 | if config.color { |
| 788 | println!("{} {}", emphasis("change"), hash(&display_hash)); |
| 789 | } else { |
| 790 | println!("change {}", display_hash); |
| 791 | } |
| 792 | |
| 793 | // Print author(s) |
| 794 | for author in header.authors.iter() { |
| 795 | let author_str = if let Some(ref email) = author.email { |
| 796 | format!("{} <{}>", author.name, email) |
| 797 | } else { |
| 798 | author.name.clone() |
| 799 | }; |
| 800 | if config.color { |
| 801 | println!("Author: {}", info(&author_str)); |
| 802 | } else { |
| 803 | println!("Author: {}", author_str); |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | // Print timestamp |
| 808 | let timestamp = header.timestamp.format("%Y-%m-%d %H:%M:%S %Z").to_string(); |
| 809 | if config.color { |
| 810 | println!("Date: {}", info(×tamp)); |
| 811 | } else { |
| 812 | println!("Date: {}", timestamp); |
| 813 | } |
| 814 | |
| 815 | // Print message |
| 816 | println!(); |
| 817 | if config.color { |
| 818 | println!(" {}", emphasis(&header.message)); |
| 819 | } else { |
| 820 | println!(" {}", header.message); |
| 821 | } |
| 822 | |
| 823 | // Print description if present |
| 824 | if let Some(ref desc) = header.description { |
| 825 | println!(); |
| 826 | for line in desc.lines() { |
| 827 | println!(" {}", line); |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | println!(); |
| 832 | } |
| 833 |