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
3 changes: 3 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
- name: Test parser and schema
run: cargo test -p alternator -p schema

- name: Test walker history
run: cargo test -p walker --test history

generator:
name: DocGen

Expand Down
7 changes: 5 additions & 2 deletions chumbucket/src/accessors/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ use super::Chronicle;
pub struct Git<'g>(DiffList<'g>);

impl<'g> Git<'g> {
pub fn from_walker(from: Option<i64>, walker: &'g mut Walker) -> Result<Self> {
Ok(Self(walker.walk(from)?))
pub fn from_walker(since: Option<&Versioning>, walker: &'g mut Walker) -> Result<Self> {
Ok(Self(walker.walk(
since.map(|v| v.hash.as_str()),
since.map(|v| v.time),
)?))
}
}

Expand Down
85 changes: 40 additions & 45 deletions chumbucket/src/commands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ pub async fn generate_command(matches: &ArgMatches) -> Result<()> {

let manifest: Manifest = toml::from_slice(&fs_content)?;
let mut bundle: Option<Bundle> = None;
let mut from_time: Option<i64> = None;
let mut since: Option<Versioning> = None;

if matches.is_present("bundle") {
let bundle_str = std::fs::read(matches.value_of("bundle").unwrap())?;

let parsed_bundle: Bundle = serde_json::from_slice(&bundle_str)?;

if let Some(version) = &parsed_bundle.version {
from_time = Some(version.time);
}
since = parsed_bundle.version.clone();

bundle = Some(parsed_bundle);
}
Expand All @@ -64,7 +62,7 @@ pub async fn generate_command(matches: &ArgMatches) -> Result<()> {
)?;

let latest_file_names = walker.latest_file_names()?;
let git = Git::from_walker(from_time, &mut walker)?;
let git = Git::from_walker(since.as_ref(), &mut walker)?;

let it_ret = iterate_chronicles(git, manifest, bundle, latest_file_names).await?;

Expand Down Expand Up @@ -313,52 +311,49 @@ impl<'b> ChronicleProcessor<'b> {
new: &HashMap<String, T>,
version: Option<Versioning>,
) -> u64 {
// Handle any new entries
for (k, v) in new {
if let Entry::Vacant(entry) = existing.entry(k.clone()) {
entry.insert(v.clone());
}
}

let mut to_remove = Vec::new();

// Handle any deleted entries
for (k, _) in existing.iter() {
if !new.contains_key(k) {
to_remove.push(k.clone());
}
}

for k in to_remove {
existing.remove(&k);
}

let mut diff = 0;

// At this point, both list should have the same keys, so we can safely iterate over them
// Handle any updated entries
for (k, v) in existing.iter_mut() {
let dp_v = new.get(k).unwrap();

let is_diff = v != dp_v;

if is_diff {
*v <<= dp_v.clone();
diff += 1;
}

// Update the metadata
match v.metadata() {
Some(m) if is_diff => {
m.last_updated = version.clone();
}
None if !is_diff => {
*v.metadata() = Some(Metadata {
// Handle any deleted entries
let before = existing.len();
existing.retain(|k, _| new.contains_key(k));
diff += (before - existing.len()) as u64;

for (k, dp_v) in new {
match existing.entry(k.clone()) {
// Newly added entry, created at this version
Entry::Vacant(entry) => {
*entry.insert(dp_v.clone()).metadata() = Some(Metadata {
last_updated: version.clone(),
created: version.clone(),
});
diff += 1;
}
// Existing entry, only its last updated version changes
Entry::Occupied(mut entry) => {
let v = entry.get_mut();

let is_diff = v != dp_v;

if is_diff {
*v <<= dp_v.clone();
diff += 1;
}

match v.metadata() {
Some(m) => {
if is_diff {
m.last_updated = version.clone();
}
}
// Entry without metadata (e.g. nested in a newly added parent)
m @ None => {
*m = Some(Metadata {
last_updated: version.clone(),
created: version.clone(),
});
}
}
}
_ => {}
}
}

Expand Down
3 changes: 1 addition & 2 deletions libschema/src/symbol/enum_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ impl Metable for EnumStruct {
impl ShlAssign for EnumStruct {
fn shl_assign(&mut self, rhs: Self) {
self.declaration <<= rhs.declaration;
self.methods = rhs.methods;
self.fields = rhs.fields;
// Methods and fields are merged individually to preserve their metadata
}
}

Expand Down
2 changes: 1 addition & 1 deletion libschema/src/symbol/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Metable for Enumeration {
impl ShlAssign for Enumeration {
fn shl_assign(&mut self, rhs: Self) {
self.declaration <<= rhs.declaration;
self.entries = rhs.entries;
// Entries are merged individually to preserve their metadata
}
}

Expand Down
3 changes: 1 addition & 2 deletions libschema/src/symbol/method_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl ShlAssign for MethodMap {
fn shl_assign(&mut self, rhs: Self) {
self.declaration <<= rhs.declaration;
self.parent = rhs.parent;
self.methods = rhs.methods;
self.properties = rhs.properties;
// Methods and properties are merged individually to preserve their metadata
}
}

Expand Down
2 changes: 1 addition & 1 deletion libschema/src/symbol/type_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Metable for TypeSet {
impl ShlAssign for TypeSet {
fn shl_assign(&mut self, rhs: Self) {
self.declaration <<= rhs.declaration;
self.types = rhs.types;
// Types are merged individually to preserve their metadata
}
}

Expand Down
3 changes: 3 additions & 0 deletions libwalker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ edition = "2021"
[dependencies]
git2 = "0.13"
thiserror = "1"

[dev-dependencies]
git2 = "0.13"
Loading
Loading