Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Automatic diff as part of commit; lint not applicable. - Unit
Automatic diff as part of commit; unit tests not applicable.
( )
| Automatic diff as part of commit; lint not applicable. |
| Automatic diff as part of commit; unit tests not applicable. |
| use crate::revlog::changelog::Changelog; | use crate::revlog::changelog::Changelog; | ||||
| use crate::revlog::manifest::{Manifest, ManifestEntry}; | use crate::revlog::manifest::{Manifest, ManifestEntry}; | ||||
| use crate::revlog::path_encode::path_encode; | use crate::revlog::path_encode::path_encode; | ||||
| use crate::revlog::revlog::Revlog; | use crate::revlog::revlog::Revlog; | ||||
| use crate::revlog::revlog::RevlogError; | use crate::revlog::revlog::RevlogError; | ||||
| use crate::revlog::Revision; | use crate::revlog::Revision; | ||||
| use crate::utils::hg_path::HgPathBuf; | use crate::utils::hg_path::HgPathBuf; | ||||
| const METADATA_DELIMITER: [u8; 2] = [b'\x01', b'\n']; | |||||
| /// Kind of error encountered by `CatRev` | /// Kind of error encountered by `CatRev` | ||||
| #[derive(Debug)] | #[derive(Debug)] | ||||
| pub enum CatRevErrorKind { | pub enum CatRevErrorKind { | ||||
| /// Error when reading a `revlog` file. | /// Error when reading a `revlog` file. | ||||
| IoError(std::io::Error), | IoError(std::io::Error), | ||||
| /// The revision has not been found. | /// The revision has not been found. | ||||
| InvalidRevision, | InvalidRevision, | ||||
| /// A `revlog` file is corrupted. | /// A `revlog` file is corrupted. | ||||
| ); | ); | ||||
| let revlog_index_path = | let revlog_index_path = | ||||
| self.root.join(&revlog_index_string); | self.root.join(&revlog_index_string); | ||||
| let file_log = Revlog::open(&revlog_index_path)?; | let file_log = Revlog::open(&revlog_index_path)?; | ||||
| let file_node = hex::decode(&node_bytes) | let file_node = hex::decode(&node_bytes) | ||||
| .map_err(|_| CatRevErrorKind::CorruptedRevlog)?; | .map_err(|_| CatRevErrorKind::CorruptedRevlog)?; | ||||
| let file_rev = file_log.get_node_rev(&file_node)?; | let file_rev = file_log.get_node_rev(&file_node)?; | ||||
| let data = file_log.get_rev_data(file_rev)?; | let data = file_log.get_rev_data(file_rev)?; | ||||
| if data.starts_with(&METADATA_DELIMITER) { | |||||
| let end_delimiter_position = data | |||||
| [METADATA_DELIMITER.len()..] | |||||
| .windows(METADATA_DELIMITER.len()) | |||||
| .position(|bytes| bytes == METADATA_DELIMITER); | |||||
| if let Some(position) = end_delimiter_position { | |||||
| let offset = METADATA_DELIMITER.len() * 2; | |||||
| bytes.extend(data[position + offset..].iter()); | |||||
| } | |||||
| } else { | |||||
| bytes.extend(data); | bytes.extend(data); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| Ok(bytes) | Ok(bytes) | ||||
| } else { | } else { | ||||
| unreachable!("manifest_entry should have been stored"); | unreachable!("manifest_entry should have been stored"); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| 0 0 | 0 0 | ||||
| file3 | file3 | ||||
| commit 3 (no-eol) | commit 3 (no-eol) | ||||
| $ rhg debugdata -m 2 | $ rhg debugdata -m 2 | ||||
| file1\x00b8e02f6433738021a065f94175c7cd23db5f05be (esc) | file1\x00b8e02f6433738021a065f94175c7cd23db5f05be (esc) | ||||
| file2\x005d9299349fc01ddd25d0070d149b124d8f10411e (esc) | file2\x005d9299349fc01ddd25d0070d149b124d8f10411e (esc) | ||||
| file3\x002661d26c649684b482d10f91960cc3db683c38b4 (esc) | file3\x002661d26c649684b482d10f91960cc3db683c38b4 (esc) | ||||
| Cat files | |||||
| $ cd $TESTTMP | |||||
| $ rm -rf repository | |||||
| $ hg init repository | |||||
| $ cd repository | |||||
| $ echo "original content" > original | |||||
| $ hg add original | |||||
| $ hg commit -m "add original" original | |||||
| $ rhg cat -r 0 original | |||||
| original content | |||||
| Cat copied file should not display copy metadata | |||||
| $ hg copy original copy_of_original | |||||
| $ hg commit -m "add copy of original" | |||||
| $ rhg cat -r 1 copy_of_original | |||||
| original content | |||||