Those methods and constants will be reused by another module.
Details
Details
Diff Detail
Diff Detail
- Repository
- rFBHGX Facebook Mercurial Extensions
- Lint
Lint Skipped - Unit
Unit Tests Skipped
| jsgf |
| Restricted Project |
Those methods and constants will be reused by another module.
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| A | M | rust/indexes/src/changelog_utils.rs (38 lines) | ||
| M | rust/indexes/src/lib.rs (1 line) | |||
| M | rust/indexes/src/nodemap.rs (29 lines) |
| // Copyright 2017 Facebook, Inc. | |||||
| // | |||||
| // This software may be used and distributed according to the terms of the | |||||
| // GNU General Public License version 2 or any later version. | |||||
| use std::u32; | |||||
| use radixbuf::key::KeyId; | |||||
| use radixbuf::errors as rerrors; | |||||
| /// See "index ng" comment in mercurial/revlog.py | |||||
| pub const CHANGELOG_ENTRY_SIZE: usize = 64; | |||||
| // Offsets of fields in a changelog entry | |||||
| pub const CHANGELOG_ENTRY_P1_OFFSET: usize = 24; | |||||
| pub const CHANGELOG_ENTRY_NODE_OFFSET: usize = 32; | |||||
| /// Return the minimal revision number the changelog.i does not have. | |||||
| pub fn changelog_end_rev<T: AsRef<[u8]>>(changelogi: &T) -> u32 { | |||||
| let changelogi = changelogi.as_ref(); | |||||
| let rev = changelogi.len() / CHANGELOG_ENTRY_SIZE; | |||||
| if rev > u32::MAX as usize { | |||||
| panic!("rev exceeds 32 bit integers") | |||||
| } | |||||
| rev as u32 | |||||
| } | |||||
| /// Helper method similar to `radixbuf::key::FixedKey::read`, but takes a revision number instead. | |||||
| pub fn rev_to_node<K: AsRef<[u8]>>(changelogi: &K, rev: KeyId) -> rerrors::Result<&[u8]> { | |||||
| let buf = changelogi.as_ref(); | |||||
| let rev_usize: usize = rev.into(); | |||||
| let start_pos = rev_usize * CHANGELOG_ENTRY_SIZE + CHANGELOG_ENTRY_NODE_OFFSET; | |||||
| let end_pos = start_pos + 20; | |||||
| if buf.len() < end_pos { | |||||
| Err(rerrors::ErrorKind::InvalidKeyId(rev).into()) | |||||
| } else { | |||||
| Ok(&buf[start_pos..end_pos]) | |||||
| } | |||||
| } | |||||
| // Copyright 2017 Facebook, Inc. | // Copyright 2017 Facebook, Inc. | ||||
| // | // | ||||
| // This software may be used and distributed according to the terms of the | // This software may be used and distributed according to the terms of the | ||||
| // GNU General Public License version 2 or any later version. | // GNU General Public License version 2 or any later version. | ||||
| extern crate python27_sys; | extern crate python27_sys; | ||||
| #[macro_use] | #[macro_use] | ||||
| extern crate cpython; | extern crate cpython; | ||||
| #[macro_use] | #[macro_use] | ||||
| extern crate error_chain; | extern crate error_chain; | ||||
| extern crate radixbuf; | extern crate radixbuf; | ||||
| pub mod errors; | pub mod errors; | ||||
| pub mod nodemap; | pub mod nodemap; | ||||
| mod changelog_utils; | |||||
| mod pybuf; | mod pybuf; | ||||
| #[allow(non_camel_case_types)] | #[allow(non_camel_case_types)] | ||||
| pub mod pyext; | pub mod pyext; | ||||
(driveby) You can use b'a' to get a character value as a u8. so b'a'...b'f' => ch - b'a',, etc