Skip to main content

chronicle/read/
mod.rs

1pub mod deps;
2pub mod history;
3pub mod retrieve;
4pub mod summary;
5
6use crate::error::{ChronicleError, Result};
7use crate::git::GitOps;
8use crate::schema::annotation::{LineRange, RegionAnnotation};
9
10/// Query parameters for reading annotations.
11#[derive(Debug, Clone)]
12pub struct ReadQuery {
13    pub file: String,
14    pub anchor: Option<String>,
15    pub lines: Option<LineRange>,
16}
17
18/// Result of a read query.
19#[derive(Debug, Clone, serde::Serialize)]
20pub struct ReadResult {
21    pub file: String,
22    pub regions: Vec<MatchedRegion>,
23}
24
25/// A region annotation matched to a specific commit.
26#[derive(Debug, Clone, serde::Serialize)]
27pub struct MatchedRegion {
28    pub commit: String,
29    pub timestamp: String,
30    pub region: RegionAnnotation,
31    pub summary: String,
32}
33
34/// Execute a read query against the repository.
35pub fn execute(git: &dyn GitOps, query: &ReadQuery) -> Result<ReadResult> {
36    let regions = retrieve::retrieve_regions(git, query).map_err(|e| ChronicleError::Git {
37        source: e,
38        location: snafu::Location::default(),
39    })?;
40
41    Ok(ReadResult {
42        file: query.file.clone(),
43        regions,
44    })
45}