##// END OF EJS Templates
censor: make rhg fall back to python when encountering a censored node...
Arseniy Alekseyev -
r50069:3f86ee42 default
parent child Browse files
Show More
@@ -42,6 +42,9 b' pub enum HgError {'
42 42 /// and syntax of each value.
43 43 #[from]
44 44 ConfigValueParseError(ConfigValueParseError),
45
46 /// Censored revision data.
47 CensoredNodeError,
45 48 }
46 49
47 50 /// Details about where an I/O error happened
@@ -101,6 +104,9 b' impl fmt::Display for HgError {'
101 104 HgError::UnsupportedFeature(explanation) => {
102 105 write!(f, "unsupported feature: {}", explanation)
103 106 }
107 HgError::CensoredNodeError => {
108 write!(f, "encountered a censored node")
109 }
104 110 HgError::ConfigValueParseError(error) => error.fmt(f),
105 111 }
106 112 }
@@ -95,7 +95,7 b" impl FilelogEntry<'_> {"
95 95 // Let’s call `file_data_len` what would be returned by
96 96 // `self.data().file_data().len()`.
97 97
98 if self.0.is_cencored() {
98 if self.0.is_censored() {
99 99 let file_data_len = 0;
100 100 return other_len != file_data_len;
101 101 }
@@ -378,7 +378,7 b" impl<'a> RevlogEntry<'a> {"
378 378 }
379 379 }
380 380
381 pub fn is_cencored(&self) -> bool {
381 pub fn is_censored(&self) -> bool {
382 382 (self.flags & REVISION_FLAG_CENSORED) != 0
383 383 }
384 384
@@ -389,7 +389,7 b" impl<'a> RevlogEntry<'a> {"
389 389 }
390 390
391 391 /// The data for this entry, after resolving deltas if any.
392 pub fn data(&self) -> Result<Cow<'a, [u8]>, HgError> {
392 pub fn rawdata(&self) -> Result<Cow<'a, [u8]>, HgError> {
393 393 let mut entry = self.clone();
394 394 let mut delta_chain = vec![];
395 395
@@ -414,6 +414,13 b" impl<'a> RevlogEntry<'a> {"
414 414 Revlog::build_data_from_deltas(entry, &delta_chain)?.into()
415 415 };
416 416
417 Ok(data)
418 }
419
420 fn check_data(
421 &self,
422 data: Cow<'a, [u8]>,
423 ) -> Result<Cow<'a, [u8]>, HgError> {
417 424 if self.revlog.check_hash(
418 425 self.p1,
419 426 self.p2,
@@ -426,6 +433,14 b" impl<'a> RevlogEntry<'a> {"
426 433 }
427 434 }
428 435
436 pub fn data(&self) -> Result<Cow<'a, [u8]>, HgError> {
437 let data = self.rawdata()?;
438 if self.is_censored() {
439 return Err(HgError::CensoredNodeError);
440 }
441 self.check_data(data)
442 }
443
429 444 /// Extract the data contained in the entry.
430 445 /// This may be a delta. (See `is_delta`.)
431 446 fn data_chunk(&self) -> Result<Cow<'a, [u8]>, HgError> {
@@ -73,6 +73,9 b' impl From<HgError> for CommandError {'
73 73 HgError::UnsupportedFeature(message) => {
74 74 CommandError::unsupported(message)
75 75 }
76 HgError::CensoredNodeError => {
77 CommandError::unsupported("Encountered a censored node")
78 }
76 79 HgError::Abort {
77 80 message,
78 81 detailed_exit_code,
@@ -10,10 +10,6 b''
10 10
11 11 #endif
12 12
13 $ cat >> $HGRCPATH <<EOF
14 > [extensions]
15 > censor=
16 > EOF
17 13 $ cp $HGRCPATH $HGRCPATH.orig
18 14
19 15 Create repo with unimpeachable content
@@ -81,7 +77,7 b' Censor revision with 2 offenses'
81 77 (this also tests file pattern matching: path relative to cwd case)
82 78
83 79 $ mkdir -p foo/bar/baz
84 $ hg --cwd foo/bar/baz censor -r $C2 -t "remove password" ../../../target
80 $ hg --config extensions.censor= --cwd foo/bar/baz censor -r $C2 -t "remove password" ../../../target
85 81 $ hg cat -r $H1 target | head -n 10
86 82 Tainted file is now sanitized
87 83 $ hg cat -r $H2 target | head -n 10
@@ -99,7 +95,7 b' Censor revision with 1 offense'
99 95
100 96 (this also tests file pattern matching: with 'path:' scheme)
101 97
102 $ hg --cwd foo/bar/baz censor -r $C1 path:target
98 $ hg --config extensions.censor= --cwd foo/bar/baz censor -r $C1 path:target
103 99 $ hg cat -r $H1 target | head -n 10
104 100 Tainted file is now sanitized
105 101 $ hg cat -r $H2 target | head -n 10
@@ -242,7 +238,7 b" with the file censored, but we can't cen"
242 238 $ echo 'advanced head H1' > target
243 239 $ hg ci -m 'advance head H1' target
244 240 $ H1=`hg id --debug -i`
245 $ hg censor -r $C3 target
241 $ hg --config extensions.censor= censor -r $C3 target
246 242 $ hg update -r $H2
247 243 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
248 244 $ hg merge -r $C3
@@ -254,14 +250,14 b' Revisions present in repository heads ma'
254 250
255 251 $ hg update -C -r $H2
256 252 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
257 $ hg censor -r $H2 target
253 $ hg --config extensions.censor= censor -r $H2 target
258 254 abort: cannot censor file in heads (78a8fc215e79)
259 255 (clean/delete and commit first)
260 256 [255]
261 257 $ echo 'twiddling thumbs' > bystander
262 258 $ hg ci -m 'bystander commit'
263 259 $ H2=`hg id --debug -i`
264 $ hg censor -r "$H2^" target
260 $ hg --config extensions.censor= censor -r "$H2^" target
265 261 abort: cannot censor file in heads (efbe78065929)
266 262 (clean/delete and commit first)
267 263 [255]
@@ -273,7 +269,7 b' Cannot censor working directory'
273 269 $ H2=`hg id --debug -i`
274 270 $ hg update -r "$H2^"
275 271 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
276 $ hg censor -r . target
272 $ hg --config extensions.censor= censor -r . target
277 273 abort: cannot censor working directory
278 274 (clean/delete/update first)
279 275 [255]
@@ -286,7 +282,7 b' Can re-add file after being deleted + ce'
286 282 $ hg rm target
287 283 $ hg ci -m 'delete target so it may be censored'
288 284 $ H2=`hg id --debug -i`
289 $ hg censor -r $C4 target
285 $ hg --config extensions.censor= censor -r $C4 target
290 286 $ hg cat -r $C4 target | head -n 10
291 287 $ hg cat -r "$H2^^" target | head -n 10
292 288 Tainted file now super sanitized
@@ -314,7 +310,7 b' Can censor after revlog has expanded to '
314 310 $ hg revert -r "$H2^" target
315 311 $ hg ci -m 'cleaned 100k passwords'
316 312 $ H2=`hg id --debug -i`
317 $ hg censor -r $C5 target
313 $ hg --config extensions.censor= censor -r $C5 target
318 314 $ hg cat -r $C5 target | head -n 10
319 315 $ hg cat -r $H2 target | head -n 10
320 316 fresh start
@@ -393,7 +389,7 b' Censored nodes can be pushed if they cen'
393 389 $ CLEANREV=$H2
394 390 $ hg cat -r $REV target | head -n 10
395 391 Passwords: hunter2hunter2
396 $ hg censor -r $REV target
392 $ hg --config extensions.censor= censor -r $REV target
397 393 $ hg cat -r $REV target | head -n 10
398 394 $ hg cat -r $CLEANREV target | head -n 10
399 395 Re-sanitized; nothing to see here
@@ -503,7 +499,7 b' Censored nodes can be imported on top of'
503 499 Can import bundle where first revision of a file is censored
504 500
505 501 $ hg init ../rinit
506 $ hg censor -r 0 target
502 $ hg --config extensions.censor= censor -r 0 target
507 503 $ hg bundle -r 0 --base null ../rinit/initbundle
508 504 1 changesets found
509 505 $ cd ../rinit
@@ -553,7 +549,7 b' Censor the file'
553 549
554 550 $ hg cat -r $B1 target | wc -l
555 551 *50002 (re)
556 $ hg censor -r $B1 target
552 $ hg --config extensions.censor= censor -r $B1 target
557 553 $ hg cat -r $B1 target | wc -l
558 554 *0 (re)
559 555
General Comments 0
You need to be logged in to leave comments. Login now