Skip to main content

dag/
lib.rs

1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#![allow(dead_code)]
9#![allow(clippy::iter_nth_zero, for_loops_over_fallibles)]
10#![allow(unexpected_cfgs)]
11
12//! # dag
13//!
14//! Building blocks for the commit graph used by source control.
15
16mod bsearch;
17pub mod config;
18pub mod dag;
19pub mod default_impl;
20mod delegate;
21pub mod errors;
22mod fmt;
23pub mod iddag;
24pub mod iddagstore;
25pub mod idmap;
26mod idset;
27mod integrity;
28pub(crate) mod lifecycle;
29pub mod ops;
30pub mod protocol;
31#[cfg(any(test, feature = "render"))]
32pub mod render;
33pub mod segment;
34pub mod set;
35pub(crate) mod types_ext;
36pub mod utils;
37mod verlink;
38mod vertex_options;
39
40#[cfg(any(test, feature = "indexedlog-backend"))]
41pub use dag::Dag;
42pub use dag::DagBuilder;
43pub use dag_types::CloneData;
44pub use dag_types::Group;
45pub use dag_types::Id;
46pub use dag_types::Location;
47pub use dag_types::Vertex;
48pub use dag_types::clone;
49pub use dag_types::id;
50pub use iddag::FirstAncestorConstraint;
51pub use iddag::IdDag;
52pub use iddag::IdDagAlgorithm;
53pub use iddagstore::IdDagStore;
54#[cfg(any(test, feature = "indexedlog-backend"))]
55pub use idmap::IdMap;
56pub use idset::IdList;
57pub use idset::IdSet;
58pub use idset::OrderedSpan;
59pub use ops::DagAlgorithm;
60pub use segment::FlatSegment;
61pub use segment::IdSegment;
62pub use segment::PreparedFlatSegments;
63pub use set::Set;
64pub use verlink::VerLink;
65pub use vertex_options::VertexListWithOptions;
66pub use vertex_options::VertexOptions;
67
68pub type Level = u8;
69pub type MemIdDag = IdDag<iddagstore::MemStore>;
70#[cfg(any(test, feature = "indexedlog-backend"))]
71pub type OnDiskIdDag = IdDag<iddagstore::IndexedLogStore>;
72
73// Short aliases for main public types.
74pub type IdSetIter<T> = idset::IdSetIter<T>;
75pub type IdSpan = idset::Span;
76pub use dag::MemDag;
77#[cfg(feature = "indexedlog-backend")]
78pub use iddagstore::indexedlog_store::describe_indexedlog_entry;
79pub use set::NameIter as SetIter;
80
81#[cfg(any(test, feature = "indexedlog-backend"))]
82pub mod tests;
83
84pub use errors::DagError as Error;
85pub type Result<T> = std::result::Result<T, Error>;
86
87// Re-export
88#[cfg(feature = "failpoints")]
89#[doc(hidden)]
90pub use fail::fail_point;
91#[cfg(feature = "indexedlog-backend")]
92pub use indexedlog::Repair;
93pub use nonblocking;
94
95#[cfg(feature = "failpoints")]
96#[macro_export]
97macro_rules! failpoint {
98    ($name:literal) => {
99        $crate::fail_point!($name, |_| {
100            let msg = format!("failpoint injected by FAILPOINTS: {}", $name);
101            Err($crate::errors::DagError::from(
102                $crate::errors::BackendError::Generic(msg),
103            ))
104        })
105    };
106}
107
108#[cfg(not(feature = "failpoints"))]
109#[macro_export]
110macro_rules! failpoint {
111    ($name:literal) => {{}};
112}
113
114/// Whether running inside a test.
115pub(crate) fn is_testing() -> bool {
116    std::env::var("TESTTMP").is_ok()
117}
118
119#[cfg(test)]
120dev_logger::init!();
121
122#[test]
123fn test_failpoint_feature() {
124    #[cfg(feature = "failpoints")]
125    let _scenario = fail::FailScenario::setup();
126    #[cfg(feature = "failpoints")]
127    fail::cfg("dag-test-failpoint", "return").unwrap();
128
129    let result = (|| -> Result<()> {
130        crate::failpoint!("dag-test-failpoint");
131        Ok(())
132    })();
133    assert_eq!(result.is_err(), cfg!(feature = "failpoints"));
134}