1use gen_core::{BranchName, CommitRef, DoltHashId};
18use rusqlite::Result as SqlResult;
19use thiserror::Error;
20
21use crate::db::GraphConnection;
22
23pub mod dolt;
24
25#[derive(Clone, Debug, Eq, PartialEq)]
26pub struct HistoryEntry {
27 pub commit_hash: DoltHashId,
28 pub parent_hash: Option<DoltHashId>,
29 pub committer: String,
30 pub email: String,
31 pub date: String,
32 pub message: String,
33 pub is_head: bool,
34}
35
36#[derive(Clone, Debug, Eq, PartialEq)]
37pub struct HistoryStatus {
38 pub table_name: String,
39 pub staged: bool,
40 pub status: String,
41}
42
43#[derive(Clone, Debug, Eq, PartialEq)]
44pub struct HistoryConflict {
45 pub table_name: String,
46 pub num_conflicts: i64,
47}
48
49#[derive(Debug, Error)]
50pub enum HistoryError {
51 #[error("Database error: {0}")]
52 Database(#[from] rusqlite::Error),
53 #[error("Commit reference '{0}' is ambiguous")]
54 AmbiguousReference(String),
55 #[error("No commit resolved for '{0}'")]
56 UnresolvedReference(String),
57}
58
59pub type HistoryResult<T> = Result<T, HistoryError>;
60
61pub trait HistoryStore {
62 fn current_head(&self) -> SqlResult<Option<DoltHashId>>;
63 fn current_branch(&self) -> SqlResult<Option<BranchName>>;
64 fn resolve_ref(&self, reference: &CommitRef) -> HistoryResult<Option<DoltHashId>>;
65 fn resolve_operation_hash(&self, reference: &CommitRef) -> HistoryResult<DoltHashId>;
66 fn log_for_ref(
67 &self,
68 reference: &CommitRef,
69 limit: Option<usize>,
70 ) -> HistoryResult<Vec<HistoryEntry>>;
71 fn log(&self, limit: Option<usize>) -> SqlResult<Vec<HistoryEntry>>;
72 fn status(&self) -> SqlResult<Vec<HistoryStatus>>;
73 fn conflicts(&self) -> SqlResult<Vec<HistoryConflict>>;
74 fn commit_exists(&self, commit_hash: &DoltHashId) -> SqlResult<bool>;
75 fn commit_parents(&self, commit_hash: &DoltHashId) -> SqlResult<Vec<DoltHashId>>;
76 fn is_ancestor(
77 &self,
78 ancestor_hash: &DoltHashId,
79 descendant_hash: &DoltHashId,
80 ) -> SqlResult<bool>;
81 fn commit_all(&self, message: &str) -> SqlResult<DoltHashId>;
82 fn checkout_branch(&self, branch_name: &BranchName) -> SqlResult<()>;
83 fn checkout_commit(&self, commit_hash: &DoltHashId) -> SqlResult<()>;
84 fn create_branch(
85 &self,
86 branch_name: &BranchName,
87 start_ref: Option<&CommitRef>,
88 ) -> SqlResult<()>;
89 fn delete_branch(&self, branch_name: &BranchName) -> SqlResult<()>;
90 fn merge_base(&self, source: &CommitRef, target: &CommitRef) -> SqlResult<DoltHashId>;
91 fn merge(&self, reference: &CommitRef) -> SqlResult<DoltHashId>;
92 fn cherry_pick(&self, commit_hash: &DoltHashId) -> SqlResult<()>;
93 fn reset_hard(&self, target: &CommitRef) -> SqlResult<()>;
94 fn push(&self, remote_name: &str, branch_name: &BranchName) -> SqlResult<()>;
95 fn pull(&self, remote_name: &str, branch_name: &BranchName) -> SqlResult<()>;
96 fn fetch(&self, remote_name: &str, branch_name: Option<&BranchName>) -> SqlResult<()>;
97 fn graph(&self) -> &GraphConnection;
98}