From d71c083a7f6519c215e99c8d1084d65b4d6fd863 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Fri, 16 Apr 2021 23:48:21 -0700 Subject: [PATCH] cli: use revsets also when looking up by description --- lib/src/dag_walk.rs | 25 -------------- src/commands.rs | 82 +++++++++++---------------------------------- 2 files changed, 19 insertions(+), 88 deletions(-) diff --git a/lib/src/dag_walk.rs b/lib/src/dag_walk.rs index 202cfa524..930aebdf3 100644 --- a/lib/src/dag_walk.rs +++ b/lib/src/dag_walk.rs @@ -17,31 +17,6 @@ use std::hash::Hash; use std::iter::Iterator; use crate::commit::Commit; -use crate::store::CommitId; - -pub struct AncestorsIter { - bfs_iter: BfsIter<'static, 'static, Commit, CommitId, Vec>, -} - -impl Iterator for AncestorsIter { - type Item = Commit; - - fn next(&mut self) -> Option { - self.bfs_iter.next() - } -} - -pub fn walk_ancestors(start: II) -> AncestorsIter -where - II: IntoIterator, -{ - let bfs_iter = bfs( - start, - Box::new(|commit| commit.id().clone()), - Box::new(|commit| commit.parents()), - ); - AncestorsIter { bfs_iter } -} pub struct BfsIter<'id_fn, 'neighbors_fn, T, ID, NI> { id_fn: Box ID + 'id_fn>, diff --git a/src/commands.rs b/src/commands.rs index 152c60390..8a4460d98 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -30,7 +30,7 @@ use clap::{crate_version, App, Arg, ArgMatches, SubCommand}; use criterion::Criterion; use jujube_lib::commit::Commit; use jujube_lib::commit_builder::CommitBuilder; -use jujube_lib::dag_walk::{topo_order_reverse, walk_ancestors}; +use jujube_lib::dag_walk::topo_order_reverse; use jujube_lib::evolution::{evolve, EvolveListener}; use jujube_lib::files::DiffLine; use jujube_lib::git::GitFetchError; @@ -42,7 +42,7 @@ use jujube_lib::repo_path::RepoPath; use jujube_lib::revset::{RevsetError, RevsetParseError}; use jujube_lib::rewrite::{back_out_commit, merge_commit_trees, rebase_commit}; use jujube_lib::settings::UserSettings; -use jujube_lib::store::{CommitId, StoreError, Timestamp, TreeValue}; +use jujube_lib::store::{StoreError, Timestamp, TreeValue}; use jujube_lib::store_wrapper::StoreWrapper; use jujube_lib::tree::Tree; use jujube_lib::trees::Diff; @@ -154,42 +154,23 @@ fn resolve_single_rev( repo = reloaded_repo; } - if revision_str.starts_with("desc(") && revision_str.ends_with(')') { - let needle = revision_str[5..revision_str.len() - 1].to_string(); - let mut matches = vec![]; - let head_ids = skip_uninteresting_heads(repo.as_ref(), &repo.view().heads()); - let heads: Vec<_> = head_ids - .iter() - .map(|id| repo.store().get_commit(&id).unwrap()) - .collect(); - for commit in walk_ancestors(heads) { - if commit.description().contains(&needle) { - matches.push(commit); - } - } - match matches.pop() { - None => Err(CommandError::UserError(String::from("No matching commit"))), - Some(commit) => Ok((repo, commit)), - } - } else { - let revset_expression = revset::parse(revision_str)?; - let revset = revset::evaluate_expression(repo.as_repo_ref(), &revset_expression)?; - let mut iter = revset.iter(); - match iter.next() { - None => Err(CommandError::UserError(format!( - "Revset \"{}\" didn't resolve to any revisions", - revision_str - ))), - Some(entry) => { - let commit = repo.store().get_commit(&entry.commit_id())?; - if iter.next().is_some() { - return Err(CommandError::UserError(format!( - "Revset \"{}\" resolved to more than one revision", - revision_str - ))); - } else { - Ok((repo.clone(), commit)) - } + let revset_expression = revset::parse(revision_str)?; + let revset = revset::evaluate_expression(repo.as_repo_ref(), &revset_expression)?; + let mut iter = revset.iter(); + match iter.next() { + None => Err(CommandError::UserError(format!( + "Revset \"{}\" didn't resolve to any revisions", + revision_str + ))), + Some(entry) => { + let commit = repo.store().get_commit(&entry.commit_id())?; + if iter.next().is_some() { + return Err(CommandError::UserError(format!( + "Revset \"{}\" resolved to more than one revision", + revision_str + ))); + } else { + Ok((repo.clone(), commit)) } } } @@ -1041,31 +1022,6 @@ fn graph_log_template(settings: &UserSettings) -> String { .unwrap_or_else(|_| String::from(default_template)) } -fn skip_uninteresting_heads(repo: &ReadonlyRepo, heads: &HashSet) -> HashSet { - let index = repo.index(); - let mut result = HashSet::new(); - let mut work: Vec<_> = heads - .iter() - .map(|id| index.entry_by_id(id).unwrap()) - .collect(); - let evolution = repo.evolution(); - while !work.is_empty() { - let index_entry = work.pop().unwrap(); - let commit_id = index_entry.commit_id(); - if result.contains(&commit_id) { - continue; - } - if !index_entry.is_pruned() && !evolution.is_obsolete(&commit_id) { - result.insert(commit_id); - } else { - for parent_entry in index_entry.parents() { - work.push(parent_entry); - } - } - } - result -} - fn cmd_log( ui: &mut Ui, matches: &ArgMatches,