dirstate: avoid leaking disk space in `hg debugrebuilddirstate` stable
authorArseniy Alekseyev <aalekseyev@janestreet.com>
Mon, 26 Jun 2023 11:15:30 +0100
branchstable
changeset 50721 a10d823a8e3d
parent 50720 bfbd84c57bda
child 50722 7e5be4a7cda7
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.
rust/hg-core/src/dirstate_tree/dirstate_map.rs
tests/test-debug-rebuild-dirstate.t
--- 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