Show More
@@ -4,7 +4,7 b' use crate::revlog::{Node, NodePrefix};' | |||||
4 | use crate::revlog::{Revlog, RevlogEntry, RevlogError}; |
|
4 | use crate::revlog::{Revlog, RevlogEntry, RevlogError}; | |
5 | use crate::utils::hg_path::HgPath; |
|
5 | use crate::utils::hg_path::HgPath; | |
6 | use crate::vfs::Vfs; |
|
6 | use crate::vfs::Vfs; | |
7 | use crate::UncheckedRevision; |
|
7 | use crate::{Graph, GraphError, UncheckedRevision}; | |
8 | use itertools::Itertools; |
|
8 | use itertools::Itertools; | |
9 | use std::ascii::escape_default; |
|
9 | use std::ascii::escape_default; | |
10 | use std::borrow::Cow; |
|
10 | use std::borrow::Cow; | |
@@ -76,6 +76,12 b' impl Changelog {' | |||||
76 | } |
|
76 | } | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
|
79 | impl Graph for Changelog { | |||
|
80 | fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { | |||
|
81 | self.revlog.parents(rev) | |||
|
82 | } | |||
|
83 | } | |||
|
84 | ||||
79 | /// A specialized `RevlogEntry` for `changelog` data format |
|
85 | /// A specialized `RevlogEntry` for `changelog` data format | |
80 | /// |
|
86 | /// | |
81 | /// This is a `RevlogEntry` with the added semantics that the associated |
|
87 | /// This is a `RevlogEntry` with the added semantics that the associated |
@@ -9,6 +9,8 b' use crate::revlog::{Revlog, RevlogError}' | |||||
9 | use crate::utils::files::get_path_from_bytes; |
|
9 | use crate::utils::files::get_path_from_bytes; | |
10 | use crate::utils::hg_path::HgPath; |
|
10 | use crate::utils::hg_path::HgPath; | |
11 | use crate::utils::SliceExt; |
|
11 | use crate::utils::SliceExt; | |
|
12 | use crate::Graph; | |||
|
13 | use crate::GraphError; | |||
12 | use crate::UncheckedRevision; |
|
14 | use crate::UncheckedRevision; | |
13 | use std::path::PathBuf; |
|
15 | use std::path::PathBuf; | |
14 |
|
16 | |||
@@ -18,6 +20,12 b' pub struct Filelog {' | |||||
18 | revlog: Revlog, |
|
20 | revlog: Revlog, | |
19 | } |
|
21 | } | |
20 |
|
22 | |||
|
23 | impl Graph for Filelog { | |||
|
24 | fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { | |||
|
25 | self.revlog.parents(rev) | |||
|
26 | } | |||
|
27 | } | |||
|
28 | ||||
21 | impl Filelog { |
|
29 | impl Filelog { | |
22 | pub fn open_vfs( |
|
30 | pub fn open_vfs( | |
23 | store_vfs: &crate::vfs::Vfs<'_>, |
|
31 | store_vfs: &crate::vfs::Vfs<'_>, |
@@ -6,7 +6,7 b' use byteorder::{BigEndian, ByteOrder};' | |||||
6 | use crate::errors::HgError; |
|
6 | use crate::errors::HgError; | |
7 | use crate::revlog::node::Node; |
|
7 | use crate::revlog::node::Node; | |
8 | use crate::revlog::{Revision, NULL_REVISION}; |
|
8 | use crate::revlog::{Revision, NULL_REVISION}; | |
9 | use crate::UncheckedRevision; |
|
9 | use crate::{Graph, GraphError, RevlogIndex, UncheckedRevision}; | |
10 |
|
10 | |||
11 | pub const INDEX_ENTRY_SIZE: usize = 64; |
|
11 | pub const INDEX_ENTRY_SIZE: usize = 64; | |
12 |
|
12 | |||
@@ -97,6 +97,23 b' impl Debug for Index {' | |||||
97 | } |
|
97 | } | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
|
100 | impl Graph for Index { | |||
|
101 | fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { | |||
|
102 | let err = || GraphError::ParentOutOfRange(rev); | |||
|
103 | match self.get_entry(rev) { | |||
|
104 | Some(entry) => { | |||
|
105 | // The C implementation checks that the parents are valid | |||
|
106 | // before returning | |||
|
107 | Ok([ | |||
|
108 | self.check_revision(entry.p1()).ok_or_else(err)?, | |||
|
109 | self.check_revision(entry.p2()).ok_or_else(err)?, | |||
|
110 | ]) | |||
|
111 | } | |||
|
112 | None => Ok([NULL_REVISION, NULL_REVISION]), | |||
|
113 | } | |||
|
114 | } | |||
|
115 | } | |||
|
116 | ||||
100 | impl Index { |
|
117 | impl Index { | |
101 | /// Create an index from bytes. |
|
118 | /// Create an index from bytes. | |
102 | /// Calculate the start of each entry when is_inline is true. |
|
119 | /// Calculate the start of each entry when is_inline is true. |
@@ -4,7 +4,7 b' use crate::revlog::{Revlog, RevlogError}' | |||||
4 | use crate::utils::hg_path::HgPath; |
|
4 | use crate::utils::hg_path::HgPath; | |
5 | use crate::utils::SliceExt; |
|
5 | use crate::utils::SliceExt; | |
6 | use crate::vfs::Vfs; |
|
6 | use crate::vfs::Vfs; | |
7 | use crate::{Revision, UncheckedRevision}; |
|
7 | use crate::{Graph, GraphError, Revision, UncheckedRevision}; | |
8 |
|
8 | |||
9 | /// A specialized `Revlog` to work with `manifest` data format. |
|
9 | /// A specialized `Revlog` to work with `manifest` data format. | |
10 | pub struct Manifestlog { |
|
10 | pub struct Manifestlog { | |
@@ -12,6 +12,12 b' pub struct Manifestlog {' | |||||
12 | revlog: Revlog, |
|
12 | revlog: Revlog, | |
13 | } |
|
13 | } | |
14 |
|
14 | |||
|
15 | impl Graph for Manifestlog { | |||
|
16 | fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { | |||
|
17 | self.revlog.parents(rev) | |||
|
18 | } | |||
|
19 | } | |||
|
20 | ||||
15 | impl Manifestlog { |
|
21 | impl Manifestlog { | |
16 | /// Open the `manifest` of a repository given by its root. |
|
22 | /// Open the `manifest` of a repository given by its root. | |
17 | pub fn open(store_vfs: &Vfs, use_nodemap: bool) -> Result<Self, HgError> { |
|
23 | pub fn open(store_vfs: &Vfs, use_nodemap: bool) -> Result<Self, HgError> { |
@@ -182,6 +182,12 b' pub struct Revlog {' | |||||
182 | nodemap: Option<nodemap::NodeTree>, |
|
182 | nodemap: Option<nodemap::NodeTree>, | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
|
185 | impl Graph for Revlog { | |||
|
186 | fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> { | |||
|
187 | self.index.parents(rev) | |||
|
188 | } | |||
|
189 | } | |||
|
190 | ||||
185 | impl Revlog { |
|
191 | impl Revlog { | |
186 | /// Open a revlog index file. |
|
192 | /// Open a revlog index file. | |
187 | /// |
|
193 | /// |
General Comments 0
You need to be logged in to leave comments.
Login now