Mercurial > hg
view tests/test-removeemptydirs.t @ 46607:e9901d01d135
revlog: add a mechanism to verify expected file position before appending
If someone uses `hg debuglocks`, or some non-hg process writes to the .hg
directory without respecting the locks, or if the repo's on a networked
filesystem, it's possible for the revlog code to write out corrupted data.
The form of this corruption can vary depending on what data was written and how
that happened. We are in the "networked filesystem" case (though I've had users
also do this to themselves with the "`hg debuglocks`" scenario), and most often
see this with the changelog. What ends up happening is we produce two items
(let's call them rev1 and rev2) in the .i file that have the same linkrev,
baserev, and offset into the .d file, while the data in the .d file is appended
properly. rev2's compressed_size is accurate for rev2, but when we go to
decompress the data in the .d file, we use the offset that's recorded in the
index file, which is the same as rev1, and attempt to decompress
rev2.compressed_size bytes of rev1's data. This usually does not succeed. :)
When using inline data, this also fails, though I haven't investigated why too
closely. This shows up as a "patch decode" error. I believe what's happening
there is that we're basically ignoring the offset field, getting the data
properly, but since baserev != rev, it thinks this is a delta based on rev
(instead of a full text) and can't actually apply it as such.
For now, I'm going to make this an optional component and default it to entirely
off. I may increase the default severity of this in the future, once I've
enabled it for my users and we gain more experience with it. Luckily, most of my
users have a versioned filesystem and can roll back to before the corruption has
been written, it's just a hassle to do so and not everyone knows how (so it's a
support burden). Users on other filesystems will not have that luxury, and this
can cause them to have a corrupted repository that they are unlikely to know how
to resolve, and they'll see this as a data-loss event. Refusing to create the
corruption is a much better user experience.
This mechanism is not perfect. There may be false-negatives (racy writes that
are not detected). There should not be any false-positives (non-racy writes that
are detected as such). This is not a mechanism that makes putting a repo on a
networked filesystem "safe" or "supported", just *less* likely to cause
corruption.
Differential Revision: https://phab.mercurial-scm.org/D9952
author | Kyle Lippincott <spectral@google.com> |
---|---|
date | Wed, 03 Feb 2021 16:33:10 -0800 |
parents | 42e2c7c52e1b |
children | e9fbf8fd5f33 |
line wrap: on
line source
Tests for experimental.removeemptydirs $ NO_RM=--config=experimental.removeemptydirs=0 $ isdir() { if [ -d $1 ]; then echo yes; else echo no; fi } $ isfile() { if [ -f $1 ]; then echo yes; else echo no; fi } `hg rm` of the last file in a directory: $ hg init hgrm $ cd hgrm $ mkdir somedir $ echo hi > somedir/foo $ hg ci -qAm foo $ isdir somedir yes $ hg rm somedir/foo $ isdir somedir no $ hg revert -qa $ isdir somedir yes $ hg $NO_RM rm somedir/foo $ isdir somedir yes $ ls somedir $ cd $TESTTMP `hg mv` of the last file in a directory: $ hg init hgmv $ cd hgmv $ mkdir somedir $ mkdir destdir $ echo hi > somedir/foo $ hg ci -qAm foo $ isdir somedir yes $ hg mv somedir/foo destdir/foo $ isdir somedir no $ hg revert -qa (revert doesn't get rid of destdir/foo?) $ rm destdir/foo $ isdir somedir yes $ hg $NO_RM mv somedir/foo destdir/foo $ isdir somedir yes $ ls somedir $ cd $TESTTMP Updating to a commit that doesn't have the directory: $ hg init hgupdate $ cd hgupdate $ echo hi > r0 $ hg ci -qAm r0 $ mkdir somedir $ echo hi > somedir/foo $ hg ci -qAm r1 $ isdir somedir yes $ hg co -q -r ".^" $ isdir somedir no $ hg co -q tip $ isdir somedir yes $ hg $NO_RM co -q -r ".^" $ isdir somedir yes $ ls somedir $ cd $TESTTMP Rebasing across a commit that doesn't have the directory, from inside the directory: $ hg init hgrebase $ cd hgrebase $ echo hi > r0 $ hg ci -qAm r0 $ mkdir somedir $ echo hi > somedir/foo $ hg ci -qAm first_rebase_source $ hg $NO_RM co -q -r ".^" $ echo hi > somedir/bar $ hg ci -qAm first_rebase_dest $ hg $NO_RM co -q -r ".^" $ echo hi > somedir/baz $ hg ci -qAm second_rebase_dest $ hg co -qr 'desc(first_rebase_source)' $ cd $TESTTMP/hgrebase/somedir $ hg --config extensions.rebase= rebase -qr . -d 'desc(first_rebase_dest)' current directory was removed (rmcwd !) (consider changing to repo root: $TESTTMP/hgrebase) (rmcwd !) $ cd $TESTTMP/hgrebase/somedir (The current node is the rebased first_rebase_source on top of first_rebase_dest) This should not output anything about current directory being removed: $ hg $NO_RM --config extensions.rebase= rebase -qr . -d 'desc(second_rebase_dest)' $ cd $TESTTMP Histediting across a commit that doesn't have the directory, from inside the directory (reordering nodes): $ hg init hghistedit $ cd hghistedit $ echo hi > r0 $ hg ci -qAm r0 $ echo hi > r1 $ hg ci -qAm r1 $ echo hi > r2 $ hg ci -qAm r2 $ mkdir somedir $ echo hi > somedir/foo $ hg ci -qAm migrating_revision $ cat > histedit_commands <<EOF > pick 89079fab8aee 0 r0 > pick e6d271df3142 1 r1 > pick 89e25aa83f0f 3 migrating_revision > pick b550aa12d873 2 r2 > EOF $ cd $TESTTMP/hghistedit/somedir $ hg --config extensions.histedit= histedit -q --commands ../histedit_commands histedit doesn't output anything when the current diretory is removed. We rely on the tests being commonly run on machines where the current directory disappearing from underneath us actually has an observable effect, such as an error or no files listed #if linuxormacos $ isfile foo no #endif $ cd $TESTTMP/hghistedit/somedir $ isfile foo yes $ cd $TESTTMP/hghistedit $ cat > histedit_commands <<EOF > pick 89079fab8aee 0 r0 > pick 7c7a22c6009f 3 migrating_revision > pick e6d271df3142 1 r1 > pick 40a53c2d4276 2 r2 > EOF $ cd $TESTTMP/hghistedit/somedir $ hg $NO_RM --config extensions.histedit= histedit -q --commands ../histedit_commands Regardless of system, we should always get a 'yes' here. $ isfile foo yes $ cd $TESTTMP This is essentially the exact test from issue5826, just cleaned up a little: $ hg init issue5826_withrm $ cd issue5826_withrm Let's only turn this on for this repo so that we don't contaminate later tests. $ cat >> .hg/hgrc <<EOF > [extensions] > histedit = > EOF Commit three revisions that each create a directory: $ mkdir foo $ touch foo/bar $ hg commit -qAm "add foo" $ mkdir bar $ touch bar/bar $ hg commit -qAm "add bar" $ mkdir baz $ touch baz/bar $ hg commit -qAm "add baz" Enter the first directory: $ cd foo Histedit doing 'pick, pick, fold': #if rmcwd $ hg histedit --commands - <<EOF > pick 6274c77c93c3 1 add bar > pick ff70a87b588f 0 add foo > fold 9992bb0ac0db 2 add baz > EOF abort: $ENOENT$ [255] Go back to the repo root after losing it as part of that operation: $ cd $TESTTMP/issue5826_withrm Note the lack of a non-zero exit code from this function - it exits successfully, but doesn't really do anything. $ hg histedit --continue 9992bb0ac0db: cannot fold - working copy is not a descendant of previous commit 5c806432464a saved backup bundle to $TESTTMP/issue5826_withrm/.hg/strip-backup/ff70a87b588f-e94f9789-histedit.hg $ hg log -T '{rev}:{node|short} {desc}\n' 2:94e3f9fae1d6 fold-temp-revision 9992bb0ac0db 1:5c806432464a add foo 0:d17db4b0303a add bar #else $ cd $TESTTMP/issue5826_withrm $ hg histedit --commands - <<EOF > pick 6274c77c93c3 1 add bar > pick ff70a87b588f 0 add foo > fold 9992bb0ac0db 2 add baz > EOF saved backup bundle to $TESTTMP/issue5826_withrm/.hg/strip-backup/5c806432464a-cd4c8d86-histedit.hg $ hg log -T '{rev}:{node|short} {desc}\n' 1:b9eddaa97cbc add foo *** add baz 0:d17db4b0303a add bar #endif Now test that again with experimental.removeemptydirs=false: $ hg init issue5826_norm $ cd issue5826_norm Let's only turn this on for this repo so that we don't contaminate later tests. $ cat >> .hg/hgrc <<EOF > [extensions] > histedit = > [experimental] > removeemptydirs = false > EOF Commit three revisions that each create a directory: $ mkdir foo $ touch foo/bar $ hg commit -qAm "add foo" $ mkdir bar $ touch bar/bar $ hg commit -qAm "add bar" $ mkdir baz $ touch baz/bar $ hg commit -qAm "add baz" Enter the first directory: $ cd foo Histedit doing 'pick, pick, fold': $ hg histedit --commands - <<EOF > pick 6274c77c93c3 1 add bar > pick ff70a87b588f 0 add foo > fold 9992bb0ac0db 2 add baz > EOF saved backup bundle to $TESTTMP/issue5826_withrm/issue5826_norm/.hg/strip-backup/5c806432464a-cd4c8d86-histedit.hg Note the lack of a 'cd' being necessary here, and we don't need to 'histedit --continue' $ hg log -T '{rev}:{node|short} {desc}\n' 1:b9eddaa97cbc add foo *** add baz 0:d17db4b0303a add bar $ cd $TESTTMP