Are /* and ../* ignore options useful?
- Dominant language
- Rust
- Stars
- 35
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
# What do ignore "/*" and "../*" do?
https://github.com/jondot/xtaskops/blob/51f458f95716d28dc9fa4ca09cb18493f3baec8c/xtaskops/src/tasks.rs#L69-L72
**I believe they do nothing in grcov and are superfluous**.
# Here's how I arrive at that conclusion
I've added some [debug logging to grcov](https://github.com/winksaville/grcov/commit/a843d92c60d34cea7e0ff43325afa043cb098925?diff=split) and investigated how [globset works](https://github.com/winksaville/exper-globset) and AFAICT `--ignore "/*"` would would ignore files that have an absolute path that begins with a `/` and `--ignore "../*"` would ignore any explicitly relative paths that begin with `../`.
After looking at the [original code in `fn rewrite_paths`](https://github.com/mozilla/grcov/blob/87f9e9f08bd8881c8699bb977952943d0233fa22/src/path_rewriting.rs#L242-L274):
```
if let Some(p) = &source_dir {
assert!(p.is_absolute());
}
// Traverse source dir and store all paths, reversed.
let mut file_to_paths: FxHashMap> = FxHashMap::default();
if let Some(ref source_dir) = source_dir {
for entry in WalkDir::new(&source_dir)
.into_iter()
.filter_entry(|e| !is_hidden(e) && !is_symbolic_link(e))
{
let entry = entry
.unwrap_or_else(|_| panic!("Failed to open directory '{}'.", source_dir.display()));
let full_path = entry.path();
if !full_path.is_file() {
continue;
}
let path = full_path.strip_prefix(&source_dir).unwrap().to_path_buf();
if to_ignore_globset.is_match(&path) {
continue;
}
let name = entry.file_name().to_str().unwrap().to_string();
match file_to_paths.entry(name) {
hash_map::Entry::Occupied(f) => f.into_mut().push(path),
hash_map::Entry::Vacant(v) => {
v.insert(vec![path]);
}
};
}
}
```
I added some debug logging to print the [`full_path` and `path`](https://github.com/winksaville/grcov/blob/a843d92c60d34cea7e0ff43325afa043cb098925/src/path_rewriting.rs#L269-L275):
```
println!("checking full_path: {:?}", full_path);
let path = full_path.strip_prefix(&source_dir).unwrap().to_path_buf();
println!("checking stripped: {:?}", path);
if to_ignore_globset.is_match(&path) {
println!("ignoring path: {:?}", path);
continue;
}
```
And here is some output where `--ignore "xtask/*" is processed:
```
checking full_path: "/home/wink/prgs/rust/myrepos/workspace-template-with-xtask/xtask/Cargo.lock"
checking stripped: "xtask/Cargo.lock"
ignoring path: "xtask/Cargo.lock"
checking full_path: "/home/wink/prgs/rust/myrepos/workspace-template-with-xtask/xtask/Cargo.toml"
checking stripped: "xtask/Cargo.toml"
ignoring path: "xtask/Cargo.toml"
checking full_path: "/home/wink/prgs/rust/myrepos/workspace-template-with-xtask/xtask/src/main.rs"
checking stripped: "xtask/src/main.rs"
ignoring path: "xtask/src/main.rs"
```
As can be seen, `full_path` always begins with `/` and `path` never begins with `/` or `../` but instead is always
relative to `source_dir`. To me, that means that "/*" and "../*" will never match `path` and are therefore superfluous.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.