mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 00:45:18 +03:00
dag: unknown names when resolving (names, heads) to paths is not an error
Summary: When translating RequestNameToLocation to ResponseIdNamePair. If "heads" are known, but some "names" aren't. Do not treat it as an error. This will be used by the client-side to properly handle the "contains" check. Reviewed By: sfilipco Differential Revision: D27629309 fbshipit-source-id: 206ec5df956b33f4e816ab8d6a67ce776fd7bd74
This commit is contained in:
parent
ba7e1c6952
commit
545e6eeb25
@ -21,7 +21,6 @@ use crate::id::VertexName;
|
||||
use crate::iddag::{FirstAncestorConstraint, IdDag};
|
||||
use crate::iddagstore::IdDagStore;
|
||||
use crate::ops::IdConvert;
|
||||
use crate::Error;
|
||||
use crate::Group;
|
||||
use crate::Id;
|
||||
#[cfg(any(test, feature = "indexedlog-backend"))]
|
||||
@ -31,7 +30,6 @@ use crate::Result;
|
||||
use futures::stream;
|
||||
use futures::stream::StreamExt;
|
||||
use futures::stream::TryStreamExt;
|
||||
use futures::TryFutureExt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cell::RefCell;
|
||||
use std::fmt;
|
||||
@ -311,33 +309,49 @@ impl<M: IdConvert, DagStore: IdDagStore> Process<RequestNameToLocation, Response
|
||||
.await?;
|
||||
IdSet::from_spans(heads)
|
||||
};
|
||||
let resolvable = dag.ancestors(heads.clone())?;
|
||||
|
||||
let id_names: Vec<(Id, VertexName)> = {
|
||||
let names = stream::iter(request.names.into_iter());
|
||||
names
|
||||
.then(|name| map.vertex_id(name.clone()).map_ok(|i| (i, name)))
|
||||
.try_collect()
|
||||
.await?
|
||||
let ids_result = map.vertex_id_batch(&request.names).await?;
|
||||
let mut id_names = Vec::with_capacity(ids_result.len());
|
||||
for (name, id_result) in request.names.into_iter().zip(ids_result) {
|
||||
match id_result {
|
||||
// If one of the names cannot be resolved to id, just skip it.
|
||||
Err(crate::Error::VertexNotFound(n)) => {
|
||||
tracing::trace!(
|
||||
"RequestNameToLocation -> ResponseIdNamePair: skip unknown name {:?}",
|
||||
&n
|
||||
);
|
||||
continue;
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(e);
|
||||
}
|
||||
Ok(id) => {
|
||||
if resolvable.contains(id) {
|
||||
id_names.push((id, name))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
id_names
|
||||
};
|
||||
|
||||
let path_names: Vec<(AncestorPath, Vec<VertexName>)> = {
|
||||
let x_n_names: Vec<(Id, u64, VertexName)> = id_names
|
||||
.into_iter()
|
||||
.map(|(id, name)| {
|
||||
let (x, n) = dag
|
||||
.to_first_ancestor_nth(
|
||||
id,
|
||||
FirstAncestorConstraint::KnownUniversally {
|
||||
heads: heads.clone(),
|
||||
},
|
||||
)?
|
||||
.ok_or_else(|| {
|
||||
Error::Programming(format!(
|
||||
"no x~n path found for {:?} ({})",
|
||||
&name, id
|
||||
))
|
||||
})?;
|
||||
Ok((x, n, name))
|
||||
.filter_map(|(id, name)| {
|
||||
match dag.to_first_ancestor_nth(
|
||||
id,
|
||||
FirstAncestorConstraint::KnownUniversally {
|
||||
heads: heads.clone(),
|
||||
},
|
||||
) {
|
||||
Err(e) => Some(Err(e)),
|
||||
// Skip ids that cannot be translated.
|
||||
Ok(None) => None,
|
||||
Ok(Some((x, n))) => Some(Ok((x, n, name))),
|
||||
}
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user