1 use crate::errors::HgError; |
1 use crate::errors::HgError; |
2 use crate::repo::Repo; |
2 use crate::repo::Repo; |
3 use crate::revlog::path_encode::path_encode; |
3 use crate::revlog::path_encode::path_encode; |
|
4 use crate::revlog::revlog::RevlogEntry; |
4 use crate::revlog::revlog::{Revlog, RevlogError}; |
5 use crate::revlog::revlog::{Revlog, RevlogError}; |
5 use crate::revlog::NodePrefix; |
6 use crate::revlog::NodePrefix; |
6 use crate::revlog::Revision; |
7 use crate::revlog::Revision; |
7 use crate::utils::files::get_path_from_bytes; |
8 use crate::utils::files::get_path_from_bytes; |
8 use crate::utils::hg_path::HgPath; |
9 use crate::utils::hg_path::HgPath; |
21 let data_path = store_path(file_path, b".d"); |
22 let data_path = store_path(file_path, b".d"); |
22 let revlog = Revlog::open(repo, index_path, Some(&data_path))?; |
23 let revlog = Revlog::open(repo, index_path, Some(&data_path))?; |
23 Ok(Self { revlog }) |
24 Ok(Self { revlog }) |
24 } |
25 } |
25 |
26 |
26 /// The given node ID is that of the file as found in a manifest, not of a |
27 /// The given node ID is that of the file as found in a filelog, not of a |
27 /// changeset. |
28 /// changeset. |
28 pub fn data_for_node( |
29 pub fn data_for_node( |
29 &self, |
30 &self, |
30 file_node: impl Into<NodePrefix>, |
31 file_node: impl Into<NodePrefix>, |
31 ) -> Result<FilelogRevisionData, RevlogError> { |
32 ) -> Result<FilelogRevisionData, RevlogError> { |
32 let file_rev = self.revlog.rev_from_node(file_node.into())?; |
33 let file_rev = self.revlog.rev_from_node(file_node.into())?; |
33 self.data_for_rev(file_rev) |
34 self.data_for_rev(file_rev) |
34 } |
35 } |
35 |
36 |
36 /// The given revision is that of the file as found in a manifest, not of a |
37 /// The given revision is that of the file as found in a filelog, not of a |
37 /// changeset. |
38 /// changeset. |
38 pub fn data_for_rev( |
39 pub fn data_for_rev( |
39 &self, |
40 &self, |
40 file_rev: Revision, |
41 file_rev: Revision, |
41 ) -> Result<FilelogRevisionData, RevlogError> { |
42 ) -> Result<FilelogRevisionData, RevlogError> { |
42 let data: Vec<u8> = self.revlog.get_rev_data(file_rev)?.into_owned(); |
43 let data: Vec<u8> = self.revlog.get_rev_data(file_rev)?.into_owned(); |
43 Ok(FilelogRevisionData(data.into())) |
44 Ok(FilelogRevisionData(data.into())) |
44 } |
45 } |
|
46 |
|
47 /// The given node ID is that of the file as found in a filelog, not of a |
|
48 /// changeset. |
|
49 pub fn entry_for_node( |
|
50 &self, |
|
51 file_node: impl Into<NodePrefix>, |
|
52 ) -> Result<FilelogEntry, RevlogError> { |
|
53 let file_rev = self.revlog.rev_from_node(file_node.into())?; |
|
54 self.entry_for_rev(file_rev) |
|
55 } |
|
56 |
|
57 /// The given revision is that of the file as found in a filelog, not of a |
|
58 /// changeset. |
|
59 pub fn entry_for_rev( |
|
60 &self, |
|
61 file_rev: Revision, |
|
62 ) -> Result<FilelogEntry, RevlogError> { |
|
63 Ok(FilelogEntry(self.revlog.get_entry(file_rev)?)) |
|
64 } |
45 } |
65 } |
46 |
66 |
47 fn store_path(hg_path: &HgPath, suffix: &[u8]) -> PathBuf { |
67 fn store_path(hg_path: &HgPath, suffix: &[u8]) -> PathBuf { |
48 let encoded_bytes = |
68 let encoded_bytes = |
49 path_encode(&[b"data/", hg_path.as_bytes(), suffix].concat()); |
69 path_encode(&[b"data/", hg_path.as_bytes(), suffix].concat()); |
50 get_path_from_bytes(&encoded_bytes).into() |
70 get_path_from_bytes(&encoded_bytes).into() |
|
71 } |
|
72 |
|
73 pub struct FilelogEntry<'a>(RevlogEntry<'a>); |
|
74 |
|
75 impl FilelogEntry<'_> { |
|
76 pub fn data(&self) -> Result<FilelogRevisionData, HgError> { |
|
77 Ok(FilelogRevisionData(self.0.data()?.into_owned())) |
|
78 } |
51 } |
79 } |
52 |
80 |
53 /// The data for one revision in a filelog, uncompressed and delta-resolved. |
81 /// The data for one revision in a filelog, uncompressed and delta-resolved. |
54 pub struct FilelogRevisionData(Vec<u8>); |
82 pub struct FilelogRevisionData(Vec<u8>); |
55 |
83 |