Skip to content

Commit

Permalink
sparse: include rule itself in rule origin
Browse files Browse the repository at this point in the history
Summary:
Previously the rule origin contained only the breadcrumb of the sparse profile trail leading to the rule. Now the origin also contains the leaf rule itself.

This makes it easier to support the debugsparseexplainmatch output when using the Rust sparse library (later in stack).

Reviewed By: quark-zju

Differential Revision: D49928286

fbshipit-source-id: 91956990315598a1ad2079e91e78eadcb3e568d3
  • Loading branch information
muirdm authored and facebook-github-bot committed Oct 5, 2023
1 parent 8a04e01 commit 82d1faa
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions eden/scm/lib/sparse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ impl Root {
}
Ok(rules) => {
for expanded_rule in rules {
origins.push(format!("{} ({})", expanded_rule, src));
matcher_rules.push(expanded_rule);
origins.push(src.clone());
}
}
}
Expand Down Expand Up @@ -213,13 +213,13 @@ impl Root {
&& (rules.is_empty() || matches!(&rules[0].0, Pattern::Exclude(_)))
&& !self.skip_catch_all
{
rules.push_front((Pattern::Include("**".to_string()), "(builtin)".to_string()))
rules.push_front((Pattern::Include("**".to_string()), "<builtin>".to_string()))
}

// This is for files such as .hgignore and .hgsparse-base, unrelated to the .hg directory.
rules.push_front((
Pattern::Include("glob:.hg*".to_string()),
"(builtin)".to_string(),
"<builtin>".to_string(),
));

let (matcher_rules, origins) = prepare_rules(rules)?;
Expand Down Expand Up @@ -992,7 +992,7 @@ re:^bar/bad/(?:.*/)?IMPORTANT.ext(?:/|$)

assert_eq!(
matcher.explain("a/b".try_into().unwrap()).unwrap(),
(true, "(builtin)".to_string())
(true, "**/** (<builtin>)".to_string())
);
}

Expand Down Expand Up @@ -1036,12 +1036,12 @@ path:d

assert_eq!(
matcher.explain("b".try_into().unwrap()).unwrap(),
(true, "base -> child_1 -> child_2".to_string())
(true, "b/** (base -> child_1 -> child_2)".to_string())
);

assert_eq!(
matcher.explain("d".try_into().unwrap()).unwrap(),
(false, "base -> child_1 -> child_2".to_string())
(false, "!d/** (base -> child_1 -> child_2)".to_string())
);
}

Expand All @@ -1064,22 +1064,22 @@ four

assert_eq!(
matcher.explain("one".try_into().unwrap()).unwrap(),
(true, "base".to_string())
(true, "one/** (base)".to_string())
);

assert_eq!(
matcher.explain("two".try_into().unwrap()).unwrap(),
(true, "base (banana)".to_string())
(true, "two/** (base (banana))".to_string())
);

assert_eq!(
matcher.explain("three".try_into().unwrap()).unwrap(),
(true, "base (banana)".to_string())
(true, "three/** (base (banana))".to_string())
);

assert_eq!(
matcher.explain("four".try_into().unwrap()).unwrap(),
(true, "base".to_string())
(true, "four/** (base)".to_string())
);
}

Expand Down

0 comments on commit 82d1faa

Please sign in to comment.