Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Branch
- default
- Lint
No Linters Available - Unit
No Unit Test Coverage
( )
No Linters Available |
No Unit Test Coverage |
Path | Packages | |||
---|---|---|---|---|
M | rust/hg-core/src/operations/cat.rs (15 lines) | |||
M | tests/test-rhg.t (16 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
40f9965869d9 | 770fb8f683a0 | Antoine cezar | Oct 29 2020, 2:25 PM |
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::files::get_path_from_bytes; | use crate::utils::files::get_path_from_bytes; | ||||
use crate::utils::hg_path::{HgPath, HgPathBuf}; | use crate::utils::hg_path::{HgPath, 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. | ||||
store_path(self.root, manifest_file, b".d"); | store_path(self.root, manifest_file, b".d"); | ||||
let file_log = | let file_log = | ||||
Revlog::open(&index_path, Some(&data_path))?; | Revlog::open(&index_path, Some(&data_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 |