Show More
@@ -202,6 +202,16 b' dependencies = [' | |||
|
202 | 202 | ] |
|
203 | 203 | |
|
204 | 204 | [[package]] |
|
205 | name = "fuchsia-cprng" | |
|
206 | version = "0.1.1" | |
|
207 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
|
208 | ||
|
209 | [[package]] | |
|
210 | name = "gcc" | |
|
211 | version = "0.3.55" | |
|
212 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
|
213 | ||
|
214 | [[package]] | |
|
205 | 215 | name = "getrandom" |
|
206 | 216 | version = "0.1.15" |
|
207 | 217 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -249,6 +259,7 b' dependencies = [' | |||
|
249 | 259 | "rand_pcg 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", |
|
250 | 260 | "rayon 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", |
|
251 | 261 | "regex 1.3.9 (registry+https://github.com/rust-lang/crates.io-index)", |
|
262 | "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", | |
|
252 | 263 | "same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", |
|
253 | 264 | "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
|
254 | 265 | "twox-hash 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -461,6 +472,27 b' dependencies = [' | |||
|
461 | 472 | |
|
462 | 473 | [[package]] |
|
463 | 474 | name = "rand" |
|
475 | version = "0.3.23" | |
|
476 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
|
477 | dependencies = [ | |
|
478 | "libc 0.2.77 (registry+https://github.com/rust-lang/crates.io-index)", | |
|
479 | "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", | |
|
480 | ] | |
|
481 | ||
|
482 | [[package]] | |
|
483 | name = "rand" | |
|
484 | version = "0.4.6" | |
|
485 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
|
486 | dependencies = [ | |
|
487 | "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", | |
|
488 | "libc 0.2.77 (registry+https://github.com/rust-lang/crates.io-index)", | |
|
489 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", | |
|
490 | "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", | |
|
491 | "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", | |
|
492 | ] | |
|
493 | ||
|
494 | [[package]] | |
|
495 | name = "rand" | |
|
464 | 496 | version = "0.7.3" |
|
465 | 497 | source = "registry+https://github.com/rust-lang/crates.io-index" |
|
466 | 498 | dependencies = [ |
@@ -482,6 +514,19 b' dependencies = [' | |||
|
482 | 514 | |
|
483 | 515 | [[package]] |
|
484 | 516 | name = "rand_core" |
|
517 | version = "0.3.1" | |
|
518 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
|
519 | dependencies = [ | |
|
520 | "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", | |
|
521 | ] | |
|
522 | ||
|
523 | [[package]] | |
|
524 | name = "rand_core" | |
|
525 | version = "0.4.2" | |
|
526 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
|
527 | ||
|
528 | [[package]] | |
|
529 | name = "rand_core" | |
|
485 | 530 | version = "0.5.1" |
|
486 | 531 | source = "registry+https://github.com/rust-lang/crates.io-index" |
|
487 | 532 | dependencies = [ |
@@ -536,6 +581,14 b' dependencies = [' | |||
|
536 | 581 | ] |
|
537 | 582 | |
|
538 | 583 | [[package]] |
|
584 | name = "rdrand" | |
|
585 | version = "0.4.0" | |
|
586 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
|
587 | dependencies = [ | |
|
588 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", | |
|
589 | ] | |
|
590 | ||
|
591 | [[package]] | |
|
539 | 592 | name = "redox_syscall" |
|
540 | 593 | version = "0.1.57" |
|
541 | 594 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -576,6 +629,23 b' dependencies = [' | |||
|
576 | 629 | ] |
|
577 | 630 | |
|
578 | 631 | [[package]] |
|
632 | name = "rust-crypto" | |
|
633 | version = "0.2.36" | |
|
634 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
|
635 | dependencies = [ | |
|
636 | "gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)", | |
|
637 | "libc 0.2.77 (registry+https://github.com/rust-lang/crates.io-index)", | |
|
638 | "rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)", | |
|
639 | "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", | |
|
640 | "time 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)", | |
|
641 | ] | |
|
642 | ||
|
643 | [[package]] | |
|
644 | name = "rustc-serialize" | |
|
645 | version = "0.3.24" | |
|
646 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
|
647 | ||
|
648 | [[package]] | |
|
579 | 649 | name = "same-file" |
|
580 | 650 | version = "1.0.6" |
|
581 | 651 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -752,6 +822,8 b' dependencies = [' | |||
|
752 | 822 | "checksum either 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" |
|
753 | 823 | "checksum env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" |
|
754 | 824 | "checksum flate2 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "766d0e77a2c1502169d4a93ff3b8c15a71fd946cd0126309752104e5f3c46d94" |
|
825 | "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" | |
|
826 | "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" | |
|
755 | 827 | "checksum getrandom 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" |
|
756 | 828 | "checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" |
|
757 | 829 | "checksum hermit-abi 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c30f6d0bc6b00693347368a67d41b58f2fb851215ff1da49e90fe2c5c667151" |
@@ -781,18 +853,25 b' dependencies = [' | |||
|
781 | 853 | "checksum python3-sys 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90af11779515a1e530af60782d273b59ac79d33b0e253c071a728563957c76d4" |
|
782 | 854 | "checksum quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" |
|
783 | 855 | "checksum quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" |
|
856 | "checksum rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)" = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" | |
|
857 | "checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" | |
|
784 | 858 | "checksum rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" |
|
785 | 859 | "checksum rand_chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" |
|
860 | "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" | |
|
861 | "checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" | |
|
786 | 862 | "checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" |
|
787 | 863 | "checksum rand_distr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96977acbdd3a6576fb1d27391900035bf3863d4a16422973a409b488cf29ffb2" |
|
788 | 864 | "checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" |
|
789 | 865 | "checksum rand_pcg 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" |
|
790 | 866 | "checksum rayon 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cfd016f0c045ad38b5251be2c9c0ab806917f82da4d36b2a327e5166adad9270" |
|
791 | 867 | "checksum rayon-core 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e8c4fec834fb6e6d2dd5eece3c7b432a52f0ba887cf40e595190c4107edc08bf" |
|
868 | "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" | |
|
792 | 869 | "checksum redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)" = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" |
|
793 | 870 | "checksum regex 1.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" |
|
794 | 871 | "checksum regex-syntax 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)" = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" |
|
795 | 872 | "checksum remove_dir_all 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" |
|
873 | "checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" | |
|
874 | "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" | |
|
796 | 875 | "checksum same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" |
|
797 | 876 | "checksum scopeguard 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" |
|
798 | 877 | "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" |
@@ -25,6 +25,7 b' micro-timer = "0.3.0"' | |||
|
25 | 25 | log = "0.4.8" |
|
26 | 26 | memmap = "0.7.0" |
|
27 | 27 | zstd = "0.5.3" |
|
28 | rust-crypto = "0.2.36" | |
|
28 | 29 | |
|
29 | 30 | # We don't use the `miniz-oxide` backend because its minimum Rust version is |
|
30 | 31 | # `1.36`. However, this PR (https://github.com/Frommi/miniz_oxide/pull/84/files) |
@@ -5,6 +5,7 b'' | |||
|
5 | 5 | // This software may be used and distributed according to the terms of the |
|
6 | 6 | // GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | use crate::revlog::node::NULL_NODE_ID; | |
|
8 | 9 | use crate::{ |
|
9 | 10 | dirstate::{parsers::PARENT_SIZE, EntryState, SIZE_FROM_OTHER_PARENT}, |
|
10 | 11 | pack_dirstate, parse_dirstate, |
@@ -24,7 +25,6 b' use std::time::Duration;' | |||
|
24 | 25 | |
|
25 | 26 | pub type FileFoldMap = FastHashMap<HgPathBuf, HgPathBuf>; |
|
26 | 27 | |
|
27 | const NULL_ID: [u8; 20] = [0; 20]; | |
|
28 | 28 | const MTIME_UNSET: i32 = -1; |
|
29 | 29 | |
|
30 | 30 | #[derive(Default)] |
@@ -72,8 +72,8 b' impl DirstateMap {' | |||
|
72 | 72 | self.non_normal_set = None; |
|
73 | 73 | self.other_parent_set = None; |
|
74 | 74 | self.set_parents(&DirstateParents { |
|
75 | p1: NULL_ID, | |
|
76 | p2: NULL_ID, | |
|
75 | p1: NULL_NODE_ID, | |
|
76 | p2: NULL_NODE_ID, | |
|
77 | 77 | }) |
|
78 | 78 | } |
|
79 | 79 | |
@@ -340,8 +340,8 b' impl DirstateMap {' | |||
|
340 | 340 | }; |
|
341 | 341 | } else if file_contents.is_empty() { |
|
342 | 342 | parents = DirstateParents { |
|
343 | p1: NULL_ID, | |
|
344 | p2: NULL_ID, | |
|
343 | p1: NULL_NODE_ID, | |
|
344 | p2: NULL_NODE_ID, | |
|
345 | 345 | }; |
|
346 | 346 | } else { |
|
347 | 347 | return Err(DirstateError::Parse(DirstateParseError::Damaged)); |
@@ -1,5 +1,6 b'' | |||
|
1 | use byteorder::{BigEndian, ByteOrder}; | |
|
2 | ||
|
1 | 3 | use crate::revlog::{Revision, NULL_REVISION}; |
|
2 | use byteorder::{BigEndian, ByteOrder}; | |
|
3 | 4 | |
|
4 | 5 | pub const INDEX_ENTRY_SIZE: usize = 64; |
|
5 | 6 | |
@@ -141,6 +142,22 b" impl<'a> IndexEntry<'a> {" | |||
|
141 | 142 | |
|
142 | 143 | BigEndian::read_i32(&self.bytes[16..]) |
|
143 | 144 | } |
|
145 | ||
|
146 | pub fn p1(&self) -> Revision { | |
|
147 | BigEndian::read_i32(&self.bytes[24..]) | |
|
148 | } | |
|
149 | ||
|
150 | pub fn p2(&self) -> Revision { | |
|
151 | BigEndian::read_i32(&self.bytes[28..]) | |
|
152 | } | |
|
153 | ||
|
154 | /// Return the hash of revision's full text. | |
|
155 | /// | |
|
156 | /// Currently, SHA-1 is used and only the first 20 bytes of this field | |
|
157 | /// are used. | |
|
158 | pub fn hash(&self) -> &[u8] { | |
|
159 | &self.bytes[32..52] | |
|
160 | } | |
|
144 | 161 | } |
|
145 | 162 | |
|
146 | 163 | #[cfg(test)] |
@@ -16,7 +16,12 b' use hex::{self, FromHex, FromHexError};' | |||
|
16 | 16 | /// are private so that calling code does not expect all nodes have |
|
17 | 17 | /// the same size, should we support several formats concurrently in |
|
18 | 18 | /// the future. |
|
19 | const NODE_BYTES_LENGTH: usize = 20; | |
|
19 | pub const NODE_BYTES_LENGTH: usize = 20; | |
|
20 | ||
|
21 | /// Id of the null node. | |
|
22 | /// | |
|
23 | /// Used to indicate the absence of node. | |
|
24 | pub const NULL_NODE_ID: [u8; NODE_BYTES_LENGTH] = [0u8; NODE_BYTES_LENGTH]; | |
|
20 | 25 | |
|
21 | 26 | /// The length in bytes of a `Node` |
|
22 | 27 | /// |
@@ -5,12 +5,15 b' use std::ops::Deref;' | |||
|
5 | 5 | use std::path::Path; |
|
6 | 6 | |
|
7 | 7 | use byteorder::{BigEndian, ByteOrder}; |
|
8 | use crypto::digest::Digest; | |
|
9 | use crypto::sha1::Sha1; | |
|
8 | 10 | use flate2::read::ZlibDecoder; |
|
9 | 11 | use memmap::{Mmap, MmapOptions}; |
|
10 | 12 | use micro_timer::timed; |
|
11 | 13 | use zstd; |
|
12 | 14 | |
|
13 | 15 | use super::index::Index; |
|
16 | use super::node::{NODE_BYTES_LENGTH, NULL_NODE_ID}; | |
|
14 | 17 | use super::patch; |
|
15 | 18 | use crate::revlog::Revision; |
|
16 | 19 | |
@@ -93,13 +96,52 b' impl Revlog {' | |||
|
93 | 96 | .map_err(|_| RevlogError::Corrupted)?; |
|
94 | 97 | } |
|
95 | 98 | |
|
96 | if delta_chain.is_empty() { | |
|
97 | Ok(entry.data()?.into()) | |
|
99 | // TODO do not look twice in the index | |
|
100 | let index = self.index(); | |
|
101 | let index_entry = | |
|
102 | index.get_entry(rev).ok_or(RevlogError::InvalidRevision)?; | |
|
103 | ||
|
104 | let data: Vec<u8> = if delta_chain.is_empty() { | |
|
105 | entry.data()?.into() | |
|
106 | } else { | |
|
107 | Revlog::build_data_from_deltas(entry, &delta_chain)? | |
|
108 | }; | |
|
109 | ||
|
110 | if self.check_hash( | |
|
111 | index_entry.p1(), | |
|
112 | index_entry.p2(), | |
|
113 | index_entry.hash(), | |
|
114 | &data, | |
|
115 | ) { | |
|
116 | Ok(data) | |
|
98 | 117 | } else { |
|
99 | Revlog::build_data_from_deltas(entry, &delta_chain) | |
|
118 | Err(RevlogError::Corrupted) | |
|
100 | 119 | } |
|
101 | 120 | } |
|
102 | 121 | |
|
122 | /// Check the hash of some given data against the recorded hash. | |
|
123 | pub fn check_hash( | |
|
124 | &self, | |
|
125 | p1: Revision, | |
|
126 | p2: Revision, | |
|
127 | expected: &[u8], | |
|
128 | data: &[u8], | |
|
129 | ) -> bool { | |
|
130 | let index = self.index(); | |
|
131 | let e1 = index.get_entry(p1); | |
|
132 | let h1 = match e1 { | |
|
133 | Some(ref entry) => entry.hash(), | |
|
134 | None => &NULL_NODE_ID, | |
|
135 | }; | |
|
136 | let e2 = index.get_entry(p2); | |
|
137 | let h2 = match e2 { | |
|
138 | Some(ref entry) => entry.hash(), | |
|
139 | None => &NULL_NODE_ID, | |
|
140 | }; | |
|
141 | ||
|
142 | hash(data, &h1, &h2).as_slice() == expected | |
|
143 | } | |
|
144 | ||
|
103 | 145 | /// Build the full data of a revision out its snapshot |
|
104 | 146 | /// and its deltas. |
|
105 | 147 | #[timed] |
@@ -234,6 +276,23 b' pub fn get_version(index_bytes: &[u8]) -' | |||
|
234 | 276 | BigEndian::read_u16(&index_bytes[2..=3]) |
|
235 | 277 | } |
|
236 | 278 | |
|
279 | /// Calculate the hash of a revision given its data and its parents. | |
|
280 | fn hash(data: &[u8], p1_hash: &[u8], p2_hash: &[u8]) -> Vec<u8> { | |
|
281 | let mut hasher = Sha1::new(); | |
|
282 | let (a, b) = (p1_hash, p2_hash); | |
|
283 | if a > b { | |
|
284 | hasher.input(b); | |
|
285 | hasher.input(a); | |
|
286 | } else { | |
|
287 | hasher.input(a); | |
|
288 | hasher.input(b); | |
|
289 | } | |
|
290 | hasher.input(data); | |
|
291 | let mut hash = vec![0; NODE_BYTES_LENGTH]; | |
|
292 | hasher.result(&mut hash); | |
|
293 | hash | |
|
294 | } | |
|
295 | ||
|
237 | 296 | #[cfg(test)] |
|
238 | 297 | mod tests { |
|
239 | 298 | use super::*; |
General Comments 0
You need to be logged in to leave comments.
Login now