1use anyhow::{ensure, Result};
9
10use swh_graph::graph::*;
11use swh_graph::labels::{EdgeLabel, VisitStatus};
12use swh_graph::properties;
13use swh_graph::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
58pub mod collections;
59
60mod fs;
61pub use fs::*;
62
63mod root_directory;
64pub use root_directory::find_root_dir;
65
66mod vcs;
67pub use vcs::*;
68
69mod visit;
70pub use visit::*;
71
72pub mod diff;