Skip to main content

rskit_git/
read.rs

1//! Read-oriented git traits.
2
3use rskit_errors::AppResult;
4
5use crate::options::{BlameOptions, DescribeOptions, GrepOptions, LogOptions};
6use crate::types::{
7    BlameLine, Commit, DiffEntry, DiffStats, GrepMatch, IndexEntry, Oid, StatusEntry, TreeEntry,
8    TreeHash,
9};
10
11/// Diff and working tree status operations.
12pub trait Differ {
13    /// Returns file changes between two refs.
14    fn diff(&self, from: &str, to: &str) -> AppResult<Vec<DiffEntry>>;
15
16    /// Returns aggregated statistics for changes between two refs.
17    fn diff_stats(&self, from: &str, to: &str) -> AppResult<DiffStats>;
18
19    /// Returns the working tree status.
20    fn status(&self) -> AppResult<Vec<StatusEntry>>;
21}
22
23/// Read access to Git ignore rules.
24pub trait IgnoreReader {
25    /// Reports whether a repository-relative path is ignored by Git.
26    ///
27    /// The path does not need to exist in the working tree.
28    fn is_ignored(&self, path: &str) -> AppResult<bool>;
29}
30
31/// Read access to git index entries.
32pub trait IndexReader {
33    /// Returns the index entry for `path`, if the path is present in the index.
34    fn index_entry(&self, path: &str) -> AppResult<Option<IndexEntry>>;
35}
36
37/// Read access to git tree objects.
38pub trait TreeReader {
39    /// Returns the OID of the tree at the given path and revision.
40    fn tree_hash(&self, revision: &str, path: &str) -> AppResult<TreeHash>;
41
42    /// Returns the content of a file at the given revision and path.
43    fn file_at(&self, revision: &str, path: &str) -> AppResult<Vec<u8>>;
44
45    /// Returns the entries in a tree at the given revision and path.
46    fn list_entries(&self, revision: &str, path: &str) -> AppResult<Vec<TreeEntry>>;
47}
48
49/// Read-only access to commit history and graph queries.
50pub trait LogReader {
51    /// Returns commits reachable from `HEAD`, filtered by the provided options.
52    fn log(&self, opts: Option<&LogOptions>) -> AppResult<Vec<Commit>>;
53
54    /// Returns the merge base between two revisions.
55    fn merge_base(&self, a: &str, b: &str) -> AppResult<Oid>;
56
57    /// Reports whether `ancestor` is an ancestor of `descendant`.
58    fn is_ancestor(&self, ancestor: &str, descendant: &str) -> AppResult<bool>;
59}
60
61/// Read-only access to `git blame` data.
62pub trait Blamer {
63    /// Returns per-line blame information for a file at the given revision.
64    fn blame(
65        &self,
66        revision: &str,
67        path: &str,
68        opts: Option<&BlameOptions>,
69    ) -> AppResult<Vec<BlameLine>>;
70}
71
72/// Read-only advanced inspection helpers.
73pub trait Inspector {
74    /// Describes the current revision in a human-readable form.
75    fn describe(&self, opts: Option<&DescribeOptions>) -> AppResult<String>;
76
77    /// Resolves a revision expression to an object ID.
78    fn rev_parse(&self, revision: &str) -> AppResult<Oid>;
79
80    /// Searches tracked content for pattern matches.
81    fn grep(
82        &self,
83        pattern: &str,
84        revision: &str,
85        opts: Option<&GrepOptions>,
86    ) -> AppResult<Vec<GrepMatch>>;
87
88    /// Returns raw object content for a revision expression.
89    fn show(&self, object: &str) -> AppResult<Vec<u8>>;
90}