Skip to content

Commit

Permalink
cli: inline resolve_revset() to caller
Browse files Browse the repository at this point in the history
There's only one caller, and the implementation is straightforward.
  • Loading branch information
yuja committed Apr 2, 2024
1 parent 5d09234 commit a5abd98
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 0 additions & 8 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions cli/src/commands/squash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down

0 comments on commit a5abd98

Please sign in to comment.