dag: rename snapshot_dag to dag_snapshot

Summary: This is more consistent with `id_map_snapshot`.

Reviewed By: sfilipco

Differential Revision: D23182519

fbshipit-source-id: 62b7fc8bfdc9d6b3a4639a6518ea084c7f3807dd
This commit is contained in:
Jun Wu 2020-08-26 15:26:49 -07:00 committed by Facebook GitHub Bot
parent 4d798c39d9
commit bd7769b34a
10 changed files with 53 additions and 53 deletions

View File

@ -295,9 +295,9 @@ impl DagAlgorithm for commits {
self.inner(py).borrow().reachable_roots(roots, heads)
}
fn snapshot_dag(&self) -> dag::Result<Arc<dyn DagAlgorithm + Send + Sync>> {
fn dag_snapshot(&self) -> dag::Result<Arc<dyn DagAlgorithm + Send + Sync>> {
let py = unsafe { Python::assume_gil_acquired() };
self.inner(py).borrow().snapshot_dag()
self.inner(py).borrow().dag_snapshot()
}
}

View File

@ -390,11 +390,11 @@ impl<T: NameDagStorage + Send + Sync> DagAlgorithm for T {
/// Sort a `NameSet` topologically.
fn sort(&self, set: &NameSet) -> Result<NameSet> {
if set.hints().contains(Flags::TOPO_DESC)
&& set.hints().is_dag_compatible(self.snapshot_dag()?)
&& set.hints().is_dag_compatible(self.dag_snapshot()?)
{
Ok(set.clone())
} else {
let flags = extract_ancestor_flag_if_compatible(set.hints(), self.snapshot_dag()?);
let flags = extract_ancestor_flag_if_compatible(set.hints(), self.dag_snapshot()?);
let mut spans = SpanSet::empty();
for name in set.iter()? {
let id = self.map().vertex_id(name?)?;
@ -404,7 +404,7 @@ impl<T: NameDagStorage + Send + Sync> DagAlgorithm for T {
result
.hints()
.add_flags(flags)
.set_dag(self.snapshot_dag()?);
.set_dag(self.dag_snapshot()?);
Ok(result)
}
}
@ -424,7 +424,7 @@ impl<T: NameDagStorage + Send + Sync> DagAlgorithm for T {
let spans = self.dag().all()?;
let query = IdStaticSet::from_spans_idmap(spans, self.clone_map());
let hints = query.hints();
hints.add_flags(Flags::FULL).set_dag(self.snapshot_dag()?);
hints.add_flags(Flags::FULL).set_dag(self.dag_snapshot()?);
let result = NameSet::from_query(query);
Ok(result)
}
@ -432,7 +432,7 @@ impl<T: NameDagStorage + Send + Sync> DagAlgorithm for T {
/// Calculates all ancestors reachable from any name from the given set.
fn ancestors(&self, set: NameSet) -> Result<NameSet> {
if set.hints().contains(Flags::ANCESTORS)
&& set.hints().is_dag_compatible(self.snapshot_dag()?)
&& set.hints().is_dag_compatible(self.dag_snapshot()?)
{
return Ok(set);
}
@ -442,7 +442,7 @@ impl<T: NameDagStorage + Send + Sync> DagAlgorithm for T {
result
.hints()
.add_flags(Flags::ANCESTORS)
.set_dag(self.snapshot_dag()?);
.set_dag(self.dag_snapshot()?);
Ok(result)
}
@ -452,7 +452,7 @@ impl<T: NameDagStorage + Send + Sync> DagAlgorithm for T {
/// to preserve order.
fn parents(&self, set: NameSet) -> Result<NameSet> {
// Preserve ANCESTORS flag. If ancestors(x) == x, then ancestors(parents(x)) == parents(x).
let flags = extract_ancestor_flag_if_compatible(set.hints(), self.snapshot_dag()?);
let flags = extract_ancestor_flag_if_compatible(set.hints(), self.dag_snapshot()?);
let spans = self.dag().parents(self.to_id_set(&set)?)?;
let result = NameSet::from_spans_idmap(spans, self.clone_map());
result.hints().add_flags(flags);
@ -481,14 +481,14 @@ impl<T: NameDagStorage + Send + Sync> DagAlgorithm for T {
/// Calculates heads of the given set.
fn heads(&self, set: NameSet) -> Result<NameSet> {
if set.hints().contains(Flags::ANCESTORS)
&& set.hints().is_dag_compatible(self.snapshot_dag()?)
&& set.hints().is_dag_compatible(self.dag_snapshot()?)
{
// heads_ancestors is faster.
return self.heads_ancestors(set);
}
let spans = self.dag().heads(self.to_id_set(&set)?)?;
let result = NameSet::from_spans_idmap(spans, self.clone_map());
result.hints().set_dag(self.snapshot_dag()?);
result.hints().set_dag(self.dag_snapshot()?);
#[cfg(test)]
{
result.assert_eq(crate::default_impl::heads(self, set)?);
@ -500,19 +500,19 @@ impl<T: NameDagStorage + Send + Sync> DagAlgorithm for T {
fn children(&self, set: NameSet) -> Result<NameSet> {
let spans = self.dag().children(self.to_id_set(&set)?)?;
let result = NameSet::from_spans_idmap(spans, self.clone_map());
result.hints().set_dag(self.snapshot_dag()?);
result.hints().set_dag(self.dag_snapshot()?);
Ok(result)
}
/// Calculates roots of the given set.
fn roots(&self, set: NameSet) -> Result<NameSet> {
let flags = extract_ancestor_flag_if_compatible(set.hints(), self.snapshot_dag()?);
let flags = extract_ancestor_flag_if_compatible(set.hints(), self.dag_snapshot()?);
let spans = self.dag().roots(self.to_id_set(&set)?)?;
let result = NameSet::from_spans_idmap(spans, self.clone_map());
result
.hints()
.add_flags(flags)
.set_dag(self.snapshot_dag()?);
.set_dag(self.dag_snapshot()?);
#[cfg(test)]
{
result.assert_eq(crate::default_impl::roots(self, set)?);
@ -542,7 +542,7 @@ impl<T: NameDagStorage + Send + Sync> DagAlgorithm for T {
fn gca_all(&self, set: NameSet) -> Result<NameSet> {
let spans = self.dag().gca_all(self.to_id_set(&set)?)?;
let result = NameSet::from_spans_idmap(spans, self.clone_map());
result.hints().set_dag(self.snapshot_dag()?);
result.hints().set_dag(self.dag_snapshot()?);
#[cfg(test)]
{
result.assert_eq(crate::default_impl::gca_all(self, set)?);
@ -557,7 +557,7 @@ impl<T: NameDagStorage + Send + Sync> DagAlgorithm for T {
result
.hints()
.add_flags(Flags::ANCESTORS)
.set_dag(self.snapshot_dag()?);
.set_dag(self.dag_snapshot()?);
#[cfg(test)]
{
result.assert_eq(crate::default_impl::common_ancestors(self, set)?);
@ -591,7 +591,7 @@ impl<T: NameDagStorage + Send + Sync> DagAlgorithm for T {
fn heads_ancestors(&self, set: NameSet) -> Result<NameSet> {
let spans = self.dag().heads_ancestors(self.to_id_set(&set)?)?;
let result = NameSet::from_spans_idmap(spans, self.clone_map());
result.hints().set_dag(self.snapshot_dag()?);
result.hints().set_dag(self.dag_snapshot()?);
#[cfg(test)]
{
// default_impl::heads_ancestors calls `heads` if `Flags::ANCESTORS`
@ -609,7 +609,7 @@ impl<T: NameDagStorage + Send + Sync> DagAlgorithm for T {
let heads = self.to_id_set(&heads)?;
let spans = self.dag().range(roots, heads)?;
let result = NameSet::from_spans_idmap(spans, self.clone_map());
result.hints().set_dag(self.snapshot_dag()?);
result.hints().set_dag(self.dag_snapshot()?);
Ok(result)
}
@ -617,13 +617,13 @@ impl<T: NameDagStorage + Send + Sync> DagAlgorithm for T {
fn descendants(&self, set: NameSet) -> Result<NameSet> {
let spans = self.dag().descendants(self.to_id_set(&set)?)?;
let result = NameSet::from_spans_idmap(spans, self.clone_map());
result.hints().set_dag(self.snapshot_dag()?);
result.hints().set_dag(self.dag_snapshot()?);
Ok(result)
}
/// Get a snapshot of the current graph.
fn snapshot_dag(&self) -> Result<Arc<dyn DagAlgorithm + Send + Sync>> {
NameDagStorage::snapshot_dag(self)
fn dag_snapshot(&self) -> Result<Arc<dyn DagAlgorithm + Send + Sync>> {
NameDagStorage::dag_snapshot(self)
}
}
@ -816,7 +816,7 @@ pub trait NameDagStorage: IdMapEq {
fn clone_map(&self) -> Arc<dyn IdConvert + Send + Sync>;
/// (Relatively cheaply) clone the dag.
fn snapshot_dag(&self) -> Result<Arc<dyn DagAlgorithm + Send + Sync>>;
fn dag_snapshot(&self) -> Result<Arc<dyn DagAlgorithm + Send + Sync>>;
}
impl NameDagStorage for NameDag {
@ -832,7 +832,7 @@ impl NameDagStorage for NameDag {
fn clone_map(&self) -> Arc<dyn IdConvert + Send + Sync> {
self.snapshot_map.clone()
}
fn snapshot_dag(&self) -> Result<Arc<dyn DagAlgorithm + Send + Sync>> {
fn dag_snapshot(&self) -> Result<Arc<dyn DagAlgorithm + Send + Sync>> {
Ok(self.try_snapshot()? as Arc<dyn DagAlgorithm + Send + Sync>)
}
}
@ -850,7 +850,7 @@ impl NameDagStorage for MemNameDag {
fn clone_map(&self) -> Arc<dyn IdConvert + Send + Sync> {
self.snapshot_map.clone()
}
fn snapshot_dag(&self) -> Result<Arc<dyn DagAlgorithm + Send + Sync>> {
fn dag_snapshot(&self) -> Result<Arc<dyn DagAlgorithm + Send + Sync>> {
Ok(self.snapshot() as Arc<dyn DagAlgorithm + Send + Sync>)
}
}

View File

@ -326,7 +326,7 @@ pub(crate) mod tests {
assert_eq!(format!("{:?}", &all), "<spans [A:G+0:6]>");
let ac: NameSet = "A C".into();
ac.hints().set_dag(dag.snapshot_dag()?);
ac.hints().set_dag(dag.dag_snapshot()?);
let intersection = all.intersection(&ac);
// should not be "<and ...>"
@ -410,7 +410,7 @@ pub(crate) mod tests {
);
// Binding to the Dag enables fast paths.
bfg.hints().set_dag(dag.snapshot_dag()?);
bfg.hints().set_dag(dag.dag_snapshot()?);
// 'heads' has a fast path that uses 'heads_ancestors' to do the calculation.
// (in this case the result is incorrect because the hints are wrong).

View File

@ -287,7 +287,7 @@ pub trait DagAlgorithm {
/// Get a snapshot of the current graph that can operate separately.
///
/// This makes it easier to fight with borrowck.
fn snapshot_dag(&self) -> Result<Arc<dyn DagAlgorithm + Send + Sync>>;
fn dag_snapshot(&self) -> Result<Arc<dyn DagAlgorithm + Send + Sync>>;
}
/// Add vertexes recursively to the DAG.
@ -456,7 +456,7 @@ impl<T: IdMapSnapshot + DagAlgorithm> ToSet for T {
fn to_set(&self, set: &IdSet) -> Result<NameSet> {
let id_map = self.id_map_snapshot()?;
let result = NameSet::from_spans_idmap(set.clone(), id_map);
result.hints().set_dag(self.snapshot_dag()?);
result.hints().set_dag(self.dag_snapshot()?);
Ok(result)
}
}

View File

@ -154,8 +154,8 @@ impl DagAlgorithm for DoubleWriteCommits {
fn reachable_roots(&self, roots: Set, heads: Set) -> dag::Result<Set> {
self.commits.reachable_roots(roots, heads)
}
fn snapshot_dag(&self) -> dag::Result<Arc<dyn DagAlgorithm + Send + Sync>> {
self.commits.snapshot_dag()
fn dag_snapshot(&self) -> dag::Result<Arc<dyn DagAlgorithm + Send + Sync>> {
self.commits.dag_snapshot()
}
}

View File

@ -208,8 +208,8 @@ impl DagAlgorithm for GitSegmentedCommits {
fn reachable_roots(&self, roots: Set, heads: Set) -> dag::Result<Set> {
self.dag.reachable_roots(roots, heads)
}
fn snapshot_dag(&self) -> dag::Result<Arc<dyn DagAlgorithm + Send + Sync>> {
self.dag.snapshot_dag()
fn dag_snapshot(&self) -> dag::Result<Arc<dyn DagAlgorithm + Send + Sync>> {
self.dag.dag_snapshot()
}
}

View File

@ -230,8 +230,8 @@ impl DagAlgorithm for HgCommits {
fn reachable_roots(&self, roots: Set, heads: Set) -> dag::Result<Set> {
self.dag.reachable_roots(roots, heads)
}
fn snapshot_dag(&self) -> dag::Result<Arc<dyn DagAlgorithm + Send + Sync>> {
self.dag.snapshot_dag()
fn dag_snapshot(&self) -> dag::Result<Arc<dyn DagAlgorithm + Send + Sync>> {
self.dag.dag_snapshot()
}
}

View File

@ -178,8 +178,8 @@ impl DagAlgorithm for MemHgCommits {
fn reachable_roots(&self, roots: Set, heads: Set) -> dag::Result<Set> {
self.dag.reachable_roots(roots, heads)
}
fn snapshot_dag(&self) -> dag::Result<Arc<dyn DagAlgorithm + Send + Sync>> {
self.dag.snapshot_dag()
fn dag_snapshot(&self) -> dag::Result<Arc<dyn DagAlgorithm + Send + Sync>> {
self.dag.dag_snapshot()
}
}

View File

@ -168,8 +168,8 @@ impl DagAlgorithm for RevlogCommits {
fn reachable_roots(&self, roots: Set, heads: Set) -> dag::Result<Set> {
self.revlog.reachable_roots(roots, heads)
}
fn snapshot_dag(&self) -> dag::Result<Arc<dyn DagAlgorithm + Send + Sync>> {
self.revlog.snapshot_dag()
fn dag_snapshot(&self) -> dag::Result<Arc<dyn DagAlgorithm + Send + Sync>> {
self.revlog.dag_snapshot()
}
}

View File

@ -967,7 +967,7 @@ impl DagAlgorithm for RevlogIndex {
spans.push(id);
}
let result = Set::from_spans_idmap(spans, self.get_snapshot());
result.hints().set_dag(self.snapshot_dag()?);
result.hints().set_dag(self.dag_snapshot()?);
Ok(result)
}
}
@ -995,7 +995,7 @@ impl DagAlgorithm for RevlogIndex {
result
.hints()
.add_flags(Flags::FULL)
.set_dag(self.snapshot_dag()?);
.set_dag(self.dag_snapshot()?);
Ok(result)
}
@ -1041,7 +1041,7 @@ impl DagAlgorithm for RevlogIndex {
set.hints()
.add_flags(Flags::ID_DESC | Flags::TOPO_DESC | Flags::ANCESTORS)
.set_max_id(max_id)
.set_dag(self.snapshot_dag()?);
.set_dag(self.dag_snapshot()?);
Ok(set)
}
@ -1082,7 +1082,7 @@ impl DagAlgorithm for RevlogIndex {
let idmap = dag;
let result = Set::from_spans_idmap(id_spans, idmap);
result.hints().set_dag(self.snapshot_dag()?);
result.hints().set_dag(self.dag_snapshot()?);
Ok(result)
}
@ -1117,7 +1117,7 @@ impl DagAlgorithm for RevlogIndex {
set.hints()
.add_flags(Flags::ID_ASC)
.set_min_id(min_id)
.set_dag(self.snapshot_dag()?);
.set_dag(self.dag_snapshot()?);
Ok(set)
}
@ -1151,7 +1151,7 @@ impl DagAlgorithm for RevlogIndex {
.add_flags(Flags::ID_DESC | Flags::TOPO_DESC)
.set_min_id(min_id)
.set_max_id(max_id)
.set_dag(self.snapshot_dag()?);
.set_dag(self.dag_snapshot()?);
Ok(set)
}
@ -1202,7 +1202,7 @@ impl DagAlgorithm for RevlogIndex {
let gcas = self.gca_revs(&revs, usize::max_value())?;
let spans = IdSet::from_spans(gcas.into_iter().map(|r| Id(r as _)));
let result = Set::from_spans_idmap(spans, self.get_snapshot());
result.hints().set_dag(self.snapshot_dag()?);
result.hints().set_dag(self.dag_snapshot()?);
Ok(result)
}
@ -1268,7 +1268,7 @@ impl DagAlgorithm for RevlogIndex {
}
}
let result = Set::from_spans_idmap(result_id_set, self.get_snapshot());
result.hints().set_dag(self.snapshot_dag()?);
result.hints().set_dag(self.dag_snapshot()?);
Ok(result)
}
@ -1290,7 +1290,7 @@ impl DagAlgorithm for RevlogIndex {
let result_revs = self.range_revs(&root_revs, &head_revs)?;
let result_id_set = IdSet::from_spans(result_revs.into_iter().map(|r| Id(r as _)));
let result = Set::from_spans_idmap(result_id_set, self.get_snapshot());
result.hints().set_dag(self.snapshot_dag()?);
result.hints().set_dag(self.dag_snapshot()?);
Ok(result)
}
@ -1361,7 +1361,7 @@ impl DagAlgorithm for RevlogIndex {
}
let result = Set::from_spans_idmap(result, self.get_snapshot());
result.hints().set_dag(self.snapshot_dag()?);
result.hints().set_dag(self.dag_snapshot()?);
Ok(result)
}
@ -1379,8 +1379,8 @@ impl DagAlgorithm for RevlogIndex {
ancestors
.hints()
.add_flags(Flags::ANCESTORS)
.set_dag(self.snapshot_dag()?);
only.hints().set_dag(self.snapshot_dag()?);
.set_dag(self.dag_snapshot()?);
only.hints().set_dag(self.dag_snapshot()?);
Ok((only, ancestors))
}
@ -1423,7 +1423,7 @@ impl DagAlgorithm for RevlogIndex {
set.hints()
.add_flags(Flags::ID_ASC)
.set_min_id(min_id)
.set_dag(self.snapshot_dag()?);
.set_dag(self.dag_snapshot()?);
Ok(set)
}
@ -1490,11 +1490,11 @@ impl DagAlgorithm for RevlogIndex {
}
let result = Set::from_spans_idmap(result, self.get_snapshot());
result.hints().set_dag(self.snapshot_dag()?);
result.hints().set_dag(self.dag_snapshot()?);
Ok(result)
}
fn snapshot_dag(&self) -> dag::Result<Arc<dyn DagAlgorithm + Send + Sync>> {
fn dag_snapshot(&self) -> dag::Result<Arc<dyn DagAlgorithm + Send + Sync>> {
Ok(self.get_snapshot())
}
}