mercurial/requirements.py
author Kyle Lippincott <spectral@google.com>
Wed, 03 Feb 2021 16:33:10 -0800
changeset 46607 e9901d01d135
parent 46334 4b0192f592cf
child 46626 ee91966aec0f
permissions -rw-r--r--
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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45372
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     1
# requirements.py - objects and functions related to repository requirements
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     2
#
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     3
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     4
#
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     7
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     8
from __future__ import absolute_import
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     9
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    10
# When narrowing is finalized and no longer subject to format changes,
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    11
# we should move this to just "narrow" or similar.
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    12
NARROW_REQUIREMENT = b'narrowhg-experimental'
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    13
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    14
# Enables sparse working directory usage
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    15
SPARSE_REQUIREMENT = b'exp-sparse'
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    16
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    17
# Enables the internal phase which is used to hide changesets instead
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    18
# of stripping them
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    19
INTERNAL_PHASE_REQUIREMENT = b'internal-phase'
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    20
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    21
# Stores manifest in Tree structure
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    22
TREEMANIFEST_REQUIREMENT = b'treemanifest'
45373
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    23
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    24
# Increment the sub-version when the revlog v2 format changes to lock out old
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    25
# clients.
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    26
REVLOGV2_REQUIREMENT = b'exp-revlogv2.1'
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    27
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    28
# A repository with the sparserevlog feature will have delta chains that
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    29
# can spread over a larger span. Sparse reading cuts these large spans into
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    30
# pieces, so that each piece isn't too big.
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    31
# Without the sparserevlog capability, reading from the repository could use
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    32
# huge amounts of memory, because the whole span would be read at once,
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    33
# including all the intermediate revisions that aren't pertinent for the chain.
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    34
# This is why once a repository has enabled sparse-read, it becomes required.
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    35
SPARSEREVLOG_REQUIREMENT = b'sparserevlog'
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    36
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    37
# A repository with the sidedataflag requirement will allow to store extra
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    38
# information for revision without altering their original hashes.
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    39
SIDEDATA_REQUIREMENT = b'exp-sidedata-flag'
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    40
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    41
# A repository with the the copies-sidedata-changeset requirement will store
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    42
# copies related information in changeset's sidedata.
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    43
COPIESSDC_REQUIREMENT = b'exp-copies-sidedata-changeset'
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    44
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    45
# The repository use persistent nodemap for the changelog and the manifest.
d7dcc75a3eae localrepo: move requirements constant to requirements module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    46
NODEMAP_REQUIREMENT = b'persistent-nodemap'
45374
bd56597b2254 requirements: introduce a set of working directory specific requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45373
diff changeset
    47
45386
034d94f8761b requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45374
diff changeset
    48
# Denotes that the current repository is a share
034d94f8761b requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45374
diff changeset
    49
SHARED_REQUIREMENT = b'shared'
034d94f8761b requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45374
diff changeset
    50
034d94f8761b requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45374
diff changeset
    51
# Denotes that current repository is a share and the shared source path is
034d94f8761b requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45374
diff changeset
    52
# relative to the current repository root path
034d94f8761b requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45374
diff changeset
    53
RELATIVE_SHARED_REQUIREMENT = b'relshared'
034d94f8761b requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45374
diff changeset
    54
45483
d252f51ab032 share: introduce config option to store requires in .hg/store
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45386
diff changeset
    55
# A repository with share implemented safely. The repository has different
d252f51ab032 share: introduce config option to store requires in .hg/store
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45386
diff changeset
    56
# store and working copy requirements i.e. both `.hg/requires` and
d252f51ab032 share: introduce config option to store requires in .hg/store
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45386
diff changeset
    57
# `.hg/store/requires` are present.
46334
4b0192f592cf share: move share safe functionality out of experimental
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45483
diff changeset
    58
SHARESAFE_REQUIREMENT = b'share-safe'
45483
d252f51ab032 share: introduce config option to store requires in .hg/store
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45386
diff changeset
    59
45374
bd56597b2254 requirements: introduce a set of working directory specific requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45373
diff changeset
    60
# List of requirements which are working directory specific
bd56597b2254 requirements: introduce a set of working directory specific requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45373
diff changeset
    61
# These requirements cannot be shared between repositories if they
bd56597b2254 requirements: introduce a set of working directory specific requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45373
diff changeset
    62
# share the same store
45386
034d94f8761b requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45374
diff changeset
    63
# * sparse is a working directory specific functionality and hence working
034d94f8761b requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45374
diff changeset
    64
#   directory specific requirement
034d94f8761b requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45374
diff changeset
    65
# * SHARED_REQUIREMENT and RELATIVE_SHARED_REQUIREMENT are requirements which
034d94f8761b requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45374
diff changeset
    66
#   represents that the current working copy/repository shares store of another
034d94f8761b requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45374
diff changeset
    67
#   repo. Hence both of them should be stored in working copy
45483
d252f51ab032 share: introduce config option to store requires in .hg/store
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45386
diff changeset
    68
# * SHARESAFE_REQUIREMENT needs to be stored in working dir to mark that rest of
d252f51ab032 share: introduce config option to store requires in .hg/store
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45386
diff changeset
    69
#   the requirements are stored in store's requires
45386
034d94f8761b requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45374
diff changeset
    70
WORKING_DIR_REQUIREMENTS = {
034d94f8761b requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45374
diff changeset
    71
    SPARSE_REQUIREMENT,
034d94f8761b requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45374
diff changeset
    72
    SHARED_REQUIREMENT,
034d94f8761b requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45374
diff changeset
    73
    RELATIVE_SHARED_REQUIREMENT,
45483
d252f51ab032 share: introduce config option to store requires in .hg/store
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45386
diff changeset
    74
    SHARESAFE_REQUIREMENT,
45386
034d94f8761b requirements: introduce constants for `shared` and `relshared` requirements
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45374
diff changeset
    75
}