diff --git a/Cargo.toml b/Cargo.toml index eff5eb36b..c16e33c09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,10 +9,6 @@ keywords = ["git", "monorepo", "workflow", "scm"] readme = "README.md" edition = "2018" -[features] -search = [] -experimental = ["search"] - [workspace] members = ["josh-proxy", "josh-ui", "josh-ssh-shell", "josh-rpc", ".", "hyper_cgi"] diff --git a/src/bin/josh-filter.rs b/src/bin/josh-filter.rs index 03c514909..14b3778aa 100644 --- a/src/bin/josh-filter.rs +++ b/src/bin/josh-filter.rs @@ -11,7 +11,6 @@ use std::io::Write; fn make_app() -> clap::Command { let app = clap::Command::new("josh-filter"); - #[cfg(feature = "search")] let app = { app.arg(clap::Arg::new("search").long("search")) }; let app = app .arg( @@ -318,20 +317,27 @@ fn run_filter(args: Vec) -> josh::JoshResult { } josh::update_refs(&transaction, &mut updated_refs, ""); - #[cfg(feature = "search")] if let Some(searchstring) = args.get_one::("search") { let ifilterobj = josh::filter::chain(filterobj, josh::filter::parse(":SQUASH:INDEX")?); - let max_complexity: usize = args.get_one::("max_comp").unwrap_or("6").parse()?; + let max_complexity: usize = args + .get_one::("max_comp") + .unwrap_or(&"6".to_string()) + .parse()?; - josh::filter_ref( - &transaction, - ifilterobj, - src.clone(), - "refs/JOSH_TMP".to_string(), - )?; - let tree = repo.find_reference(&src)?.peel_to_tree()?; - let index_tree = repo.find_reference(&"refs/JOSH_TMP")?.peel_to_tree()?; + let commit = repo.find_reference(&input_ref)?.peel_to_commit()?; + + let index_commit = + josh::filter_commit(&transaction, ifilterobj, commit.id(), permissions_filter)?; + let tree = repo + .find_commit(josh::filter_commit( + &transaction, + filterobj, + commit.id(), + permissions_filter, + )?)? + .tree()?; + let index_tree = repo.find_commit(index_commit)?.tree()?; /* let start = std::time::Instant::now(); */ let candidates = josh::filter::tree::search_candidates( diff --git a/src/filter/mod.rs b/src/filter/mod.rs index 2a2eefc13..67bbe815d 100644 --- a/src/filter/mod.rs +++ b/src/filter/mod.rs @@ -104,7 +104,6 @@ enum Op { RegexReplace(Vec<(regex::Regex, String)>), - #[cfg(feature = "search")] Index, Invert, @@ -278,7 +277,6 @@ fn spec2(op: &Op) -> String { Op::Empty => ":empty".to_string(), Op::Paths => ":PATHS".to_string(), Op::Invert => ":INVERT".to_string(), - #[cfg(feature = "search")] Op::Index => ":INDEX".to_string(), Op::Fold => ":FOLD".to_string(), Op::Squash(None) => ":SQUASH".to_string(), @@ -760,7 +758,6 @@ fn apply2<'a>( } Op::Paths => tree::pathstree("", tree.id(), transaction), - #[cfg(feature = "search")] Op::Index => tree::trigram_index(transaction, tree), Op::Invert => tree::invert_paths(transaction, "", tree), diff --git a/src/filter/parse.rs b/src/filter/parse.rs index b68531cfa..ab91946ae 100644 --- a/src/filter/parse.rs +++ b/src/filter/parse.rs @@ -35,7 +35,6 @@ fn make_op(args: &[&str]) -> JoshResult { ["linear"] => Ok(Op::Linear), ["unsign"] => Ok(Op::Unsign), ["PATHS"] => Ok(Op::Paths), - #[cfg(feature = "search")] ["INDEX"] => Ok(Op::Index), ["INVERT"] => Ok(Op::Invert), ["FOLD"] => Ok(Op::Fold), diff --git a/src/filter/tree.rs b/src/filter/tree.rs index 50ce8b2c8..ee52939a9 100644 --- a/src/filter/tree.rs +++ b/src/filter/tree.rs @@ -1,6 +1,5 @@ use super::*; -#[cfg(feature = "search")] use rayon::prelude::*; pub fn pathstree<'a>( @@ -608,7 +607,6 @@ pub fn trigram_index<'a>( Ok(result) } -#[cfg(feature = "search")] pub fn search_candidates( transaction: &cache::Transaction, tree: &git2::Tree, @@ -627,7 +625,6 @@ pub fn search_candidates( Ok(results) } -#[cfg(feature = "search")] pub fn search_matches( transaction: &cache::Transaction, tree: &git2::Tree, @@ -655,7 +652,6 @@ pub fn search_matches( Ok(results) } -#[cfg(feature = "search")] pub fn trigram_search<'a>( transaction: &'a cache::Transaction, tree: git2::Tree<'a>, diff --git a/src/graphql.rs b/src/graphql.rs index f312c69cb..06c41721e 100644 --- a/src/graphql.rs +++ b/src/graphql.rs @@ -418,11 +418,7 @@ impl Revision { Ok(Some(warnings)) } -} -#[cfg(feature = "search")] -#[graphql_object(context = Context)] -impl Revision { fn search( &self, string: String, diff --git a/tests/experimental/indexer.t b/tests/experimental/indexer.t index 16ae82454..edc23689f 100644 --- a/tests/experimental/indexer.t +++ b/tests/experimental/indexer.t @@ -1,7 +1,7 @@ $ export TESTTMP=${PWD} $ cd ${TESTTMP} - $ git init testrepo 1> /dev/null + $ git init -q testrepo 1> /dev/null $ cd testrepo $ mkdir sub1 @@ -41,7 +41,49 @@ sub1/file2:3: one line $ josh-filter :/ -g 'query { rev(at: "refs/heads/master") { results: search(string: "e") { path { path }, matches { line, text }} }}' - {"rev":{"results":[{"path":{"path":"sub1/file1"},"matches":[{"line":1,"text":"First Test document"}]},{"path":{"path":"sub1/file2"},"matches":[{"line":1,"text":"Another document with more "},{"line":3,"text":" one line"}]},{"path":{"path":"sub2/file3"},"matches":[{"line":1,"text":"One more to see what happens"}]}]}} + { + "rev": { + "results": [ + { + "path": { + "path": "sub1/file1" + }, + "matches": [ + { + "line": 1, + "text": "First Test document" + } + ] + }, + { + "path": { + "path": "sub1/file2" + }, + "matches": [ + { + "line": 1, + "text": "Another document with more " + }, + { + "line": 3, + "text": " one line" + } + ] + }, + { + "path": { + "path": "sub2/file3" + }, + "matches": [ + { + "line": 1, + "text": "One more to see what happens" + } + ] + } + ] + } + } $ git diff ${EMPTY_TREE}..refs/heads/index diff --git a/SUB1 b/SUB1 diff --git a/tests/proxy/graphql_schema.t b/tests/proxy/graphql_schema.t index b37b2f0b4..8ad4311f9 100644 --- a/tests/proxy/graphql_schema.t +++ b/tests/proxy/graphql_schema.t @@ -664,6 +664,51 @@ } } } + }, + { + "args": [ + { + "defaultValue": null, + "description": null, + "name": "string", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + } + }, + { + "defaultValue": null, + "description": null, + "name": "maxComplexity", + "type": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + } + } + ], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "search", + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "SearchResult", + "ofType": null + } + } + } } ], "inputFields": null, @@ -1714,6 +1759,100 @@ "name": "__EnumValue", "possibleTypes": null }, + { + "description": null, + "enumValues": null, + "fields": [ + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "path", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "Path", + "ofType": null + } + } + }, + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "matches", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "SearchMatch", + "ofType": null + } + } + } + } + } + ], + "inputFields": null, + "interfaces": [], + "kind": "OBJECT", + "name": "SearchResult", + "possibleTypes": null + }, + { + "description": null, + "enumValues": null, + "fields": [ + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "line", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + } + } + }, + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "text", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + } + } + ], + "inputFields": null, + "interfaces": [], + "kind": "OBJECT", + "name": "SearchMatch", + "possibleTypes": null + }, { "description": null, "enumValues": [