| |
}
|
| |
|
| |
/// Given a graph evaluate it to produce a collaborative object. This will
|
| - |
/// filter out branches of the graph which do not have valid signatures,
|
| - |
/// or which do not have permission to make a change, or which make a
|
| - |
/// change which invalidates the schema of the object
|
| + |
/// filter out branches of the graph which do not have valid signatures.
|
| |
pub(crate) fn evaluate(&self) -> CollaborativeObject {
|
| |
let mut roots: Vec<(&Oid, &Node<_, _>)> = self.graph.roots().collect();
|
| |
roots.sort_by_key(|(k, _)| *k);
|
| |
let (root, root_node) = roots.first().unwrap();
|
| |
let manifest = root_node.manifest.clone();
|
| |
let rng = fastrand::Rng::new();
|
| - |
let sorted = self.graph.sorted(rng);
|
| - |
let items = sorted.iter().map(|oid| {
|
| - |
let node = &self.graph[oid];
|
| + |
let items = self.graph.sorted(rng).into_iter().map(|oid| {
|
| + |
let node = &self.graph[&oid];
|
| |
let child_commits = node
|
| |
.dependents
|
| |
.iter()
|
| |
.map(|e| *self.graph[e].id())
|
| |
.collect::<Vec<_>>();
|
| |
|
| - |
(&node.value, *oid, child_commits)
|
| + |
(&node.value, oid, child_commits)
|
| |
});
|
| |
let history = {
|
| |
let root_change = &self.graph[*root];
|
| |
evaluate(*root_change.id(), &self.graph, items)
|
| |
};
|
| + |
|
| |
CollaborativeObject {
|
| |
manifest,
|
| |
history,
|
| |
) -> impl Iterator<Item = (object::Commit, Oid)> + '_ {
|
| |
let resource_commit = *change.resource();
|
| |
let commit_id = commit.id;
|
| - |
if let Entry::Vacant(e) = self.node_indices.entry(commit_id) {
|
| - |
self.graph.node(commit_id, change);
|
| - |
e.insert(commit_id);
|
| - |
}
|
| + |
|
| + |
self.graph.node(commit_id, change);
|
| + |
|
| |
commit.parents.into_iter().filter_map(move |parent| {
|
| - |
if parent.id != resource_commit && !self.has_dependency(commit_id, parent.id) {
|
| + |
if parent.id != resource_commit && !self.graph.has_dependency(&commit_id, &parent.id) {
|
| |
Some((parent, commit_id))
|
| |
} else {
|
| |
None
|
| |
})
|
| |
}
|
| |
|
| - |
fn has_dependency(&mut self, child_id: Oid, parent_id: Oid) -> bool {
|
| - |
let parent_ix = self.node_indices.get(&parent_id);
|
| - |
let child_ix = self.node_indices.get(&child_id);
|
| - |
match (parent_ix, child_ix) {
|
| - |
(Some(parent_ix), Some(child_ix)) => self.graph.has_dependency(child_ix, parent_ix),
|
| - |
_ => false,
|
| - |
}
|
| - |
}
|
| - |
|
| |
fn add_edge(&mut self, child: Oid, parent: Oid) {
|
| - |
// This panics if the child or parent ids are not in the graph already
|
| - |
let child_id = self
|
| - |
.node_indices
|
| - |
.get(&child)
|
| - |
.expect("BUG: child id expected to be in graph");
|
| - |
let parent_id = self
|
| - |
.node_indices
|
| - |
.get(&parent)
|
| - |
.expect("BUG: parent id expected to in graph");
|
| - |
self.graph.dependency(*child_id, *parent_id);
|
| + |
self.graph.dependency(child, parent);
|
| |
}
|
| |
|
| |
fn build(self, object_id: ObjectId) -> Option<ChangeGraph> {
|