Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
28 changes: 17 additions & 11 deletions src/bin/josh-filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -318,20 +317,27 @@ fn run_filter(args: Vec<String>) -> josh::JoshResult<i32> {
}
josh::update_refs(&transaction, &mut updated_refs, "");

#[cfg(feature = "search")]
if let Some(searchstring) = args.get_one::<String>("search") {
let ifilterobj = josh::filter::chain(filterobj, josh::filter::parse(":SQUASH:INDEX")?);

let max_complexity: usize = args.get_one::<String>("max_comp").unwrap_or("6").parse()?;
let max_complexity: usize = args
.get_one::<String>("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(
Expand Down
3 changes: 0 additions & 3 deletions src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ enum Op {

RegexReplace(Vec<(regex::Regex, String)>),

#[cfg(feature = "search")]
Index,
Invert,

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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),
Expand Down
1 change: 0 additions & 1 deletion src/filter/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ fn make_op(args: &[&str]) -> JoshResult<Op> {
["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),
Expand Down
4 changes: 0 additions & 4 deletions src/filter/tree.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::*;

#[cfg(feature = "search")]
use rayon::prelude::*;

pub fn pathstree<'a>(
Expand Down Expand Up @@ -608,7 +607,6 @@ pub fn trigram_index<'a>(
Ok(result)
}

#[cfg(feature = "search")]
pub fn search_candidates(
transaction: &cache::Transaction,
tree: &git2::Tree,
Expand All @@ -627,7 +625,6 @@ pub fn search_candidates(
Ok(results)
}

#[cfg(feature = "search")]
pub fn search_matches(
transaction: &cache::Transaction,
tree: &git2::Tree,
Expand Down Expand Up @@ -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>,
Expand Down
4 changes: 0 additions & 4 deletions src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,7 @@ impl Revision {

Ok(Some(warnings))
}
}

#[cfg(feature = "search")]
#[graphql_object(context = Context)]
impl Revision {
fn search(
&self,
string: String,
Expand Down
46 changes: 44 additions & 2 deletions tests/experimental/indexer.t
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
139 changes: 139 additions & 0 deletions tests/proxy/graphql_schema.t
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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": [
Expand Down