mirror of
https://github.com/martinvonz/jj.git
synced 2024-11-11 13:46:02 +03:00
revset: move revset_for_commits()
to test
The function is only used in tests, so it doesn't belong in `default_revset_engine`. Also, it's not specific to that implementation, so I rewrote as a revset evaluation.
This commit is contained in:
parent
2a87e1f95a
commit
d3cf543abc
@ -19,7 +19,6 @@ use std::iter::Peekable;
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::backend::CommitId;
|
||||
use crate::commit::Commit;
|
||||
use crate::default_index_store::IndexEntry;
|
||||
use crate::default_revset_graph_iterator::RevsetGraphIterator;
|
||||
use crate::matchers::{EverythingMatcher, Matcher, PrefixMatcher};
|
||||
@ -614,19 +613,6 @@ fn revset_for_commit_ids<'index>(
|
||||
RevsetImpl::new(Box::new(EagerRevset { index_entries }))
|
||||
}
|
||||
|
||||
pub fn revset_for_commits<'index>(
|
||||
repo: &'index dyn Repo,
|
||||
commits: &[&Commit],
|
||||
) -> Box<dyn Revset<'index> + 'index> {
|
||||
let index = repo.index();
|
||||
let mut index_entries = commits
|
||||
.iter()
|
||||
.map(|commit| index.entry_by_id(commit.id()).unwrap())
|
||||
.collect_vec();
|
||||
index_entries.sort_by_key(|b| Reverse(b.position()));
|
||||
Box::new(RevsetImpl::new(Box::new(EagerRevset { index_entries })))
|
||||
}
|
||||
|
||||
type PurePredicateFn<'index> = Box<dyn Fn(&IndexEntry<'index>) -> bool + 'index>;
|
||||
|
||||
impl<'index> ToPredicateFn<'index> for PurePredicateFn<'index> {
|
||||
|
@ -14,13 +14,21 @@
|
||||
|
||||
use itertools::Itertools;
|
||||
use jujutsu_lib::commit::Commit;
|
||||
use jujutsu_lib::default_revset_engine::revset_for_commits;
|
||||
use jujutsu_lib::default_revset_graph_iterator::RevsetGraphIterator;
|
||||
use jujutsu_lib::repo::Repo;
|
||||
use jujutsu_lib::revset::RevsetGraphEdge;
|
||||
use jujutsu_lib::revset::{Revset, RevsetExpression, RevsetGraphEdge};
|
||||
use test_case::test_case;
|
||||
use testutils::{CommitGraphBuilder, TestRepo};
|
||||
|
||||
fn revset_for_commits<'index>(
|
||||
repo: &'index dyn Repo,
|
||||
commits: &[&Commit],
|
||||
) -> Box<dyn Revset<'index> + 'index> {
|
||||
RevsetExpression::commits(commits.iter().map(|commit| commit.id().clone()).collect())
|
||||
.evaluate(repo)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn direct(commit: &Commit) -> RevsetGraphEdge {
|
||||
RevsetGraphEdge::direct(commit.id().clone())
|
||||
}
|
||||
|
@ -17,15 +17,15 @@ use std::path::Path;
|
||||
use assert_matches::assert_matches;
|
||||
use itertools::Itertools;
|
||||
use jujutsu_lib::backend::{CommitId, MillisSinceEpoch, ObjectId, Signature, Timestamp};
|
||||
use jujutsu_lib::default_revset_engine::revset_for_commits;
|
||||
use jujutsu_lib::commit::Commit;
|
||||
use jujutsu_lib::git;
|
||||
use jujutsu_lib::op_store::{RefTarget, WorkspaceId};
|
||||
use jujutsu_lib::repo::Repo;
|
||||
use jujutsu_lib::repo_path::RepoPath;
|
||||
use jujutsu_lib::revset::{
|
||||
optimize, parse, resolve_symbol, resolve_symbols, ReverseRevsetGraphIterator, RevsetAliasesMap,
|
||||
RevsetError, RevsetExpression, RevsetFilterPredicate, RevsetGraphEdge, RevsetIteratorExt,
|
||||
RevsetWorkspaceContext,
|
||||
optimize, parse, resolve_symbol, resolve_symbols, ReverseRevsetGraphIterator, Revset,
|
||||
RevsetAliasesMap, RevsetError, RevsetExpression, RevsetFilterPredicate, RevsetGraphEdge,
|
||||
RevsetIteratorExt, RevsetWorkspaceContext,
|
||||
};
|
||||
use jujutsu_lib::settings::GitSettings;
|
||||
use jujutsu_lib::workspace::Workspace;
|
||||
@ -34,6 +34,14 @@ use testutils::{
|
||||
create_random_commit, write_random_commit, CommitGraphBuilder, TestRepo, TestWorkspace,
|
||||
};
|
||||
|
||||
fn revset_for_commits<'index>(
|
||||
repo: &'index dyn Repo,
|
||||
commits: &[&Commit],
|
||||
) -> Box<dyn Revset<'index> + 'index> {
|
||||
RevsetExpression::commits(commits.iter().map(|commit| commit.id().clone()).collect())
|
||||
.evaluate(repo)
|
||||
.unwrap()
|
||||
}
|
||||
#[test_case(false ; "local backend")]
|
||||
#[test_case(true ; "git backend")]
|
||||
fn test_resolve_symbol_root(use_git: bool) {
|
||||
|
Loading…
Reference in New Issue
Block a user