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
22 changes: 22 additions & 0 deletions apps/origin-src/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,28 @@ impl Index {
Ok((index, tail != Tail::Damaged))
}

/// Adds the records among `objects`, which this process just wrote, so this
/// index knows them without being read again.
///
/// # Errors
///
/// Fails if a record doesn't decode.
pub(crate) fn add<'o>(
&mut self,
objects: impl IntoIterator<Item = &'o EncodedObject>,
) -> Result<(), StoreError> {
for object in objects {
let entry = Entry::of(object).map_err(|source| StoreError::Decode {
id: object.id(),
source,
})?;
if let Some(entry) = entry {
self.insert(entry);
}
}
Ok(())
}

/// Adds a record, unless it's already indexed.
fn insert(&mut self, entry: Entry) {
if !self.known.insert(entry.record()) {
Expand Down
42 changes: 22 additions & 20 deletions apps/origin-src/src/workspace/annotate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ impl WorkingCopy {
/// unique prefix of its id, a change for its head, or a revision. A
/// prefix naming a change and another revision than its head is
/// ambiguous.
fn find_revision(&self, index: &Index, rev: &str) -> Result<RevisionId, WorkspaceError> {
fn find_revision(&self, rev: &str) -> Result<RevisionId, WorkspaceError> {
if rev == "@" {
return Ok(self.id);
}
let index = &self.index;
match (index.find_change(rev), index.find_revision(rev)) {
(Err(FindError::NotFound(_)), revision) => Ok(revision?),
(Ok(change), Err(FindError::NotFound(_))) => Workspace::single_head(index, change),
Expand All @@ -44,14 +45,10 @@ impl WorkingCopy {

/// The record `annotated` names, as [`WorkingCopy::find_revision`]
/// finds a revision, or a statement by a unique prefix of its id.
fn find_record(
&self,
index: &Index,
annotated: Annotated<'_>,
) -> Result<RecordId, WorkspaceError> {
fn find_record(&self, annotated: Annotated<'_>) -> Result<RecordId, WorkspaceError> {
Ok(match annotated {
Annotated::Revision(rev) => RecordId::Revision(self.find_revision(index, rev)?),
Annotated::Statement(prefix) => RecordId::Statement(index.find_statement(prefix)?),
Annotated::Revision(rev) => RecordId::Revision(self.find_revision(rev)?),
Annotated::Statement(prefix) => RecordId::Statement(self.index.find_statement(prefix)?),
})
}
}
Expand Down Expand Up @@ -99,16 +96,21 @@ impl Workspace {
Principal::Node(self.config.node().clone())
}

/// Issues `core.divergent` if `revision`, just saved, made its change
/// diverge. The statement is the same for the same heads, so checking
/// again writes nothing.
pub(super) fn flag_divergence(&self, revision: RevisionId) -> Result<(), WorkspaceError> {
/// Issues a `core.divergent` statement if saving `revision` made its change
/// diverge, as `index`, which has `revision`, shows. The statement is the same
/// for the same heads, so calling this again writes nothing.
pub(super) fn flag_divergence(
&self,
index: &Index,
revision: RevisionId,
) -> Result<(), WorkspaceError> {
let revision: Revision = self.store.get(revision)?;
// A new change has a single revision.
if revision.predecessors.is_empty() {
if revision.predecessors.is_empty() || !index.is_divergent(revision.change) {
return Ok(());
}
Annotations::open(&self.store)?.flag_divergence(revision.change, self.node_principal())?;
Annotations::new(&self.store, index.clone())
.flag_divergence(revision.change, self.node_principal())?;
Ok(())
}

Expand All @@ -135,8 +137,8 @@ impl Workspace {
return Err(WorkspaceError::ReservedKind(kind));
}
let working_copy = self.refresh()?;
let mut annotations = Annotations::open(&self.store)?;
let subject = working_copy.find_record(annotations.index(), annotated)?;
let subject = working_copy.find_record(annotated)?;
let mut annotations = Annotations::new(&self.store, working_copy.index);
let payload = payload.map(Payload::blob).transpose()?;
let statement = Statement {
subject,
Expand Down Expand Up @@ -232,8 +234,8 @@ impl Workspace {
/// Fails if the revision cannot be found or a record cannot be read.
pub fn statements(&mut self, rev: &str) -> Result<(), WorkspaceError> {
let working_copy = self.snapshot()?;
let annotations = Annotations::open(&self.store)?;
let revision = working_copy.find_revision(annotations.index(), rev)?;
let revision = working_copy.find_revision(rev)?;
let annotations = Annotations::new(&self.store, working_copy.index);
let subject = RecordId::Revision(revision);
if annotations.index().statements(subject).is_empty() {
println!("No statements about revision {}", revision.short());
Expand Down Expand Up @@ -326,8 +328,8 @@ impl Workspace {
/// written.
pub fn promote(&mut self, rev: &str) -> Result<(), WorkspaceError> {
let working_copy = self.refresh()?;
let mut annotations = Annotations::open(&self.store)?;
let revision = working_copy.find_revision(annotations.index(), rev)?;
let revision = working_copy.find_revision(rev)?;
let mut annotations = Annotations::new(&self.store, working_copy.index);
let promoted = annotations.promote(RecordId::Revision(revision), &self.node_principal())?;
if promoted.is_empty() {
println!("Nothing to promote to revision {}", revision.short());
Expand Down
6 changes: 2 additions & 4 deletions apps/origin-src/src/workspace/land.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use origin_shared::{
};

use super::{WorkingCopy, Workspace, WorkspaceError};
use crate::index::Index;
use crate::policy::Policy;
use crate::queue::{Blocked, Landing, Pending, Proposal, Queue};

Expand All @@ -33,11 +32,10 @@ impl Workspace {
onto: Option<TargetName>,
) -> Result<(), WorkspaceError> {
let working_copy = self.refresh()?;
let index = Index::open(&self.store)?;
let change = working_copy.find_change(&index, change.unwrap_or("@"))?;
let change = working_copy.find_change(change.unwrap_or("@"))?;
let onto = match onto {
Some(onto) => onto,
None => self.target_of(Self::single_head(&index, change)?)?,
None => self.target_of(Self::single_head(&working_copy.index, change)?)?,
};
let key = self.config.node_key()?;
let landings =
Expand Down
Loading
Loading