ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: inline repo_paths_from_values()

Unlike matcher_from_values(), this function is trivial and isn't widely
used. Let's simply do .map() and .collect().

TODO comment is relocated to matcher_from_values(). I think glob and
fileset-like stuff will be added to the matcher parser, not to the
'Path -> RepoPath' function. And it's probably implemented in lib crate.
This commit is contained in:
Yuya Nishihara 2022-10-21 14:46:27 +09:00
parent 50f327768c
commit b885dc75f6
2 changed files with 16 additions and 18 deletions

View file

@ -507,25 +507,15 @@ impl WorkspaceCommandHelper {
RepoPath::parse_fs_path(&self.cwd, self.workspace_root(), input)
}
pub fn repo_paths_from_values(&self, values: &[String]) -> Result<Vec<RepoPath>, CommandError> {
if !values.is_empty() {
// TODO: Add support for globs and other formats
let mut paths = vec![];
for value in values {
let repo_path = self.parse_file_path(value)?;
paths.push(repo_path);
}
Ok(paths)
} else {
Ok(vec![])
}
}
pub fn matcher_from_values(&self, values: &[String]) -> Result<Box<dyn Matcher>, CommandError> {
let paths = self.repo_paths_from_values(values)?;
if paths.is_empty() {
if values.is_empty() {
Ok(Box::new(EverythingMatcher))
} else {
// TODO: Add support for globs and other formats
let paths = values
.iter()
.map(|v| self.parse_file_path(v))
.collect::<Result<Vec<_>, _>>()?;
Ok(Box::new(PrefixMatcher::new(&paths)))
}
}

View file

@ -3890,8 +3890,16 @@ fn cmd_sparse(ui: &mut Ui, command: &CommandHelper, args: &SparseArgs) -> Result
}
} else {
let mut workspace_command = command.workspace_helper(ui)?;
let paths_to_add = workspace_command.repo_paths_from_values(&args.add)?;
let paths_to_remove = workspace_command.repo_paths_from_values(&args.remove)?;
let paths_to_add = args
.add
.iter()
.map(|v| workspace_command.parse_file_path(v))
.collect::<Result<Vec<_>, _>>()?;
let paths_to_remove = args
.remove
.iter()
.map(|v| workspace_command.parse_file_path(v))
.collect::<Result<Vec<_>, _>>()?;
let (mut locked_wc, _wc_commit) = workspace_command.start_working_copy_mutation()?;
let mut new_patterns = HashSet::new();
if args.reset {