cli: inline resolve_revset() to caller

There's only one caller, and the implementation is straightforward.
This commit is contained in:
Yuya Nishihara 2024-03-31 13:46:29 +09:00
parent 5d09234839
commit a5abd98076
2 changed files with 6 additions and 10 deletions

View file

@ -799,14 +799,6 @@ impl WorkspaceCommandHelper {
}
}
/// Resolve a revset any number of revisions (including 0).
pub fn resolve_revset(&self, revision_str: &str) -> Result<Vec<Commit>, CommandError> {
Ok(self
.parse_revset(revision_str)?
.evaluate_to_commits()?
.try_collect()?)
}
pub fn parse_revset(
&self,
revision_str: &str,

View file

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use itertools::Itertools as _;
use jj_lib::commit::Commit;
use jj_lib::matchers::Matcher;
use jj_lib::object_id::ObjectId;
@ -80,10 +81,13 @@ pub(crate) fn cmd_squash(
) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
let mut sources;
let mut sources: Vec<Commit>;
let destination;
if args.from.is_some() || args.into.is_some() {
sources = workspace_command.resolve_revset(args.from.as_deref().unwrap_or("@"))?;
sources = workspace_command
.parse_revset(args.from.as_deref().unwrap_or("@"))?
.evaluate_to_commits()?
.try_collect()?;
destination = workspace_command.resolve_single_rev(args.into.as_deref().unwrap_or("@"))?;
if sources.iter().any(|source| source.id() == destination.id()) {
return Err(user_error("Source and destination cannot be the same"));