Show More
@@ -101,7 +101,7 b" pub fn cat<'a>(" | |||||
101 | let file_log = repo.filelog(file_path)?; |
|
101 | let file_log = repo.filelog(file_path)?; | |
102 | results.push(( |
|
102 | results.push(( | |
103 | file_path, |
|
103 | file_path, | |
104 | file_log.data_for_node(file_node)?.into_data()?, |
|
104 | file_log.data_for_node(file_node)?.into_file_data()?, | |
105 | )); |
|
105 | )); | |
106 | } |
|
106 | } | |
107 |
|
107 |
@@ -22,7 +22,7 b' impl Changelog {' | |||||
22 | pub fn data_for_node( |
|
22 | pub fn data_for_node( | |
23 | &self, |
|
23 | &self, | |
24 | node: NodePrefix, |
|
24 | node: NodePrefix, | |
25 |
) -> Result<Changelog |
|
25 | ) -> Result<ChangelogRevisionData, RevlogError> { | |
26 | let rev = self.revlog.rev_from_node(node)?; |
|
26 | let rev = self.revlog.rev_from_node(node)?; | |
27 | self.data_for_rev(rev) |
|
27 | self.data_for_rev(rev) | |
28 | } |
|
28 | } | |
@@ -31,9 +31,9 b' impl Changelog {' | |||||
31 | pub fn data_for_rev( |
|
31 | pub fn data_for_rev( | |
32 | &self, |
|
32 | &self, | |
33 | rev: Revision, |
|
33 | rev: Revision, | |
34 |
) -> Result<Changelog |
|
34 | ) -> Result<ChangelogRevisionData, RevlogError> { | |
35 | let bytes = self.revlog.get_rev_data(rev)?; |
|
35 | let bytes = self.revlog.get_rev_data(rev)?; | |
36 |
Ok(Changelog |
|
36 | Ok(ChangelogRevisionData { bytes }) | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | pub fn node_from_rev(&self, rev: Revision) -> Option<&Node> { |
|
39 | pub fn node_from_rev(&self, rev: Revision) -> Option<&Node> { | |
@@ -43,12 +43,12 b' impl Changelog {' | |||||
43 |
|
43 | |||
44 | /// `Changelog` entry which knows how to interpret the `changelog` data bytes. |
|
44 | /// `Changelog` entry which knows how to interpret the `changelog` data bytes. | |
45 | #[derive(Debug)] |
|
45 | #[derive(Debug)] | |
46 |
pub struct Changelog |
|
46 | pub struct ChangelogRevisionData { | |
47 | /// The data bytes of the `changelog` entry. |
|
47 | /// The data bytes of the `changelog` entry. | |
48 | bytes: Vec<u8>, |
|
48 | bytes: Vec<u8>, | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 |
impl Changelog |
|
51 | impl ChangelogRevisionData { | |
52 | /// Return an iterator over the lines of the entry. |
|
52 | /// Return an iterator over the lines of the entry. | |
53 | pub fn lines(&self) -> impl Iterator<Item = &[u8]> { |
|
53 | pub fn lines(&self) -> impl Iterator<Item = &[u8]> { | |
54 | self.bytes |
|
54 | self.bytes |
@@ -28,7 +28,7 b' impl Filelog {' | |||||
28 | pub fn data_for_node( |
|
28 | pub fn data_for_node( | |
29 | &self, |
|
29 | &self, | |
30 | file_node: impl Into<NodePrefix>, |
|
30 | file_node: impl Into<NodePrefix>, | |
31 |
) -> Result<Filelog |
|
31 | ) -> Result<FilelogRevisionData, RevlogError> { | |
32 | let file_rev = self.revlog.rev_from_node(file_node.into())?; |
|
32 | let file_rev = self.revlog.rev_from_node(file_node.into())?; | |
33 | self.data_for_rev(file_rev) |
|
33 | self.data_for_rev(file_rev) | |
34 | } |
|
34 | } | |
@@ -38,9 +38,9 b' impl Filelog {' | |||||
38 | pub fn data_for_rev( |
|
38 | pub fn data_for_rev( | |
39 | &self, |
|
39 | &self, | |
40 | file_rev: Revision, |
|
40 | file_rev: Revision, | |
41 |
) -> Result<Filelog |
|
41 | ) -> Result<FilelogRevisionData, RevlogError> { | |
42 | let data: Vec<u8> = self.revlog.get_rev_data(file_rev)?; |
|
42 | let data: Vec<u8> = self.revlog.get_rev_data(file_rev)?; | |
43 |
Ok(Filelog |
|
43 | Ok(FilelogRevisionData(data.into())) | |
44 | } |
|
44 | } | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
@@ -50,9 +50,10 b' fn store_path(hg_path: &HgPath, suffix: ' | |||||
50 | get_path_from_bytes(&encoded_bytes).into() |
|
50 | get_path_from_bytes(&encoded_bytes).into() | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | pub struct FilelogEntry(Vec<u8>); |
|
53 | /// The data for one revision in a filelog, uncompressed and delta-resolved. | |
|
54 | pub struct FilelogRevisionData(Vec<u8>); | |||
54 |
|
55 | |||
55 |
impl Filelog |
|
56 | impl FilelogRevisionData { | |
56 | /// Split into metadata and data |
|
57 | /// Split into metadata and data | |
57 | pub fn split(&self) -> Result<(Option<&[u8]>, &[u8]), HgError> { |
|
58 | pub fn split(&self) -> Result<(Option<&[u8]>, &[u8]), HgError> { | |
58 | const DELIMITER: &[u8; 2] = &[b'\x01', b'\n']; |
|
59 | const DELIMITER: &[u8; 2] = &[b'\x01', b'\n']; | |
@@ -71,14 +72,14 b' impl FilelogEntry {' | |||||
71 | } |
|
72 | } | |
72 |
|
73 | |||
73 | /// Returns the file contents at this revision, stripped of any metadata |
|
74 | /// Returns the file contents at this revision, stripped of any metadata | |
74 | pub fn data(&self) -> Result<&[u8], HgError> { |
|
75 | pub fn file_data(&self) -> Result<&[u8], HgError> { | |
75 | let (_metadata, data) = self.split()?; |
|
76 | let (_metadata, data) = self.split()?; | |
76 | Ok(data) |
|
77 | Ok(data) | |
77 | } |
|
78 | } | |
78 |
|
79 | |||
79 | /// Consume the entry, and convert it into data, discarding any metadata, |
|
80 | /// Consume the entry, and convert it into data, discarding any metadata, | |
80 | /// if present. |
|
81 | /// if present. | |
81 | pub fn into_data(self) -> Result<Vec<u8>, HgError> { |
|
82 | pub fn into_file_data(self) -> Result<Vec<u8>, HgError> { | |
82 | if let (Some(_metadata), data) = self.split()? { |
|
83 | if let (Some(_metadata), data) = self.split()? { | |
83 | Ok(data.to_owned()) |
|
84 | Ok(data.to_owned()) | |
84 | } else { |
|
85 | } else { |
@@ -214,7 +214,7 b' impl Revlog {' | |||||
214 | .ok_or(RevlogError::InvalidRevision)?; |
|
214 | .ok_or(RevlogError::InvalidRevision)?; | |
215 |
|
215 | |||
216 | let data: Vec<u8> = if delta_chain.is_empty() { |
|
216 | let data: Vec<u8> = if delta_chain.is_empty() { | |
217 | entry.data()?.into() |
|
217 | entry.data_chunk()?.into() | |
218 | } else { |
|
218 | } else { | |
219 | Revlog::build_data_from_deltas(entry, &delta_chain)? |
|
219 | Revlog::build_data_from_deltas(entry, &delta_chain)? | |
220 | }; |
|
220 | }; | |
@@ -260,11 +260,11 b' impl Revlog {' | |||||
260 | snapshot: RevlogEntry, |
|
260 | snapshot: RevlogEntry, | |
261 | deltas: &[RevlogEntry], |
|
261 | deltas: &[RevlogEntry], | |
262 | ) -> Result<Vec<u8>, RevlogError> { |
|
262 | ) -> Result<Vec<u8>, RevlogError> { | |
263 | let snapshot = snapshot.data()?; |
|
263 | let snapshot = snapshot.data_chunk()?; | |
264 | let deltas = deltas |
|
264 | let deltas = deltas | |
265 | .iter() |
|
265 | .iter() | |
266 | .rev() |
|
266 | .rev() | |
267 | .map(RevlogEntry::data) |
|
267 | .map(RevlogEntry::data_chunk) | |
268 | .collect::<Result<Vec<Cow<'_, [u8]>>, RevlogError>>()?; |
|
268 | .collect::<Result<Vec<Cow<'_, [u8]>>, RevlogError>>()?; | |
269 | let patches: Vec<_> = |
|
269 | let patches: Vec<_> = | |
270 | deltas.iter().map(|d| patch::PatchList::new(d)).collect(); |
|
270 | deltas.iter().map(|d| patch::PatchList::new(d)).collect(); | |
@@ -339,7 +339,8 b" impl<'a> RevlogEntry<'a> {" | |||||
339 | } |
|
339 | } | |
340 |
|
340 | |||
341 | /// Extract the data contained in the entry. |
|
341 | /// Extract the data contained in the entry. | |
342 | pub fn data(&self) -> Result<Cow<'_, [u8]>, RevlogError> { |
|
342 | /// This may be a delta. (See `is_delta`.) | |
|
343 | fn data_chunk(&self) -> Result<Cow<'_, [u8]>, RevlogError> { | |||
343 | if self.bytes.is_empty() { |
|
344 | if self.bytes.is_empty() { | |
344 | return Ok(Cow::Borrowed(&[])); |
|
345 | return Ok(Cow::Borrowed(&[])); | |
345 | } |
|
346 | } |
@@ -522,7 +522,7 b' fn unsure_is_modified(' | |||||
522 | filelog.data_for_node(entry.node_id()?).map_err(|_| { |
|
522 | filelog.data_for_node(entry.node_id()?).map_err(|_| { | |
523 | HgError::corrupted("filelog missing node from manifest") |
|
523 | HgError::corrupted("filelog missing node from manifest") | |
524 | })?; |
|
524 | })?; | |
525 | let contents_in_p1 = filelog_entry.data()?; |
|
525 | let contents_in_p1 = filelog_entry.file_data()?; | |
526 | if contents_in_p1.len() as u64 != fs_len { |
|
526 | if contents_in_p1.len() as u64 != fs_len { | |
527 | // No need to read the file contents: |
|
527 | // No need to read the file contents: | |
528 | // it cannot be equal if it has a different length. |
|
528 | // it cannot be equal if it has a different length. |
General Comments 0
You need to be logged in to leave comments.
Login now