Skip to content

Commit 4081b12

Browse files
Rearange code
Split the code up into more logical related components. Move josh-filter.rs to josh-cli crate Those two make a lot of sense to be installed together. Also we're considering to use the "josh-filter" crate name to extract parts of josh-core.
1 parent 4f276d6 commit 4081b12

File tree

24 files changed

+422
-399
lines changed

24 files changed

+422
-399
lines changed

Cargo.lock

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ members = [
55
"hyper-reverse-proxy",
66
"josh-core",
77
"josh-cli",
8-
"josh-filter",
98
"josh-graphql",
109
"josh-proxy",
1110
"josh-rpc",

docs/src/reference/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ history, taking a filter specification as argument.
99

1010
It can be installed with the following Cargo command, assuming Rust is installed:
1111
```shell
12-
cargo install josh-filter --git https://github.com/josh-project/josh.git
12+
cargo install josh-cli --git https://github.com/josh-project/josh.git
1313
```
1414

1515
git-sync

josh-cli/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ toml = { workspace = true }
2626

2727
[features]
2828
incubating = []
29+
30+
[[bin]]
31+
name = "josh-filter"
32+
path = "src/bin/josh-filter.rs"
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,13 @@ fn run_filter(args: Vec<String>) -> josh_core::JoshResult<i32> {
193193
};
194194

195195
if !args.get_flag("no-cache") {
196-
josh_core::cache_sled::sled_load(&repo_path)?;
196+
josh_core::cache::sled_load(&repo_path)?;
197197
}
198198

199199
let cache = std::sync::Arc::new(
200-
josh_core::cache_stack::CacheStack::new()
201-
.with_backend(josh_core::cache_sled::SledCacheBackend::default())
202-
.with_backend(josh_core::cache_notes::NotesCacheBackend::new(&repo_path)?),
200+
josh_core::cache::CacheStack::new()
201+
.with_backend(josh_core::cache::SledCacheBackend::default())
202+
.with_backend(josh_core::cache::NotesCacheBackend::new(&repo_path)?),
203203
);
204204

205205
let mut transaction =
@@ -296,7 +296,7 @@ fn run_filter(args: Vec<String>) -> josh_core::JoshResult<i32> {
296296
rs_tracing::close_trace_file!();
297297
}
298298
if args.get_flag("cache-stats") {
299-
josh_core::cache_sled::sled_print_stats().expect("failed to collect cache stats");
299+
josh_core::cache::sled_print_stats().expect("failed to collect cache stats");
300300
}
301301
if let Some(mempack) = mp {
302302
let mut buf = git2::Buf::new();

josh-cli/src/bin/josh.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,15 @@ fn run_command(cli: &Cli) -> anyhow::Result<()> {
319319
repo.path().parent().unwrap().to_path_buf()
320320
};
321321

322-
josh_core::cache_sled::sled_load(&repo_path.join(".git"))
322+
josh_core::cache::sled_load(&repo_path.join(".git"))
323323
.map_err(from_josh_err)
324324
.context("Failed to load sled cache")?;
325325

326326
let cache = std::sync::Arc::new(
327-
josh_core::cache_stack::CacheStack::new()
328-
.with_backend(josh_core::cache_sled::SledCacheBackend::default())
327+
josh_core::cache::CacheStack::new()
328+
.with_backend(josh_core::cache::SledCacheBackend::default())
329329
.with_backend(
330-
josh_core::cache_notes::NotesCacheBackend::new(&repo_path)
330+
josh_core::cache::NotesCacheBackend::new(&repo_path)
331331
.map_err(from_josh_err)
332332
.context("Failed to create NotesCacheBackend")?,
333333
),

josh-core/src/build.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use crate::filter::op::{LazyRef, Op};
2+
use crate::filter::opt;
3+
use crate::filter::persist::to_filter;
4+
use crate::filter::{Filter, MESSAGE_MATCH_ALL_REGEX};
5+
6+
/// Create a no-op filter that passes everything through unchanged
7+
pub fn nop() -> Filter {
8+
to_filter(Op::Nop)
9+
}
10+
11+
/// Create an empty filter that matches nothing
12+
pub fn empty() -> Filter {
13+
to_filter(Op::Empty)
14+
}
15+
16+
/// Create a message filter that transforms commit messages
17+
pub fn message(m: &str) -> Filter {
18+
to_filter(Op::Message(m.to_string(), MESSAGE_MATCH_ALL_REGEX.clone()))
19+
}
20+
21+
/// Create a file filter that selects a single file
22+
pub fn file(path: impl Into<std::path::PathBuf>) -> Filter {
23+
let p = path.into();
24+
to_filter(Op::File(p.clone(), p))
25+
}
26+
27+
/// Create a hook filter
28+
pub fn hook(h: &str) -> Filter {
29+
to_filter(Op::Hook(h.to_string()))
30+
}
31+
32+
/// Create a squash filter
33+
pub fn squash(ids: Option<&[(git2::Oid, Filter)]>) -> Filter {
34+
if let Some(ids) = ids {
35+
to_filter(Op::Squash(Some(
36+
ids.iter()
37+
.map(|(x, y)| (LazyRef::Resolved(*x), *y))
38+
.collect(),
39+
)))
40+
} else {
41+
to_filter(Op::Squash(None))
42+
}
43+
}
44+
45+
/// Create a filter that is the result of feeding the output of `first` into `second`
46+
pub fn chain(first: Filter, second: Filter) -> Filter {
47+
opt::optimize(to_filter(Op::Chain(first, second)))
48+
}
49+
50+
/// Create a filter that is the result of overlaying the output of `first` onto `second`
51+
pub fn compose(first: Filter, second: Filter) -> Filter {
52+
opt::optimize(to_filter(Op::Compose(vec![first, second])))
53+
}
54+
55+
/// Create a sequence_number filter used for tracking commit sequence numbers
56+
pub fn sequence_number() -> Filter {
57+
Filter::from_oid(git2::Oid::zero())
58+
}

0 commit comments

Comments
 (0)