Mercurial > public > mercurial-scm > hg
diff rust/rhg/src/commands/annotate.rs @ 52969:874c64e041b5
rhg-annotate: support whitespace options
This adds support to rhg annotate for all the whitespace options:
-w, --ignore-all-space
-b, --ignore-space-change
-B, --ignore-blank-lines
-Z, --ignore-space-at-eol
Note that --ignore-blank-lines has no effect on annotate so it is ignored. You
can see this in dagop.py _annotepair which only checks if blocks are '=' or not,
whereas the effect of --ignore-blank-lines is to change some '!' into '~'.
When the other 3 are combined, we use the strongest option since -w implies -b
and -b implies -Z. This is not explicit in the Python implementation, but I have
verified that's how it behaves.
author | Mitchell Kember <mkember@janestreet.com> |
---|---|
date | Fri, 07 Feb 2025 17:42:43 -0500 |
parents | 6183949219b2 |
children |
line wrap: on
line diff
--- a/rust/rhg/src/commands/annotate.rs Wed Feb 12 11:37:07 2025 -0500 +++ b/rust/rhg/src/commands/annotate.rs Fri Feb 07 17:42:43 2025 -0500 @@ -8,6 +8,7 @@ annotate, AnnotateOptions, AnnotateOutput, ChangesetAnnotation, }, revlog::changelog::Changelog, + utils::strings::CleanWhitespace, FastHashMap, Revision, }; @@ -106,6 +107,34 @@ .action(clap::ArgAction::SetTrue) .conflicts_with("quiet"), ) + .arg( + clap::Arg::new("ignore-all-space") + .help("ignore white space when comparing lines") + .short('w') + .long("ignore-all-space") + .action(clap::ArgAction::SetTrue), + ) + .arg( + clap::Arg::new("ignore-space-change") + .help("ignore changes in the amount of white space") + .short('b') + .long("ignore-space-change") + .action(clap::ArgAction::SetTrue), + ) + .arg( + clap::Arg::new("ignore-blank-lines") + .help("ignore changes whose lines are all blank") + .short('B') + .long("ignore-blank-lines") + .action(clap::ArgAction::SetTrue), + ) + .arg( + clap::Arg::new("ignore-space-at-eol") + .help("ignore changes in whitespace at EOL") + .short('Z') + .long("ignore-space-at-eol") + .action(clap::ArgAction::SetTrue), + ) .about(HELP_TEXT) } @@ -131,6 +160,17 @@ let options = AnnotateOptions { treat_binary_as_text: args.get_flag("text"), follow_copies: !args.get_flag("no-follow"), + whitespace: if args.get_flag("ignore-all-space") { + CleanWhitespace::All + } else if args.get_flag("ignore-space-change") { + CleanWhitespace::Collapse + } else if args.get_flag("ignore-space-at-eol") { + CleanWhitespace::AtEol + } else { + // We ignore the --ignore-blank-lines flag (present for consistency + // with other commands) since it has no effect on annotate. + CleanWhitespace::None + }, }; let mut include = Include {