Skip to content

Commit 243cbd2

Browse files
committed
Problem: the concept of "items"
It originally was a conversion of "issues" into something that can be somewhat more generic. However, with further exploration of different domains it became rather clear that it doesn't fit many of them well and can only be artifically bolted on. That's not great. Solution: transition into a flat records namespace In order to avoid this problem, the idea is to move out all records to .sit/records into a single flat namespace and make the transition (almost) seamless by retaining items for a little while but converting records in them into "text link" files to the real records.
1 parent 3d5fa17 commit 243cbd2

30 files changed

+2136
-1001
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ language: rust
22
rust:
33
- stable
44
- nightly
5+
build_script: make test
56
cache: cargo
67
matrix:
78
include:

Cargo.lock

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

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.PHONY: test
2+
13
osx: target/x86_64-apple-darwin/release/sit target/x86_64-apple-darwin/release/sit-web
24
linux: target/x86_64-unknown-linux-musl/release/sit target/x86_64-unknown-linux-musl/release/sit-web
35

@@ -12,3 +14,11 @@ target/x86_64-unknown-linux-musl/release/sit target/x86_64-unknown-linux-musl/re
1214
sed -i s/sha256://g ._docker_linux
1315
docker run -u `id -u`:`id -g` -v `pwd`:/sit -w /sit -t `cat ._docker_linux` sh -c "cargo build --release --target=x86_64-unknown-linux-musl && strip target/x86_64-unknown-linux-musl/release/sit target/x86_64-unknown-linux-musl/release/sit-web"
1416
rm -f ._docker_linux
17+
18+
test:
19+
# Test without deprecated-item-api
20+
cd sit-core && cargo test --no-default-features --features="sha-1 blake2 duktape-reducers duktape-mmap duktape-require"
21+
# Test
22+
cargo test
23+
# Test sit without deprecated-items
24+
cd sit && cargo test --no-default-features

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ install:
2424
build: false
2525

2626
test_script:
27-
- cargo test
27+
- make test
2828

2929
on_failure:
3030
- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

doc/overview.png

-4.84 KB
Loading

doc/overview.uml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
class Repository {
33
hashing_algorithm : Blake2(N) | SHA-1
44
encoding: Base32
5-
id_generator: UUIDv4
6-
version: 1
7-
}
8-
class Item {
9-
id : repository.id_generator::type
5+
version: 2
106
}
117
class Record {
128
hash : repository.hashing_algorithm::type
@@ -15,7 +11,6 @@ class File {
1511
name : String
1612
content : Binary
1713
}
18-
Repository "1" --> "many" Item: contains
19-
Item "1" --> "many" Record: contains
14+
Repository "1" --> "many" Record: contains
2015
Record "1" --> "many" File: contains
2116
@enduml

sit-core/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ data-encoding = "2.1"
1919
data-encoding-macro = "0.1"
2020
glob = "0.2"
2121
lazy_static = "1.0"
22+
itertools = "0.7"
23+
walkdir = "2"
2224
blake2 = { version = "0.7", optional = true }
2325
sha-1 = { version = "0.7", optional = true }
2426
uuid = { version = "0.5", features = ["v4"], optional = true }
@@ -37,10 +39,11 @@ cc = "1.0"
3739
include_dir = "0.1.5"
3840

3941
[features]
40-
default = ["blake2", "sha-1", "uuid", "duktape-reducers", "duktape-mmap", "duktape-require"]
42+
default = ["blake2", "sha-1", "uuid", "duktape-reducers", "duktape-mmap", "duktape-require", "deprecated-item-api"]
4143
duktape-require = []
4244
duktape-reducers = ["duktape", "cesu8"]
4345
duktape = []
4446
duktape-mmap = ["memmap"]
4547
windows7 = []
4648
git = ["git2"]
49+
deprecated-item-api = []

sit-core/src/hash.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ impl HashingAlgorithm {
112112
}
113113
}
114114

