Patchwork D10712: tests: show that hg fails to rollback transaction on revlog split

login
register
mail settings
Submitter phabricator
Date May 16, 2021, 7:31 p.m.
Message ID <differential-rev-PHID-DREV-ik2qk4ii2kazsd7aokjq-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49032/
State Superseded
Headers show

Comments

phabricator - May 16, 2021, 7:31 p.m.
valentin.gatienbaron created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10712

AFFECTED FILES
  mercurial/transaction.py
  tests/test-transaction-rollback-on-revlog-split.t

CHANGE DETAILS




To: valentin.gatienbaron, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-transaction-rollback-on-revlog-split.t b/tests/test-transaction-rollback-on-revlog-split.t
new file mode 100644
--- /dev/null
+++ b/tests/test-transaction-rollback-on-revlog-split.t
@@ -0,0 +1,41 @@ 
+  $ hg init .
+
+Create a filelog smaller than revlog._maxinlinesize, but larger than
+a revlog index entry.
+
+  >>> import os
+  >>> open('file', 'wb').write(os.urandom(1000))
+  1000
+  $ hg commit -Aqm_
+
+Now make a transaction that makes the filelog go over _maxinlinesize,
+so we get a .d file, and make that transaction rollback:
+
+  $ cat > .hg/hgrc <<EOF
+  > [hooks]
+  > pretxnchangegroup = false
+  > pretxncommit = false
+  > EOF
+
+  >>> import os
+  >>> open('file', 'wb').write(os.urandom(300000))
+  300000
+
+  $ hg commit -m_
+  transaction abort!
+  rollback failed - please run hg recover
+  (failure reason: attempted to truncate data/file.i to 1065 bytes, but it was already 128 bytes)
+  abort: pretxncommit hook exited with status 1
+  [40]
+
+  $ cat .hg/store/journal | tr -s '\000' ' '
+  data/file.i 1065
+  data/file.d 0
+  data/file.i 0
+  00manifest.i 111
+  00changelog.i 122
+
+  $ hg recover
+  rolling back interrupted transaction
+  abort: attempted to truncate data/file.i to 1065 bytes, but it was already 128 bytes
+  [255]
diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -65,7 +65,7 @@ 
                     raise error.Abort(
                         _(
                             b"attempted to truncate %s to %d bytes, but it was "
-                            b"already %d bytes\n"
+                            b"already %d bytes"
                         )
                         % (f, o, fp.tell())
                     )