Skip to content

Commit

Permalink
identities: update on fast-forward
Browse files Browse the repository at this point in the history
When we have a latest head that is a fast-forward of a known delegate
then we can update the top-level rad/id to that head, given that both
identities also verify.

Signed-off-by: Fintan Halpenny <[email protected]>
  • Loading branch information
FintanH committed Jun 24, 2021
1 parent 75cb749 commit 4ecd47c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions librad/src/identities/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,11 +775,29 @@ impl<'a> Identities<'a, Project> {
known: Person,
latest_head: git2::Oid,
) -> Result<VerifiedPerson, error::VerifyPerson> {
let is_fast_forward = |known: &Person, head: git2::Oid| {
let commit = self.repo.find_commit(head)?;
self.is_in_ancestry_path(known.content_id.into(), commit.tree_id())
};
// Nb. technically we could coerce `known` into a `VerifiedPerson` if its
// `content_id` equals `latest_head`. Let's not introduce an unsafe
// coercion, but rely on caching to be implemented efficiently.
if self.is_in_ancestry_path(latest_head, known.revision.into())? {
self.as_person().verify(latest_head)
// If the latest is a fast-forward then we can update the top-level
} else if is_fast_forward(&known, latest_head)? {
let latest = self.as_person().verify(latest_head)?;
let _known = self.as_person().verify(known.content_id.into())?;
let urn = reflike!("refs/namespaces")
.join(ext::RefLike::from(known.urn()))
.join((*urn::DEFAULT_PATH).clone())
.to_string();
let mut reference = self.repo.find_reference(&urn)?;
reference.set_target(
latest_head,
&format!("fast-forward of identity to {}", latest_head),
)?;
Ok(latest)
} else {
Err(error::VerifyPerson::NotInAncestryPath {
revision: known.revision,
Expand Down

0 comments on commit 4ecd47c

Please sign in to comment.