115+
/// Returns the output length of the hash
116+
pub fn len(&self) -> usize {
117+
match self {
118+
#[cfg(feature = "blake2")]
119+
&HashingAlgorithm::Blake2b { size } => size,
120+
#[cfg(feature = "sha-1")]
121+
&HashingAlgorithm::SHA1 => 20,
122+
}
123+
}
124+
115125
}
116126

117127
#[cfg(test)]

sit-core/src/item.rs

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,21 @@
22
33
use serde_json::{Map, Value};
44

5-
use super::Reducer;
6-
use record::{File, OrderedFiles};
7-
8-
#[derive(Debug, Error)]
9-
pub enum ReductionError<Err: ::std::error::Error + ::std::fmt::Debug> {
10-
ImplementationError(Err)
11-
}
5+
use record::{RecordOwningContainer, RecordContainerReduction};
126

137
/// Because of SIT's extensible nature, item can
148
/// be used to represent a wild variety of entities, such
159
/// as issue, documents, accounts, etc.
16-
pub trait Item: Sized {
17-
/// Error type used by the implementation
18-
type Error: ::std::error::Error + ::std::fmt::Debug;
19-
/// Record type used by the implementation
20-
type Record : super::Record;
21-
/// Type used to list records that can be referenced as a slice of records
22-
type Records : IntoIterator<Item=Self::Record>;
23-
/// Iterator over lists of records
24-
type RecordIter : Iterator<Item=Self::Records>;
25-
/// Issue must have an ID, ideally human-readable
10+
pub trait Item: RecordOwningContainer {
11+
/// Item must have an ID, ideally human-readable
2612
fn id(&self) -> &str;
27-
/// Iterates through the tree of records
28-
fn record_iter(&self) -> Result<Self::RecordIter, Self::Error>;
29-
/// Creates and returns a new record.
30-
///
31-
/// Will reference all dangling records as its parent, unless
32-
/// `link_parents` is set to `false`
33-
fn new_record<'f, F: File + 'f, I: Into<OrderedFiles<'f, F>>>(&self, files: I, link_parents: bool)
34-
-> Result<Self::Record, Self::Error> where F::Read: 'f;
3513
}
3614

37-
/// [`Issue`] trait extension that defines and implements default reduction algorithms
38-
///
39-
/// [`Issue`]: trait.Issue.html
40-
pub trait ItemReduction: Item {
4115

42-
/// Reduces item with a given [`Reducer`]
43-
///
44-
/// Will insert item's `id` into the initial state
45-
///
46-
/// [`Reducer`]: ../reducers/trait.Reducer.html
47-
fn reduce_with_reducer<R: Reducer<State=Map<String, Value>, Item=Self::Record>>(&self, reducer: &mut R) -> Result<Map<String, Value>, ReductionError<Self::Error>> {
48-
let records = self.record_iter()?;
49-
let mut state: Map<String, Value> = Default::default();
16+
impl<T> RecordContainerReduction for T where T: Item {
17+
fn initialize_state(&self, mut state: Map<String, Value>) -> Map<String, Value> {
5018
state.insert("id".into(), Value::String(self.id().into()));
51-
Ok(records.fold(state, |acc, recs|
52-
recs.into_iter().fold(acc, |acc, rec| reducer.reduce(acc, &rec))))
19+
state
5320
}
54-
55-
5621
}
5722

58-
impl<T> ItemReduction for T where T: Item {}
59-

sit-core/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ extern crate digest;
3838

3939
extern crate relative_path;
4040

41+
extern crate itertools;
42+
extern crate walkdir;
43+
4144
// Crates necessary for testing
4245
#[cfg(test)] #[macro_use] extern crate assert_matches;
4346
#[cfg(test)] #[macro_use] extern crate proptest;
@@ -46,9 +49,12 @@ extern crate relative_path;
4649
pub mod path;
4750
pub mod hash;
4851
pub mod encoding;
52+
#[cfg(feature = "deprecated-item-api")]
4953
pub mod id;
5054
pub mod repository;
55+
#[cfg(feature = "deprecated-item-api")]
5156
pub mod item;
57+
#[cfg(feature = "deprecated-item-api")]
5258
pub use item::Item;
5359
pub mod record;
5460
pub use record::Record;

0 commit comments

Comments
 (0)