formatter: don't allow rules to match labels out of order

I don't see a good reason to let e.g. "added diff" to match added text
inside a diff when we already allow "diff added" for that. Allowing
both means that we have to decide which should take precedence. With
the recent change to add labels for methods, we no longer depend on it
for the "timestamp author" case ("author timestamp" now
matches). Thanks to @yuja for noticing that dependency.
This commit is contained in:
Martin von Zweigbergk 2023-01-01 10:00:06 -08:00 committed by Martin von Zweigbergk
parent f46030e549
commit 9257cc34e5

View file

@ -155,13 +155,23 @@ impl<W> ColorFormatter<W> {
let mut best_match = (-1, "");
for (key, value) in self.colors.as_ref() {
let mut num_matching = 0;
let mut labels_iter = self.labels.iter();
let mut valid = true;
for label in key.split_whitespace() {
if !self.labels.contains(&label.to_string()) {
for required_label in key.split_whitespace() {
loop {
match labels_iter.next() {
Some(label) if label == required_label => {
num_matching += 1;
}
None => {
valid = false;
}
Some(_) => {
continue;
}
}
break;
}
num_matching += 1;
}
if !valid {
continue;