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
6 6
7/// Access7/// Access
8impl Graph {8impl 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()].
9 pub fn commit_at(&self, pos: graph::Position) -> Commit<'_> {13 pub fn commit_at(&self, pos: graph::Position) -> Commit<'_> {
10 let r = self.lookup_by_pos(pos);14 let r = self.lookup_by_pos(pos);
11 r.file.commit_at(r.pos)15 r.file.commit_at(r.pos)
12 }16 }
13 17
18 /// Returns the commit matching the given `id`.
14 pub fn commit_by_id(&self, id: borrowed::Id<'_>) -> Option<Commit<'_>> {19 pub fn commit_by_id(&self, id: borrowed::Id<'_>) -> Option<Commit<'_>> {
15 let r = self.lookup_by_id(id)?;20 let r = self.lookup_by_id(id)?;
16 Some(r.file.commit_at(r.file_pos))21 Some(r.file.commit_at(r.file_pos))
17 }22 }
18 23
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()].
19 pub fn id_at(&self, pos: graph::Position) -> borrowed::Id<'_> {28 pub fn id_at(&self, pos: graph::Position) -> borrowed::Id<'_> {
20 let r = self.lookup_by_pos(pos);29 let r = self.lookup_by_pos(pos);
21 r.file.id_at(r.pos)30 r.file.id_at(r.pos)
@@ -31,10 +40,12 @@ impl Graph { · 9 unmodified lines
31 self.files.iter().flat_map(|file| file.iter_ids())40 self.files.iter().flat_map(|file| file.iter_ids())
32 }41 }
33 42
43 /// Translate the given `id` to its position in the file.
34 pub fn lookup(&self, id: borrowed::Id<'_>) -> Option<graph::Position> {44 pub fn lookup(&self, id: borrowed::Id<'_>) -> Option<graph::Position> {
35 Some(self.lookup_by_id(id)?.graph_pos)45 Some(self.lookup_by_id(id)?.graph_pos)
36 }46 }
37 47
48 /// Returns the amount of commits stored in this file.
38 pub fn num_commits(&self) -> u32 {49 pub fn num_commits(&self) -> u32 {
39 self.files.iter().map(|f| f.num_commits()).sum()50 self.files.iter().map(|f| f.num_commits()).sum()
40 }51 }
git-commitgraph/src/graph/init.rs+8−0
@@ -9,7 +9,9 @@ use std::{ · 8 unmodified lines
9 path::{Path, PathBuf},9 path::{Path, PathBuf},
10};10};
11 11
12/// The error used in the [`graph`][crate::graph] module.
12#[derive(thiserror::Error, Debug)]13#[derive(thiserror::Error, Debug)]
14#[allow(missing_docs)]
13pub enum Error {15pub enum Error {
14 #[error("{}", .path.display())]16 #[error("{}", .path.display())]
15 File {17 File {
@@ -41,10 +43,12 @@ pub enum Error { · 25 unmodified lines
41 43
42/// Instantiate a `Graph` from various sources.44/// Instantiate a `Graph` from various sources.
43impl Graph {45impl Graph {
46 /// Instantiate a commit graph from `path` which may be a directory containing graph files or the graph file itself.
44 pub fn at(path: impl AsRef<Path>) -> Result<Self, Error> {47 pub fn at(path: impl AsRef<Path>) -> Result<Self, Error> {
45 Self::try_from(path.as_ref())48 Self::try_from(path.as_ref())
46 }49 }
47 50
51 /// Instantiate a commit graph from the directory containing all of its files.
48 pub fn from_commit_graphs_dir(path: impl AsRef<Path>) -> Result<Self, Error> {52 pub fn from_commit_graphs_dir(path: impl AsRef<Path>) -> Result<Self, Error> {
49 let commit_graphs_dir = path.as_ref();53 let commit_graphs_dir = path.as_ref();
50 let chain_file_path = commit_graphs_dir.join("commit-graph-chain");54 let chain_file_path = commit_graphs_dir.join("commit-graph-chain");
@@ -67,6 +71,8 @@ impl Graph { · 16 unmodified lines
67 Self::new(files)71 Self::new(files)
68 }72 }
69 73
74 /// Instantiate a commit graph from a `.git/objects/info/commit-graph` or
75 /// `.git/objects/info/commit-graphs/graph-*.graph` file.
70 pub fn from_file(path: impl AsRef<Path>) -> Result<Self, Error> {76 pub fn from_file(path: impl AsRef<Path>) -> Result<Self, Error> {
71 let path = path.as_ref();77 let path = path.as_ref();
72 let file = File::at(path).map_err(|e| Error::File {78 let file = File::at(path).map_err(|e| Error::File {
@@ -76,11 +82,13 @@ impl Graph { · 3 unmodified lines
76 Self::new(vec![file])82 Self::new(vec![file])
77 }83 }
78 84
85 /// Instantiate a commit graph from an `.git/objects/info` directory.
79 pub fn from_info_dir(info_dir: impl AsRef<Path>) -> Result<Self, Error> {86 pub fn from_info_dir(info_dir: impl AsRef<Path>) -> Result<Self, Error> {
80 Self::from_file(info_dir.as_ref().join("commit-graph"))87 Self::from_file(info_dir.as_ref().join("commit-graph"))
81 .or_else(|_| Self::from_commit_graphs_dir(info_dir.as_ref().join("commit-graphs")))88 .or_else(|_| Self::from_commit_graphs_dir(info_dir.as_ref().join("commit-graphs")))
82 }89 }
83 90
91 /// Create a new commit graph from a list of `files`.
84 pub fn new(files: Vec<File>) -> Result<Self, Error> {92 pub fn new(files: Vec<File>) -> Result<Self, Error> {
85 let num_commits: u64 = files.iter().map(|f| u64::from(f.num_commits())).sum();93 let num_commits: u64 = files.iter().map(|f| u64::from(f.num_commits())).sum();
86 if num_commits > u64::from(MAX_COMMITS) {94 if num_commits > u64::from(MAX_COMMITS) {
git-commitgraph/src/graph/verify.rs+2−0
@@ -10,7 +10,9 @@ use std::{ · 9 unmodified lines
10 path::PathBuf,10 path::PathBuf,
11};11};
12 12
13/// The error used in [`verify_integrity()`][Graph::verify_integrity].
13#[derive(thiserror::Error, Debug)]14#[derive(thiserror::Error, Debug)]
15#[allow(missing_docs)]
14pub enum Error<E: std::error::Error + 'static> {16pub enum Error<E: std::error::Error + 'static> {
15 #[error("'{}' should have {expected} base graphs, but claims {actual} base graphs", .path.display())]17 #[error("'{}' should have {expected} base graphs, but claims {actual} base graphs", .path.display())]
16 BaseGraphCount { actual: u8, expected: u8, path: PathBuf },18 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