Mercurial > hg
comparison rust/hg-core/src/revlog/revlog.rs @ 45534:4f11a67a12fb
hg-core: add `Revlog.get_node_rev`
Find the revision of a node given its full hash.
Differential Revision: https://phab.mercurial-scm.org/D9012
author | Antoine Cezar <antoine.cezar@octobus.net> |
---|---|
date | Fri, 18 Sep 2020 16:52:08 +0200 |
parents | b0d6309ff50c |
children | 639f33f22faf |
comparison
equal
deleted
inserted
replaced
45533:89ac95bd4993 | 45534:4f11a67a12fb |
---|---|
75 | 75 |
76 Ok(Revlog { | 76 Ok(Revlog { |
77 index_bytes, | 77 index_bytes, |
78 data_bytes, | 78 data_bytes, |
79 }) | 79 }) |
80 } | |
81 | |
82 /// Return number of entries of the `Revlog`. | |
83 pub fn len(&self) -> usize { | |
84 self.index().len() | |
85 } | |
86 | |
87 /// Returns `true` if the `Revlog` has zero `entries`. | |
88 pub fn is_empty(&self) -> bool { | |
89 self.index().is_empty() | |
90 } | |
91 | |
92 /// Return the full data associated to a node. | |
93 #[timed] | |
94 pub fn get_node_rev(&self, node: &[u8]) -> Result<Revision, RevlogError> { | |
95 let index = self.index(); | |
96 // This is brute force. But it is fast enough for now. | |
97 // Optimization will come later. | |
98 for rev in (0..self.len() as Revision).rev() { | |
99 let index_entry = | |
100 index.get_entry(rev).ok_or(RevlogError::Corrupted)?; | |
101 if node == index_entry.hash() { | |
102 return Ok(rev); | |
103 } | |
104 } | |
105 Err(RevlogError::InvalidRevision) | |
80 } | 106 } |
81 | 107 |
82 /// Return the full data associated to a revision. | 108 /// Return the full data associated to a revision. |
83 /// | 109 /// |
84 /// All entries required to build the final data out of deltas will be | 110 /// All entries required to build the final data out of deltas will be |