History

more commitgraph docs

Sebastian Thiel committed 5 years ago

Commit a81ea671 parent cba048f4 files · +26 −3Browse files

Showing the changes to git-commitgraph/src (3 of 4 files). Show all

Unified · Split

3 files
  1. git-commitgraph/src/graph/access.rs +11 −0
  2. git-commitgraph/src/graph/init.rs +8 −0
  3. git-commitgraph/src/graph/verify.rs +2 −0
git-commitgraph/src/graph/access.rs+11−0
@@ -6,16 +6,25 @@ use git_object::borrowed; · 5 unmodified lines
66
77 /// Access
88 impl Graph {
9+ /// Returns the commit at the given position `pos`.
10+ ///
11+ /// # Panics
12+ /// If `pos` is greater or equal to [`num_commits()`][Graph::num_commits()].
913 pub fn commit_at(&self, pos: graph::Position) -> Commit<'_> {
1014 let r = self.lookup_by_pos(pos);
1115 r.file.commit_at(r.pos)
1216 }
1317
18+ /// Returns the commit matching the given `id`.
1419 pub fn commit_by_id(&self, id: borrowed::Id<'_>) -> Option<Commit<'_>> {
1520 let r = self.lookup_by_id(id)?;
1621 Some(r.file.commit_at(r.file_pos))
1722 }
1823
24+ /// Returns the `hash` at the given position `pos`.
25+ ///
26+ /// # Panics
27+ /// If `pos` is greater or equal to [`num_commits()`][Graph::num_commits()].
1928 pub fn id_at(&self, pos: graph::Position) -> borrowed::Id<'_> {
2029 let r = self.lookup_by_pos(pos);
2130 r.file.id_at(r.pos)
@@ -31,10 +40,12 @@ impl Graph { · 9 unmodified lines
3140 self.files.iter().flat_map(|file| file.iter_ids())
3241 }
3342
43+ /// Translate the given `id` to its position in the file.
3444 pub fn lookup(&self, id: borrowed::Id<'_>) -> Option<graph::Position> {
3545 Some(self.lookup_by_id(id)?.graph_pos)
3646 }
3747
48+ /// Returns the amount of commits stored in this file.
3849 pub fn num_commits(&self) -> u32 {
3950 self.files.iter().map(|f| f.num_commits()).sum()
4051 }
git-commitgraph/src/graph/init.rs+8−0
@@ -9,7 +9,9 @@ use std::{ · 8 unmodified lines
99 path::{Path, PathBuf},
1010 };
1111
12+/// The error used in the [`graph`][crate::graph] module.
1213 #[derive(thiserror::Error, Debug)]
14+#[allow(missing_docs)]
1315 pub enum Error {
1416 #[error("{}", .path.display())]
1517 File {
@@ -41,10 +43,12 @@ pub enum Error { · 25 unmodified lines
4143
4244 /// Instantiate a `Graph` from various sources.
4345 impl Graph {
46+ /// Instantiate a commit graph from `path` which may be a directory containing graph files or the graph file itself.
4447 pub fn at(path: impl AsRef<Path>) -> Result<Self, Error> {
4548 Self::try_from(path.as_ref())
4649 }
4750
51+ /// Instantiate a commit graph from the directory containing all of its files.
4852 pub fn from_commit_graphs_dir(path: impl AsRef<Path>) -> Result<Self, Error> {
4953 let commit_graphs_dir = path.as_ref();
5054 let chain_file_path = commit_graphs_dir.join("commit-graph-chain");
@@ -67,6 +71,8 @@ impl Graph { · 16 unmodified lines
6771 Self::new(files)
6872 }
6973
74+ /// Instantiate a commit graph from a `.git/objects/info/commit-graph` or
75+ /// `.git/objects/info/commit-graphs/graph-*.graph` file.
7076 pub fn from_file(path: impl AsRef<Path>) -> Result<Self, Error> {
7177 let path = path.as_ref();
7278 let file = File::at(path).map_err(|e| Error::File {
@@ -76,11 +82,13 @@ impl Graph { · 3 unmodified lines
7682 Self::new(vec![file])
7783 }
7884
85+ /// Instantiate a commit graph from an `.git/objects/info` directory.
7986 pub fn from_info_dir(info_dir: impl AsRef<Path>) -> Result<Self, Error> {
8087 Self::from_file(info_dir.as_ref().join("commit-graph"))
8188 .or_else(|_| Self::from_commit_graphs_dir(info_dir.as_ref().join("commit-graphs")))
8289 }
8390
91+ /// Create a new commit graph from a list of `files`.
8492 pub fn new(files: Vec<File>) -> Result<Self, Error> {
8593 let num_commits: u64 = files.iter().map(|f| u64::from(f.num_commits())).sum();
8694 if num_commits > u64::from(MAX_COMMITS) {
git-commitgraph/src/graph/verify.rs+2−0
@@ -10,7 +10,9 @@ use std::{ · 9 unmodified lines
1010 path::PathBuf,
1111 };
1212
13+/// The error used in [`verify_integrity()`][Graph::verify_integrity].
1314 #[derive(thiserror::Error, Debug)]
15+#[allow(missing_docs)]
1416 pub enum Error<E: std::error::Error + 'static> {
1517 #[error("'{}' should have {expected} base graphs, but claims {actual} base graphs", .path.display())]
1618 BaseGraphCount { actual: u8, expected: u8, path: PathBuf },

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t