# HG changeset patch # User Arseniy Alekseyev # Date 1687774530 -3600 # Node ID a10d823a8e3d5fb17ed97011ef3b0657667b1cce # Parent bfbd84c57bda1d3f1d9be3da848ad921d99a0536 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. diff -r bfbd84c57bda -r a10d823a8e3d rust/hg-core/src/dirstate_tree/dirstate_map.rs --- 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; }); } diff -r bfbd84c57bda -r a10d823a8e3d tests/test-debug-rebuild-dirstate.t --- /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