mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-15 08:53:16 +00:00
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:
parent
f46030e549
commit
9257cc34e5
1 changed files with 14 additions and 4 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue