# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1701479603 -3600
#      Sat Dec 02 02:13:23 2023 +0100
# Branch stable
# Node ID 3e2a878fb96f5d3d16214f0e4925bd5cadbd6e43
# Parent  e9eac01c57f3872cff1376631ce66844a625f4cd
censor: fix things around inlining

The temporary revlog cannot go through the inline → split process as this would
break at transaction commit.  (that might be fixable, but lets keep things
simple for now). We introduce a cleaner way to enforce this as the previous one
was broken in 6.6

On the way we remove multiple weird, fragile and broken overwrite of revlog
attributes and we focus on passing the configuration across.

We also had to update the test to actually create a non-inline revlog.

diff --git a/mercurial/revlogutils/rewrite.py b/mercurial/revlogutils/rewrite.py
--- a/mercurial/revlogutils/rewrite.py
+++ b/mercurial/revlogutils/rewrite.py
@@ -72,11 +72,16 @@
         radix=rl.radix,
         postfix=b'tmpcensored',
         censorable=True,
+        data_config=rl.data_config,
+        delta_config=rl.delta_config,
+        feature_config=rl.feature_config,
+        may_inline=rl._inline,
     )
-    newrl._format_version = rl._format_version
-    newrl._format_flags = rl._format_flags
-    newrl.delta_config.general_delta = rl.delta_config.general_delta
-    newrl._parse_index = rl._parse_index
+    # inline splitting will prepare some transaction work that will get
+    # confused by the final file move. So if there is a risk of not being
+    # inline at the end, we prevent the new revlog to be inline in the first
+    # place.
+    assert not (newrl._inline and not rl._inline)
 
     for rev in rl.revs():
         node = rl.node(rev)
@@ -122,7 +127,10 @@
         tr.addbackup(rl._datafile, location=b'store')
 
     rl.opener.rename(newrl._indexfile, rl._indexfile)
-    if not rl._inline:
+    if newrl._inline:
+        assert rl._inline
+    else:
+        assert not rl._inline
         rl.opener.rename(newrl._datafile, rl._datafile)
 
     rl.clearcaches()
diff --git a/tests/test-censor.t b/tests/test-censor.t
--- a/tests/test-censor.t
+++ b/tests/test-censor.t
@@ -298,12 +298,9 @@
 
   $ hg debugrevlogstats | grep target
   rev-count   data-size inl type      target 
-          8   ????????? no  file      target (glob) (revlogv2 !)
-          8   ????????? yes file      target (glob) (revlogv1 !)
-  $ for x in `"$PYTHON" $TESTDIR/seq.py 0 50000`
-  > do
-  >   echo "Password: hunter$x" >> target
-  > done
+          8         ??? no  file      target (glob) (revlogv2 !)
+          8         ??? yes file      target (glob) (revlogv1 !)
+  $ cat /dev/rand?m | dd status=none count=200 | f --hexdump > target
   $ hg ci -m 'add 100k passwords'
   $ H2=`hg id --debug -i`
   $ C5=$H2
@@ -312,17 +309,25 @@
   $ H2=`hg id --debug -i`
   $ hg debugrevlogstats | grep target
   rev-count   data-size inl type      target 
-         10   ????????? no  file      target (glob) (revlogv2 !)
-         10   ????????? no  file      target (glob) (missing-correct-output revlogv1 !)
-         10   ????????? yes file      target (glob) (known-bad-output revlogv1 !)
+         10      ?????? no  file      target (glob)
   $ hg --config extensions.censor= censor -r $C5 target
+
+The important part is for the censor operation to not crash and the repository
+to not be corrupted.  Right now this involve keeping the revlog split.
+
   $ hg debugrevlogstats | grep target
   rev-count   data-size inl type      target 
-         10   ????????? no  file      target (glob) (revlogv2 !)
-         10   ????????? yes file      target (glob) (revlogv1 !)
+         10         ??? no  file      target (glob)
   $ hg cat -r $C5 target | head -n 10
   $ hg cat -r $H2 target | head -n 10
   fresh start
+  $ hg verify
+  checking changesets
+  checking manifests
+  crosschecking files in changesets and manifests
+  checking files
+  checking dirstate
+  checked 12 changesets with 13 changes to 2 files
 
 Repo with censored nodes can be cloned and cloned nodes are censored
 
@@ -354,7 +359,7 @@
   adding manifests
   adding file changes
   added 11 changesets with 11 changes to 2 files (+1 heads)
-  new changesets 186fb27560c3:683e4645fded
+  new changesets * (glob)
   (run 'hg heads' to see heads, 'hg merge' to merge)
   $ hg update 4
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -414,7 +419,7 @@
   adding manifests
   adding file changes
   added 2 changesets with 2 changes to 2 files (+1 heads)
-  new changesets 075be80ac777:dcbaf17bf3a1 (2 drafts)
+  new changesets * (glob)
   (run 'hg heads .' to see heads, 'hg merge' to merge)
   $ hg cat -r $REV target | head -n 10
   $ hg cat -r $CLEANREV target | head -n 10
@@ -471,7 +476,7 @@
   adding manifests
   adding file changes
   added 6 changesets with 5 changes to 2 files (+1 heads)
-  new changesets efbe78065929:683e4645fded (6 drafts)
+  new changesets * (glob)
   (run 'hg heads .' to see heads, 'hg merge' to merge)
   $ hg update $H2
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved