Mercurial > hg
diff rust/hg-core/src/operations/cat.rs @ 45804:6991f3014311
rhg: strip copied files metadata from `cat` output
Differential Revision: https://phab.mercurial-scm.org/D9264
author | Antoine cezar<acezar@chwitlabs.fr> |
---|---|
date | Thu, 29 Oct 2020 19:25:33 +0100 |
parents | 522ec3dc44b9 |
children | 7252f5237352 |
line wrap: on
line diff
--- a/rust/hg-core/src/operations/cat.rs Mon Nov 02 14:39:43 2020 -0500 +++ b/rust/hg-core/src/operations/cat.rs Thu Oct 29 19:25:33 2020 +0100 @@ -16,6 +16,8 @@ use crate::revlog::Revision; use crate::utils::hg_path::HgPathBuf; +const METADATA_DELIMITER: [u8; 2] = [b'\x01', b'\n']; + /// Kind of error encountered by `CatRev` #[derive(Debug)] pub enum CatRevErrorKind { @@ -132,7 +134,18 @@ .map_err(|_| CatRevErrorKind::CorruptedRevlog)?; let file_rev = file_log.get_node_rev(&file_node)?; let data = file_log.get_rev_data(file_rev)?; - bytes.extend(data); + 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); + } } } }