Showing the changes to git-commitgraph/src/file/access.rs (1 of 6 files). Show all
Unified · Split
| @@ -9,6 +9,7 @@ use std::{ · 8 unmodified lines | ||
| 9 | 9 | |
| 10 | 10 | /// Access |
| 11 | 11 | impl File { |
| 12 | + /// The amount of base graphs that this file depends on. | |
| 12 | 13 | pub fn base_graph_count(&self) -> u8 { |
| 13 | 14 | self.base_graph_count |
| 14 | 15 | } |
| @@ -24,6 +25,9 @@ impl File { · 9 unmodified lines | ||
| 24 | 25 | Commit::new(self, pos) |
| 25 | 26 | } |
| 26 | 27 | |
| 28 | + /// The kind of hash used in this File. | |
| 29 | + /// | |
| 30 | + /// Note that it is always conforming to the hash used in the owning repository. | |
| 27 | 31 | pub fn hash_kind(&self) -> HashKind { |
| 28 | 32 | HashKind::Sha1 |
| 29 | 33 | } |
| @@ -46,6 +50,7 @@ impl File { · 16 unmodified lines | ||
| 46 | 50 | borrowed::Id::try_from(&self.data[start..start + SHA1_SIZE]).expect("20 bytes SHA1 to be alright") |
| 47 | 51 | } |
| 48 | 52 | |
| 53 | + /// Return an iterator over all object hashes stored in the base graph. | |
| 49 | 54 | pub fn iter_base_graph_ids(&self) -> impl Iterator<Item = borrowed::Id<'_>> { |
| 50 | 55 | let start = self.base_graphs_list_offset.unwrap_or(0); |
| 51 | 56 | let base_graphs_list = &self.data[start..start + (SHA1_SIZE * usize::from(self.base_graph_count))]; |
| @@ -54,14 +59,17 @@ impl File { · 2 unmodified lines | ||
| 54 | 59 | .map(|bytes| borrowed::Id::try_from(bytes).expect("20 bytes SHA1 to be alright")) |
| 55 | 60 | } |
| 56 | 61 | |
| 62 | + /// return an iterator over all commits in this file. | |
| 57 | 63 | pub fn iter_commits(&self) -> impl Iterator<Item = Commit<'_>> { |
| 58 | 64 | (0..self.num_commits()).map(move |i| self.commit_at(file::Position(i))) |
| 59 | 65 | } |
| 60 | 66 | |
| 67 | + /// Return an iterator over all object hashes stored in this file. | |
| 61 | 68 | pub fn iter_ids(&self) -> impl Iterator<Item = borrowed::Id<'_>> { |
| 62 | 69 | (0..self.num_commits()).map(move |i| self.id_at(file::Position(i))) |
| 63 | 70 | } |
| 64 | 71 | |
| 72 | + /// Translate the given object hash to its position within this file, if present. | |
| 65 | 73 | // copied from git-odb/src/pack/index/access.rs |
| 66 | 74 | pub fn lookup(&self, id: borrowed::Id<'_>) -> Option<file::Position> { |
| 67 | 75 | let first_byte = usize::from(id.first_byte()); |
| @@ -94,6 +102,7 @@ impl File { · 26 unmodified lines | ||
| 94 | 102 | self.fan[255] |
| 95 | 103 | } |
| 96 | 104 | |
| 105 | + /// Returns the path to this file. | |
| 97 | 106 | pub fn path(&self) -> &Path { |
| 98 | 107 | &self.path |
| 99 | 108 | } |