Mercurial > hg
annotate rust/hg-core/src/revlog/path_encode.rs @ 46033:88e741bf2d93
rust: use NodePrefix::from_hex instead of hex::decode directly
This adds support for prefixes with an odd number of hex digits.
Differential Revision: https://phab.mercurial-scm.org/D9490
author | Simon Sapin <simon-commits@exyr.org> |
---|---|
date | Wed, 02 Dec 2020 15:00:49 +0100 |
parents | aebc976fd7d5 |
children | fad504cfc94b |
rev | line source |
---|---|
45539
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1 use crypto::digest::Digest; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
2 use crypto::sha1::Sha1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
3 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
4 #[derive(PartialEq, Debug)] |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
5 #[allow(non_camel_case_types)] |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
6 enum path_state { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
7 START, /* first byte of a path component */ |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
8 A, /* "AUX" */ |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
9 AU, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
10 THIRD, /* third of a 3-byte sequence, e.g. "AUX", "NUL" */ |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
11 C, /* "CON" or "COMn" */ |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
12 CO, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
13 COMLPT, /* "COM" or "LPT" */ |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
14 COMLPTn, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
15 L, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
16 LP, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
17 N, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
18 NU, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
19 P, /* "PRN" */ |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
20 PR, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
21 LDOT, /* leading '.' */ |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
22 DOT, /* '.' in a non-leading position */ |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
23 H, /* ".h" */ |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
24 HGDI, /* ".hg", ".d", or ".i" */ |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
25 SPACE, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
26 DEFAULT, /* byte of a path component after the first */ |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
27 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
28 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
29 /* state machine for dir-encoding */ |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
30 #[allow(non_camel_case_types)] |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
31 enum dir_state { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
32 DDOT, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
33 DH, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
34 DHGDI, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
35 DDEFAULT, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
36 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
37 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
38 fn inset(bitset: &[u32; 8], c: u8) -> bool { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
39 bitset[(c as usize) >> 5] & (1 << (c & 31)) != 0 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
40 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
41 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
42 fn charcopy(dest: Option<&mut [u8]>, destlen: &mut usize, c: u8) { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
43 if let Some(slice) = dest { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
44 slice[*destlen] = c |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
45 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
46 *destlen += 1 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
47 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
48 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
49 fn memcopy(dest: Option<&mut [u8]>, destlen: &mut usize, src: &[u8]) { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
50 if let Some(slice) = dest { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
51 slice[*destlen..*destlen + src.len()].copy_from_slice(src) |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
52 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
53 *destlen += src.len(); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
54 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
55 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
56 fn rewrap_option<'a, 'b: 'a>( |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
57 x: &'a mut Option<&'b mut [u8]>, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
58 ) -> Option<&'a mut [u8]> { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
59 match x { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
60 None => None, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
61 Some(y) => Some(y), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
62 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
63 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
64 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
65 fn hexencode<'a>(mut dest: Option<&'a mut [u8]>, destlen: &mut usize, c: u8) { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
66 let hexdigit = b"0123456789abcdef"; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
67 charcopy( |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
68 rewrap_option(&mut dest), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
69 destlen, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
70 hexdigit[(c as usize) >> 4], |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
71 ); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
72 charcopy(dest, destlen, hexdigit[(c as usize) & 15]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
73 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
74 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
75 /* 3-byte escape: tilde followed by two hex digits */ |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
76 fn escape3(mut dest: Option<&mut [u8]>, destlen: &mut usize, c: u8) { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
77 charcopy(rewrap_option(&mut dest), destlen, b'~'); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
78 hexencode(dest, destlen, c); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
79 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
80 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
81 fn encode_dir(mut dest: Option<&mut [u8]>, src: &[u8]) -> usize { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
82 let mut state = dir_state::DDEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
83 let mut i = 0; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
84 let mut destlen = 0; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
85 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
86 while i < src.len() { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
87 match state { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
88 dir_state::DDOT => match src[i] { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
89 b'd' | b'i' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
90 state = dir_state::DHGDI; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
91 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
92 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
93 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
94 b'h' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
95 state = dir_state::DH; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
96 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
97 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
98 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
99 _ => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
100 state = dir_state::DDEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
101 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
102 }, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
103 dir_state::DH => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
104 if src[i] == b'g' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
105 state = dir_state::DHGDI; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
106 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
107 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
108 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
109 state = dir_state::DDEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
110 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
111 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
112 dir_state::DHGDI => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
113 if src[i] == b'/' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
114 memcopy(rewrap_option(&mut dest), &mut destlen, b".hg"); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
115 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
116 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
117 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
118 state = dir_state::DDEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
119 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
120 dir_state::DDEFAULT => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
121 if src[i] == b'.' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
122 state = dir_state::DDOT |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
123 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
124 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
125 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
126 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
127 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
128 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
129 destlen |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
130 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
131 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
132 fn _encode( |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
133 twobytes: &[u32; 8], |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
134 onebyte: &[u32; 8], |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
135 mut dest: Option<&mut [u8]>, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
136 src: &[u8], |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
137 encodedir: bool, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
138 ) -> usize { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
139 let mut state = path_state::START; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
140 let mut i = 0; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
141 let mut destlen = 0; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
142 let len = src.len(); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
143 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
144 while i < len { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
145 match state { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
146 path_state::START => match src[i] { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
147 b'/' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
148 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
149 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
150 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
151 b'.' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
152 state = path_state::LDOT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
153 escape3(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
154 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
155 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
156 b' ' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
157 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
158 escape3(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
159 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
160 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
161 b'a' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
162 state = path_state::A; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
163 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
164 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
165 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
166 b'c' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
167 state = path_state::C; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
168 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
169 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
170 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
171 b'l' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
172 state = path_state::L; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
173 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
174 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
175 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
176 b'n' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
177 state = path_state::N; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
178 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
179 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
180 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
181 b'p' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
182 state = path_state::P; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
183 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
184 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
185 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
186 _ => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
187 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
188 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
189 }, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
190 path_state::A => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
191 if src[i] == b'u' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
192 state = path_state::AU; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
193 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
194 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
195 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
196 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
197 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
198 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
199 path_state::AU => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
200 if src[i] == b'x' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
201 state = path_state::THIRD; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
202 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
203 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
204 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
205 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
206 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
207 path_state::THIRD => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
208 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
209 match src[i] { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
210 b'.' | b'/' | b'\0' => escape3( |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
211 rewrap_option(&mut dest), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
212 &mut destlen, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
213 src[i - 1], |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
214 ), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
215 _ => i -= 1, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
216 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
217 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
218 path_state::C => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
219 if src[i] == b'o' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
220 state = path_state::CO; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
221 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
222 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
223 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
224 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
225 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
226 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
227 path_state::CO => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
228 if src[i] == b'm' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
229 state = path_state::COMLPT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
230 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
231 } else if src[i] == b'n' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
232 state = path_state::THIRD; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
233 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
234 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
235 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
236 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
237 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
238 path_state::COMLPT => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
239 if src[i] >= b'1' && src[i] <= b'9' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
240 state = path_state::COMLPTn; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
241 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
242 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
243 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
244 charcopy( |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
245 rewrap_option(&mut dest), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
246 &mut destlen, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
247 src[i - 1], |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
248 ); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
249 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
250 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
251 path_state::COMLPTn => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
252 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
253 match src[i] { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
254 b'.' | b'/' | b'\0' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
255 escape3( |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
256 rewrap_option(&mut dest), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
257 &mut destlen, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
258 src[i - 2], |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
259 ); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
260 charcopy( |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
261 rewrap_option(&mut dest), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
262 &mut destlen, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
263 src[i - 1], |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
264 ); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
265 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
266 _ => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
267 memcopy( |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
268 rewrap_option(&mut dest), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
269 &mut destlen, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
270 &src[i - 2..i], |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
271 ); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
272 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
273 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
274 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
275 path_state::L => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
276 if src[i] == b'p' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
277 state = path_state::LP; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
278 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
279 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
280 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
281 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
282 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
283 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
284 path_state::LP => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
285 if src[i] == b't' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
286 state = path_state::COMLPT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
287 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
288 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
289 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
290 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
291 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
292 path_state::N => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
293 if src[i] == b'u' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
294 state = path_state::NU; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
295 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
296 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
297 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
298 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
299 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
300 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
301 path_state::NU => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
302 if src[i] == b'l' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
303 state = path_state::THIRD; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
304 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
305 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
306 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
307 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
308 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
309 path_state::P => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
310 if src[i] == b'r' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
311 state = path_state::PR; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
312 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
313 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
314 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
315 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
316 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
317 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
318 path_state::PR => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
319 if src[i] == b'n' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
320 state = path_state::THIRD; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
321 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
322 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
323 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
324 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
325 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
326 path_state::LDOT => match src[i] { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
327 b'd' | b'i' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
328 state = path_state::HGDI; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
329 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
330 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
331 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
332 b'h' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
333 state = path_state::H; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
334 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
335 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
336 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
337 _ => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
338 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
339 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
340 }, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
341 path_state::DOT => match src[i] { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
342 b'/' | b'\0' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
343 state = path_state::START; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
344 memcopy(rewrap_option(&mut dest), &mut destlen, b"~2e"); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
345 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
346 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
347 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
348 b'd' | b'i' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
349 state = path_state::HGDI; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
350 charcopy(rewrap_option(&mut dest), &mut destlen, b'.'); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
351 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
352 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
353 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
354 b'h' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
355 state = path_state::H; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
356 memcopy(rewrap_option(&mut dest), &mut destlen, b".h"); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
357 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
358 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
359 _ => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
360 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
361 charcopy(rewrap_option(&mut dest), &mut destlen, b'.'); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
362 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
363 }, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
364 path_state::H => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
365 if src[i] == b'g' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
366 state = path_state::HGDI; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
367 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
368 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
369 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
370 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
371 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
372 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
373 path_state::HGDI => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
374 if src[i] == b'/' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
375 state = path_state::START; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
376 if encodedir { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
377 memcopy( |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
378 rewrap_option(&mut dest), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
379 &mut destlen, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
380 b".hg", |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
381 ); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
382 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
383 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
384 i += 1 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
385 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
386 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
387 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
388 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
389 path_state::SPACE => match src[i] { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
390 b'/' | b'\0' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
391 state = path_state::START; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
392 memcopy(rewrap_option(&mut dest), &mut destlen, b"~20"); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
393 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
394 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
395 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
396 _ => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
397 state = path_state::DEFAULT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
398 charcopy(rewrap_option(&mut dest), &mut destlen, b' '); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
399 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
400 }, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
401 path_state::DEFAULT => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
402 while i != len && inset(onebyte, src[i]) { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
403 charcopy(rewrap_option(&mut dest), &mut destlen, src[i]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
404 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
405 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
406 if i == len { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
407 break; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
408 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
409 match src[i] { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
410 b'.' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
411 state = path_state::DOT; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
412 i += 1 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
413 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
414 b' ' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
415 state = path_state::SPACE; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
416 i += 1 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
417 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
418 b'/' => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
419 state = path_state::START; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
420 charcopy(rewrap_option(&mut dest), &mut destlen, b'/'); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
421 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
422 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
423 _ => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
424 if inset(onebyte, src[i]) { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
425 loop { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
426 charcopy( |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
427 rewrap_option(&mut dest), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
428 &mut destlen, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
429 src[i], |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
430 ); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
431 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
432 if !(i < len && inset(onebyte, src[i])) { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
433 break; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
434 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
435 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
436 } else if inset(twobytes, src[i]) { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
437 let c = src[i]; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
438 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
439 charcopy( |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
440 rewrap_option(&mut dest), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
441 &mut destlen, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
442 b'_', |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
443 ); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
444 charcopy( |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
445 rewrap_option(&mut dest), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
446 &mut destlen, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
447 if c == b'_' { b'_' } else { c + 32 }, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
448 ); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
449 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
450 escape3( |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
451 rewrap_option(&mut dest), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
452 &mut destlen, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
453 src[i], |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
454 ); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
455 i += 1; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
456 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
457 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
458 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
459 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
460 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
461 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
462 match state { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
463 path_state::START => (), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
464 path_state::A => (), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
465 path_state::AU => (), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
466 path_state::THIRD => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
467 escape3(rewrap_option(&mut dest), &mut destlen, src[i - 1]) |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
468 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
469 path_state::C => (), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
470 path_state::CO => (), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
471 path_state::COMLPT => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
472 charcopy(rewrap_option(&mut dest), &mut destlen, src[i - 1]) |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
473 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
474 path_state::COMLPTn => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
475 escape3(rewrap_option(&mut dest), &mut destlen, src[i - 2]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
476 charcopy(rewrap_option(&mut dest), &mut destlen, src[i - 1]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
477 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
478 path_state::L => (), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
479 path_state::LP => (), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
480 path_state::N => (), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
481 path_state::NU => (), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
482 path_state::P => (), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
483 path_state::PR => (), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
484 path_state::LDOT => (), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
485 path_state::DOT => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
486 memcopy(rewrap_option(&mut dest), &mut destlen, b"~2e"); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
487 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
488 path_state::H => (), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
489 path_state::HGDI => (), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
490 path_state::SPACE => { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
491 memcopy(rewrap_option(&mut dest), &mut destlen, b"~20"); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
492 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
493 path_state::DEFAULT => (), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
494 }; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
495 destlen |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
496 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
497 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
498 fn basic_encode(dest: Option<&mut [u8]>, src: &[u8]) -> usize { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
499 let twobytes: [u32; 8] = [0, 0, 0x87ff_fffe, 0, 0, 0, 0, 0]; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
500 let onebyte: [u32; 8] = |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
501 [1, 0x2bff_3bfa, 0x6800_0001, 0x2fff_ffff, 0, 0, 0, 0]; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
502 _encode(&twobytes, &onebyte, dest, src, true) |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
503 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
504 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
505 const MAXSTOREPATHLEN: usize = 120; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
506 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
507 fn lower_encode(mut dest: Option<&mut [u8]>, src: &[u8]) -> usize { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
508 let onebyte: [u32; 8] = |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
509 [1, 0x2bff_fbfb, 0xe800_0001, 0x2fff_ffff, 0, 0, 0, 0]; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
510 let lower: [u32; 8] = [0, 0, 0x07ff_fffe, 0, 0, 0, 0, 0]; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
511 let mut destlen = 0; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
512 for c in src { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
513 if inset(&onebyte, *c) { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
514 charcopy(rewrap_option(&mut dest), &mut destlen, *c) |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
515 } else if inset(&lower, *c) { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
516 charcopy(rewrap_option(&mut dest), &mut destlen, *c + 32) |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
517 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
518 escape3(rewrap_option(&mut dest), &mut destlen, *c) |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
519 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
520 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
521 destlen |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
522 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
523 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
524 fn aux_encode(dest: Option<&mut [u8]>, src: &[u8]) -> usize { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
525 let twobytes = [0; 8]; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
526 let onebyte: [u32; 8] = [!0, 0xffff_3ffe, !0, !0, !0, !0, !0, !0]; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
527 _encode(&twobytes, &onebyte, dest, src, false) |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
528 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
529 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
530 fn hash_mangle(src: &[u8], sha: &[u8]) -> Vec<u8> { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
531 let dirprefixlen = 8; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
532 let maxshortdirslen = 68; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
533 let mut destlen = 0; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
534 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
535 let last_slash = src.iter().rposition(|b| *b == b'/'); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
536 let last_dot: Option<usize> = { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
537 let s = last_slash.unwrap_or(0); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
538 src[s..] |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
539 .iter() |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
540 .rposition(|b| *b == b'.') |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
541 .and_then(|i| Some(i + s)) |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
542 }; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
543 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
544 let mut dest = vec![0; MAXSTOREPATHLEN]; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
545 memcopy(Some(&mut dest), &mut destlen, b"dh/"); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
546 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
547 { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
548 let mut first = true; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
549 for slice in src[..last_slash.unwrap_or_else(|| src.len())] |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
550 .split(|b| *b == b'/') |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
551 { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
552 let slice = &slice[..std::cmp::min(slice.len(), dirprefixlen)]; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
553 if destlen + (slice.len() + if first { 0 } else { 1 }) |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
554 > maxshortdirslen + 3 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
555 { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
556 break; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
557 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
558 if !first { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
559 charcopy(Some(&mut dest), &mut destlen, b'/') |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
560 }; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
561 memcopy(Some(&mut dest), &mut destlen, slice); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
562 if dest[destlen - 1] == b'.' || dest[destlen - 1] == b' ' { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
563 dest[destlen - 1] = b'_' |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
564 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
565 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
566 first = false; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
567 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
568 if !first { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
569 charcopy(Some(&mut dest), &mut destlen, b'/'); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
570 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
571 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
572 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
573 let used = destlen + 40 + { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
574 if let Some(l) = last_dot { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
575 src.len() - l |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
576 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
577 0 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
578 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
579 }; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
580 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
581 if MAXSTOREPATHLEN > used { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
582 let slop = MAXSTOREPATHLEN - used; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
583 let basenamelen = match last_slash { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
584 Some(l) => src.len() - l - 1, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
585 None => src.len(), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
586 }; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
587 let basenamelen = std::cmp::min(basenamelen, slop); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
588 if basenamelen > 0 { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
589 let start = match last_slash { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
590 Some(l) => l + 1, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
591 None => 0, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
592 }; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
593 memcopy( |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
594 Some(&mut dest), |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
595 &mut destlen, |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
596 &src[start..][..basenamelen], |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
597 ) |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
598 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
599 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
600 for c in sha { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
601 hexencode(Some(&mut dest), &mut destlen, *c); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
602 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
603 if let Some(l) = last_dot { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
604 memcopy(Some(&mut dest), &mut destlen, &src[l..]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
605 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
606 if destlen == dest.len() { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
607 dest |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
608 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
609 // sometimes the path are shorter than MAXSTOREPATHLEN |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
610 dest[..destlen].to_vec() |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
611 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
612 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
613 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
614 const MAXENCODE: usize = 4096 * 4; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
615 fn hash_encode(src: &[u8]) -> Vec<u8> { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
616 let dired = &mut [0; MAXENCODE]; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
617 let lowered = &mut [0; MAXENCODE]; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
618 let auxed = &mut [0; MAXENCODE]; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
619 let baselen = (src.len() - 5) * 3; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
620 if baselen >= MAXENCODE { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
621 panic!("path_encode::hash_encore: string too long: {}", baselen) |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
622 }; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
623 let dirlen = encode_dir(Some(&mut dired[..]), src); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
624 let sha = { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
625 let mut hasher = Sha1::new(); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
626 hasher.input(&dired[..dirlen]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
627 let mut hash = vec![0; 20]; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
628 hasher.result(&mut hash); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
629 hash |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
630 }; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
631 let lowerlen = lower_encode(Some(&mut lowered[..]), &dired[..dirlen][5..]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
632 let auxlen = aux_encode(Some(&mut auxed[..]), &lowered[..lowerlen]); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
633 hash_mangle(&auxed[..auxlen], &sha) |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
634 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
635 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
636 pub fn path_encode(path: &[u8]) -> Vec<u8> { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
637 let newlen = if path.len() <= MAXSTOREPATHLEN { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
638 basic_encode(None, path) |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
639 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
640 MAXSTOREPATHLEN + 1 |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
641 }; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
642 if newlen <= MAXSTOREPATHLEN { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
643 if newlen == path.len() { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
644 path.to_vec() |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
645 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
646 let mut res = vec![0; newlen]; |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
647 basic_encode(Some(&mut res), path); |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
648 res |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
649 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
650 } else { |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
651 hash_encode(&path) |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
652 } |
aebc976fd7d5
hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
653 } |