Mercurial > public > mercurial-scm > hg
comparison rust/hg-core/src/repo.rs @ 49145:dd2503a63d33 stable
rust-dirstate-v2: save proper data size if no new data on append
This is currently only triggered with the tests ran with `--rhg` without
`--rust`, by "luck", there probably always was something to write, like an
mtime when also using Rust extensions alongside `rhg`.
Differential Revision: https://phab.mercurial-scm.org/D12580
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Thu, 21 Apr 2022 14:47:13 +0200 |
parents | dd6b67d5c256 |
children | 802e2c25dab8 |
comparison
equal
deleted
inserted
replaced
49068:90e564882f07 | 49145:dd2503a63d33 |
---|---|
436 let parents = self.dirstate_parents()?; | 436 let parents = self.dirstate_parents()?; |
437 let packed_dirstate = if self.has_dirstate_v2() { | 437 let packed_dirstate = if self.has_dirstate_v2() { |
438 let uuid = self.dirstate_data_file_uuid.get_or_init(self)?; | 438 let uuid = self.dirstate_data_file_uuid.get_or_init(self)?; |
439 let mut uuid = uuid.as_ref(); | 439 let mut uuid = uuid.as_ref(); |
440 let can_append = uuid.is_some(); | 440 let can_append = uuid.is_some(); |
441 let (data, tree_metadata, append) = map.pack_v2(can_append)?; | 441 let (data, tree_metadata, append, old_data_size) = |
442 map.pack_v2(can_append)?; | |
442 if !append { | 443 if !append { |
443 uuid = None | 444 uuid = None |
444 } | 445 } |
445 let uuid = if let Some(uuid) = uuid { | 446 let uuid = if let Some(uuid) = uuid { |
446 std::str::from_utf8(uuid) | 447 std::str::from_utf8(uuid) |
462 let data_size = (|| { | 463 let data_size = (|| { |
463 // TODO: loop and try another random ID if !append and this | 464 // TODO: loop and try another random ID if !append and this |
464 // returns `ErrorKind::AlreadyExists`? Collision chance of two | 465 // returns `ErrorKind::AlreadyExists`? Collision chance of two |
465 // random IDs is one in 2**32 | 466 // random IDs is one in 2**32 |
466 let mut file = options.open(&data_filename)?; | 467 let mut file = options.open(&data_filename)?; |
467 file.write_all(&data)?; | 468 if data.is_empty() { |
468 file.flush()?; | 469 // If we're not appending anything, the data size is the |
469 // TODO: use https://doc.rust-lang.org/std/io/trait.Seek.html#method.stream_position when we require Rust 1.51+ | 470 // same as in the previous docket. It is *not* the file |
470 file.seek(SeekFrom::Current(0)) | 471 // length, since it could have garbage at the end. |
472 // We don't have to worry about it when we do have data | |
473 // to append since we rewrite the root node in this case. | |
474 Ok(old_data_size as u64) | |
475 } else { | |
476 file.write_all(&data)?; | |
477 file.flush()?; | |
478 // TODO: use https://doc.rust-lang.org/std/io/trait.Seek.html#method.stream_position when we require Rust 1.51+ | |
479 file.seek(SeekFrom::Current(0)) | |
480 } | |
471 })() | 481 })() |
472 .when_writing_file(&data_filename)?; | 482 .when_writing_file(&data_filename)?; |
473 DirstateDocket::serialize( | 483 DirstateDocket::serialize( |
474 parents, | 484 parents, |
475 tree_metadata, | 485 tree_metadata, |