tests/test-revlog.t
author Gregory Szorc <gregory.szorc@gmail.com>
Wed, 12 Sep 2018 11:02:16 -0700
changeset 39703 bfeab472e3c0
parent 39309 828a45233036
child 39908 803b7569c9ea
permissions -rw-r--r--
localrepo: create new function for instantiating a local repo object Today, there is a single local repository class - localrepository. Its __init__ is responsible for loading the .hg/requires file and taking different actions depending on what is present. In addition, extensions may define a "reposetup" function that monkeypatches constructed repository instances, often by implementing a derived type and changing the __class__ of the repo instance. Work around alternate storage backends and partial clone has made it clear to me that shoehorning all this logic into __init__ and operating on an existing instance is too convoluted. For example, localrepository assumes revlog storage and swapping in non-revlog storage requires overriding e.g. file() to return something that isn't a revlog. I've authored various patches that either: a) teach various methods (like file()) about different states and taking the appropriate code path at run-time b) create methods/attributes/callables used for instantiating things and populating these in __init__ "a" incurs run-time performance penalties and makes code more complicated since various functions have a bunch of "if storage is X" branches. "b" makes localrepository quickly explode in complexity. My plan for tackling this problem is to make the local repository type more dynamic. Instead of a static localrepository class/type that supports all of the local repository configurations (revlogs vs other, revlogs with ellipsis, revlog v1 versus revlog v2, etc), we'll dynamically construct a type providing the implementations that are needed for the repository on disk, derived from the .hg/requires file and configuration options. The constructed repository type will be specialized and methods won't need to be taught about different implementations nor overloaded. We may also leverage this functionality for building types that don't implement all attributes. For example, the "intents" feature allows commands to declare that they are read only. By dynamically constructing a repository type, we could return a repository instance with no attributes related to mutating the repository. This could include things like a "changelog" property implementation that doesn't check whether it needs to invalidate the hidden revisions set on every access. This commit establishes a function for building a local repository instance. Future commits will start moving functionality from localrepository.__init__ to this function. Then we'll start dynamically changing the returned type depending on options that are present. This change may seem radical. But it should be fully compatible with the reposetup() model - at least for now. Differential Revision: https://phab.mercurial-scm.org/D4563
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32429
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
     1
  $ hg init empty-repo
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
     2
  $ cd empty-repo
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
     3
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
     4
Flags on revlog version 0 are rejected
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
     5
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
     6
  >>> with open('.hg/store/00changelog.i', 'wb') as fh:
38113
0a10f142299d py3: suppress the output from .write() calls in few tests
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37285
diff changeset
     7
  ...     fh.write(b'\x00\x01\x00\x00') and None
32429
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
     8
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
     9
  $ hg log
32430
36d3559c69a6 revlog: tweak wording and logic for flags validation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32429
diff changeset
    10
  abort: unknown flags (0x01) in version 0 revlog 00changelog.i!
32429
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    11
  [255]
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    12
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    13
Unknown flags on revlog version 1 are rejected
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    14
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    15
  >>> with open('.hg/store/00changelog.i', 'wb') as fh:
38113
0a10f142299d py3: suppress the output from .write() calls in few tests
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37285
diff changeset
    16
  ...     fh.write(b'\x00\x04\x00\x01') and None
32429
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    17
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    18
  $ hg log
32430
36d3559c69a6 revlog: tweak wording and logic for flags validation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32429
diff changeset
    19
  abort: unknown flags (0x04) in version 1 revlog 00changelog.i!
32429
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    20
  [255]
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    21
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    22
Unknown version is rejected
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    23
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    24
  >>> with open('.hg/store/00changelog.i', 'wb') as fh:
38113
0a10f142299d py3: suppress the output from .write() calls in few tests
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37285
diff changeset
    25
  ...     fh.write(b'\x00\x00\x00\x02') and None
32429
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    26
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    27
  $ hg log
32430
36d3559c69a6 revlog: tweak wording and logic for flags validation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32429
diff changeset
    28
  abort: unknown version (2) in revlog 00changelog.i!
32429
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    29
  [255]
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    30
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    31
  $ cd ..
3ea1f1e71a0a tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32410
diff changeset
    32
28656
b6ed2505d6cf parsers: fix list sizing rounding error (SEC)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    33
Test for CVE-2016-3630
b6ed2505d6cf parsers: fix list sizing rounding error (SEC)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    34
b6ed2505d6cf parsers: fix list sizing rounding error (SEC)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    35
  $ hg init
b6ed2505d6cf parsers: fix list sizing rounding error (SEC)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    36
36514
71d1bbf1617e py3: add b'' prefixes in tests/test-revlog.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32430
diff changeset
    37
  >>> open("a.i", "wb").write(
71d1bbf1617e py3: add b'' prefixes in tests/test-revlog.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32430
diff changeset
    38
  ... b"""eJxjYGZgZIAAYQYGxhgom+k/FMx8YKx9ZUaKSOyqo4cnuKb8mbqHV5cBCVTMWb1Cwqkhe4Gsg9AD
28656
b6ed2505d6cf parsers: fix list sizing rounding error (SEC)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    39
  ... Joa3dYtcYYYBAQ8Qr4OqZAYRICPTSr5WKd/42rV36d+8/VmrNpv7NP1jQAXrQE4BqQUARngwVA=="""
b6ed2505d6cf parsers: fix list sizing rounding error (SEC)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    40
  ... .decode("base64").decode("zlib"))
b6ed2505d6cf parsers: fix list sizing rounding error (SEC)
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    41
39309
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39307
diff changeset
    42
  $ hg debugrevlogindex a.i
37285
d4e62df1c73d debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
    43
     rev linkrev nodeid       p1           p2
d4e62df1c73d debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
    44
       0       2 99e0332bd498 000000000000 000000000000
d4e62df1c73d debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37284
diff changeset
    45
       1       3 6674f57a23d8 99e0332bd498 000000000000
39307
da459d426c20 tests: use inline Python for revlog test
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38113
diff changeset
    46
da459d426c20 tests: use inline Python for revlog test
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38113
diff changeset
    47
  >>> from mercurial import revlog, vfs
da459d426c20 tests: use inline Python for revlog test
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38113
diff changeset
    48
  >>> tvfs = vfs.vfs(b'.')
da459d426c20 tests: use inline Python for revlog test
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38113
diff changeset
    49
  >>> tvfs.options = {b'revlogv1': True}
da459d426c20 tests: use inline Python for revlog test
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38113
diff changeset
    50
  >>> rl = revlog.revlog(tvfs, b'a.i')
da459d426c20 tests: use inline Python for revlog test
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38113
diff changeset
    51
  >>> rl.revision(1)
da459d426c20 tests: use inline Python for revlog test
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38113
diff changeset
    52
  mpatchError('patch cannot be decoded',)