Mercurial > public > mercurial-scm > hg-stable
diff rust/hg-core/src/repo.rs @ 48843: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 |
line wrap: on
line diff
--- a/rust/hg-core/src/repo.rs Wed Apr 13 14:46:22 2022 -0400 +++ b/rust/hg-core/src/repo.rs Thu Apr 21 14:47:13 2022 +0200 @@ -438,7 +438,8 @@ let uuid = self.dirstate_data_file_uuid.get_or_init(self)?; let mut uuid = uuid.as_ref(); let can_append = uuid.is_some(); - let (data, tree_metadata, append) = map.pack_v2(can_append)?; + let (data, tree_metadata, append, old_data_size) = + map.pack_v2(can_append)?; if !append { uuid = None } @@ -464,10 +465,19 @@ // returns `ErrorKind::AlreadyExists`? Collision chance of two // random IDs is one in 2**32 let mut file = options.open(&data_filename)?; - file.write_all(&data)?; - file.flush()?; - // TODO: use https://doc.rust-lang.org/std/io/trait.Seek.html#method.stream_position when we require Rust 1.51+ - file.seek(SeekFrom::Current(0)) + if data.is_empty() { + // If we're not appending anything, the data size is the + // same as in the previous docket. It is *not* the file + // length, since it could have garbage at the end. + // We don't have to worry about it when we do have data + // to append since we rewrite the root node in this case. + Ok(old_data_size as u64) + } else { + file.write_all(&data)?; + file.flush()?; + // TODO: use https://doc.rust-lang.org/std/io/trait.Seek.html#method.stream_position when we require Rust 1.51+ + file.seek(SeekFrom::Current(0)) + } })() .when_writing_file(&data_filename)?; DirstateDocket::serialize(