1use anyhow::{ensure, Result};
9
10use crate::graph::*;
11use crate::labels::{EdgeLabel, VisitStatus};
12use crate::properties;
13use crate::NodeType;
14
15pub fn find_latest_snp<G>(graph: &G, ori: NodeId) -> Result<Option<(NodeId, u64)>>
22where
23 G: SwhLabeledForwardGraph + SwhGraphWithProperties,
24 <G as SwhGraphWithProperties>::Maps: properties::Maps,
25{
26 let props = graph.properties();
27 let node_type = props.node_type(ori);
28 ensure!(
29 node_type == NodeType::Origin,
30 "Type of {ori} should be ori, but is {node_type} instead"
31 );
32 let mut latest_snp: Option<(usize, u64)> = None;
34 for (succ, labels) in graph.labeled_successors(ori) {
35 let node_type = props.node_type(succ);
36 if node_type != NodeType::Snapshot {
37 continue;
38 }
39 for label in labels {
40 if let EdgeLabel::Visit(visit) = label {
41 if visit.status() != VisitStatus::Full {
42 continue;
43 }
44 let ts = visit.timestamp();
45 if let Some((_cur_snp, cur_ts)) = latest_snp {
46 if ts > cur_ts {
47 latest_snp = Some((succ, ts))
48 }
49 } else {
50 latest_snp = Some((succ, ts))
51 }
52 }
53 }
54 }
55 Ok(latest_snp)
56}
57
58mod fs;
59pub use fs::*;
60
61mod vcs;
62pub use vcs::*;
63
64mod visit;
65pub use visit::*;
66
67mod root_directory;
68pub use root_directory::find_root_dir;