Mercurial > hg
changeset 50724:a10d823a8e3d stable
dirstate: avoid leaking disk space in `hg debugrebuilddirstate`
Before this MR running `hg debugrebuilddirstate` simply grows the dirstate
without bound, never shrinking it, because the unused bytes counter stays low,
even though the entirety of the file becomes unused.
author | Arseniy Alekseyev <aalekseyev@janestreet.com> |
---|---|
date | Mon, 26 Jun 2023 11:15:30 +0100 |
parents | bfbd84c57bda |
children | 7e5be4a7cda7 |
files | rust/hg-core/src/dirstate_tree/dirstate_map.rs tests/test-debug-rebuild-dirstate.t |
diffstat | 2 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs Mon Jun 26 11:21:43 2023 +0100 +++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs Mon Jun 26 11:15:30 2023 +0100 @@ -964,6 +964,7 @@ map.root = Default::default(); map.nodes_with_entry_count = 0; map.nodes_with_copy_source_count = 0; + map.unreachable_bytes = map.on_disk.len() as u32; }); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-debug-rebuild-dirstate.t Mon Jun 26 11:15:30 2023 +0100 @@ -0,0 +1,39 @@ +#require rust + + $ cat >> $HGRCPATH << EOF + > [format] + > use-dirstate-v2=1 + > [storage] + > dirstate-v2.slow-path=allow + > EOF + + $ hg init t + $ cd t + + $ for i in 1 2 3 4 5 6 7 8 9 10; do touch foobar$i; done + $ hg add . + adding foobar1 + adding foobar10 + adding foobar2 + adding foobar3 + adding foobar4 + adding foobar5 + adding foobar6 + adding foobar7 + adding foobar8 + adding foobar9 + $ hg commit -m "1" + +Check that there's no space leak on debugrebuilddirstate + + $ f --size .hg/dirstate* + .hg/dirstate: size=133 + .hg/dirstate.b870a51b: size=511 + $ hg debugrebuilddirstate + $ f --size .hg/dirstate* + .hg/dirstate: size=133 + .hg/dirstate.88698448: size=511 + $ hg debugrebuilddirstate + $ f --size .hg/dirstate* + .hg/dirstate: size=133 + .hg/dirstate.6b8ab34b: size=511