tests/test-parseindex.t
author Gregory Szorc <gregory.szorc@gmail.com>
Mon, 24 Sep 2018 09:41:42 -0700
changeset 39861 db5501d93bcf
parent 39707 5abc47d4ca6b
child 40369 ef6cab7930b3
permissions -rw-r--r--
changegroup: remove reordering control (BC) This logic - including the experimental bundle.reorder option - was originally added in a8e3931e3fb5 in 2011 and then later ported to changegroup.py. The intent of this option and associated logic is to control the ordering of revisions in deltagroups in changegroups. At the time it was implemented, only changegroup version 1 existed and generaldelta revlogs were just coming into the world. Changegroup version 1 requires that deltas be made against the last revision sent over the wire. Used with generaldelta, this created an impedance mismatch of sorts and resulted in changegroup producers spending a lot of time recomputing deltas. Revision reordering was introduced so outgoing revisions would be sent in "generaldelta order" and producers would be able to reuse internal deltas from storage. Later on, we introduced changegroup version 2. It supported denoting which revision a delta was against. So we no longer needed to sort outgoing revisions to ensure optimal delta generation from the producer. So, subsequent changegroup versions disabled reordering. We also later made the changelog not store deltas by default. And we also made the changelog send out deltas in storage order. Why we do this for changelog, I'm not sure. Maybe we want to preserve revision order across clones? It doesn't really matter for this commit. Fast forward to 2018. We want to abstract storage backends. And having changegroup code require knowledge about how deltas are stored internally interferes with that goal. This commit removes reordering control from changegroup generation. After this commit, the reordering behavior is: * The changelog is always sent out in storage order (no behavior change). * Non-changelog generaldelta revlogs are reordered to always be in DAG topological order (previously, generaldelta revlogs would be emitted in storage order for version 2 and 3 changegroups). * Non-changelog non-generaldelta revlogs are sent in storage order (no behavior change). * There exists no config option to override behavior. The big difference here is that generaldelta revlogs now *always* have their revisions sorted in DAG order before going out over the wire. This behavior was previously only done for changegroup version 1. Version 2 and version 3 changegroups disabled reordering because the interchange format supported encoding arbitrary delta parents, so reordering wasn't strictly necessary. I can think of a few significant implications for this change. Because changegroup receivers will now see non-changelog revisions in DAG order instead of storage order, the internal storage order of manifests and files may differ substantially between producer and consumer. I don't think this matters that much, since the storage order of manifests and files is largely hidden from users. Only the storage order of changelog matters (because `hg log` shows the changelog in storage order). I don't think there should be any controversy here. The reordering of revisions has implications for changegroup producers. Previously, generaldelta revlogs would be emitted in storage order. And in the common case, the internally-stored delta could effectively be copied from disk into the deltagroup delta. This meant that emitting delta groups for generaldelta revlogs would be mostly linear read I/O. This is desirable for performance. With us now reordering generaldelta revlog revisions in DAG order, the read operations may use more random I/O instead of sequential I/O. This could result in performance loss. But with the prevalence of SSDs and fast random I/O, I'm not too worried. (Note: the optimal emission order for revlogs is actually delta encoding order. But the changegroup code wasn't doing that before or after this change. We could potentially implement that in a later commit.) Changegroups in DAG order will have implications for receivers. Previously, receiving storage order might mean seeing a number of interleaved branches. This would mean long delta chains, sparse I/O, and possibly more fulltext revisions instead of deltas, blowing up storage storage. (This is the same set of problems that sparse revlogs aims to address.) With the producer now sending revisions in DAG order, the receiver also stores revisions in DAG order. That means revisions for the same DAG branch are all grouped together. And this should yield better storage outcomes. In other words, sending the reordered changegroup allows the receiver to have better storage order and for the producer to not propagate its (possibly sub-optimal) internal storage order. On the mozilla-unified repository, this change influences bundle generation: $ hg bundle -t none-v2 -a before: time: real 355.680 secs (user 256.790+0.000 sys 16.820+0.000) after: time: real 382.950 secs (user 281.700+0.000 sys 17.690+0.000) before: 7,150,228,967 bytes (uncompressed) after: 7,041,556,273 bytes (uncompressed) before: 1,669,063,234 bytes (zstd l=3) after: 1,628,598,830 bytes (zstd l=3) $ hg unbundle before: time: real 511.910 secs (user 466.750+0.000 sys 32.680+0.000) after: time: real 487.790 secs (user 443.940+0.000 sys 30.840+0.000) 00manifest.d size: source: 274,924,292 bytes before: 304,741,626 bytes after: 245,252,087 bytes .hg/store total file size: source: 2,649,133,490 before: 2,680,888,130 after: 2,627,875,673 We see the bundle size drop. That's probably because if a revlog internally isn't storing a delta, it will choose to delta against the last emitted revision. And on repos with interleaved branches (like mozilla-unified), the previous revision could be an unrelated branch and therefore be a large delta. But with this patch, the previous revision is likely p1 or p2 and a delta should be small. We also see the manifest size drop by ~50 MB. It's worth noting that the manifest actually *increased* in size by ~25 MB in the old strategy and decreased ~25 MB from its source in the new strategy. Again, my explanation for this is that the DAG ordering in the changegroup is resulting in better grouping of revisions in the receiver, which results in more compact delta chains and higher storage efficiency. Unbundle time also dropped. I suspect this is due to the revlog having to work less to compute deltas since the incoming deltas are more optimal. i.e. the receiver spends less time resolving fulltext revisions as incoming deltas bounce around between DAG branches and delta chains. We also see bundle generation time increase. This is not desirable. However, the regression is only significant on the original repository: if we generate a bundle from the repository created from the new, always reordered bundles, we're close to baseline (if not at it with expected noise): $ hg bundle -t none-v2 -a before (original): time: real 355.680 secs (user 256.790+0.000 sys 16.820+0.000) after (original): time: real 382.950 secs (user 281.700+0.000 sys 17.690+0.000) after (new repo): time: real 362.280 secs (user 260.300+0.000 sys 17.700+0.000) This regression is a bit worrying because it will impact serving canonical repositories (that don't have optimal internal storage unless they are reordered - possibly as part of running `hg debugupgraderepo`). However, this regression will only be noticed by very large changegroups. And I'm guessing/hoping that any repository that large is using clonebundles to mitigate server load. Again, sending DAG order isn't the optimal send order for servers: sending in storage-delta order is. But in order to enable storage-optimal send order, we'll need a storage API that handles sorting. Future commits will introduce such an API. Differential Revision: https://phab.mercurial-scm.org/D4721
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12476
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
     1
revlog.parseindex must be able to parse the index file even if
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
     2
an index entry is split between two 64k blocks.  The ideal test
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
     3
would be to create an index file with inline data where
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
     4
64k < size < 64k + 64 (64k is the size of the read buffer, 64 is
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
     5
the size of an index entry) and with an index entry starting right
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
     6
before the 64k block boundary, and try to read it.
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
     7
We approximate that by reducing the read buffer to 1 byte.
2290
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     8
12476
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
     9
  $ hg init a
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    10
  $ cd a
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    11
  $ echo abc > foo
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    12
  $ hg add foo
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    13
  $ hg commit -m 'add foo'
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    14
  $ echo >> foo
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    15
  $ hg commit -m 'change foo'
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    16
  $ hg log -r 0:
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    17
  changeset:   0:7c31755bf9b5
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    18
  user:        test
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    19
  date:        Thu Jan 01 00:00:00 1970 +0000
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    20
  summary:     add foo
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    21
  
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    22
  changeset:   1:26333235a41c
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    23
  tag:         tip
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    24
  user:        test
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    25
  date:        Thu Jan 01 00:00:00 1970 +0000
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    26
  summary:     change foo
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    27
  
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    28
  $ cat >> test.py << EOF
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    29
  > from __future__ import print_function
31250
6d44de27790c vfs: use 'vfs' module directly in 'test-parseindex'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31216
diff changeset
    30
  > from mercurial import changelog, vfs
12476
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    31
  > from mercurial.node import *
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    32
  > 
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    33
  > class singlebyteread(object):
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    34
  >     def __init__(self, real):
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    35
  >         self.real = real
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    36
  > 
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    37
  >     def read(self, size=-1):
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    38
  >         if size == 65536:
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    39
  >             size = 1
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    40
  >         return self.real.read(size)
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    41
  > 
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    42
  >     def __getattr__(self, key):
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    43
  >         return getattr(self.real, key)
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    44
  > 
35966
8140ce44dec4 parseindex: implement context manager method on the wrapper
Boris Feld <boris.feld@octobus.net>
parents: 35965
diff changeset
    45
  >     def __enter__(self):
8140ce44dec4 parseindex: implement context manager method on the wrapper
Boris Feld <boris.feld@octobus.net>
parents: 35965
diff changeset
    46
  >         self.real.__enter__()
8140ce44dec4 parseindex: implement context manager method on the wrapper
Boris Feld <boris.feld@octobus.net>
parents: 35965
diff changeset
    47
  >         return self
8140ce44dec4 parseindex: implement context manager method on the wrapper
Boris Feld <boris.feld@octobus.net>
parents: 35965
diff changeset
    48
  > 
8140ce44dec4 parseindex: implement context manager method on the wrapper
Boris Feld <boris.feld@octobus.net>
parents: 35965
diff changeset
    49
  >     def __exit__(self, *args, **kwargs):
8140ce44dec4 parseindex: implement context manager method on the wrapper
Boris Feld <boris.feld@octobus.net>
parents: 35965
diff changeset
    50
  >         return self.real.__exit__(*args, **kwargs)
8140ce44dec4 parseindex: implement context manager method on the wrapper
Boris Feld <boris.feld@octobus.net>
parents: 35965
diff changeset
    51
  > 
12476
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    52
  > def opener(*args):
31250
6d44de27790c vfs: use 'vfs' module directly in 'test-parseindex'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31216
diff changeset
    53
  >     o = vfs.vfs(*args)
35965
c839bbee1e13 parseindex: also forward keyword argument in a debug wrapper
Boris Feld <boris.feld@octobus.net>
parents: 33262
diff changeset
    54
  >     def wrapper(*a, **kwargs):
c839bbee1e13 parseindex: also forward keyword argument in a debug wrapper
Boris Feld <boris.feld@octobus.net>
parents: 33262
diff changeset
    55
  >         f = o(*a, **kwargs)
12476
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    56
  >         return singlebyteread(f)
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    57
  >     return wrapper
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    58
  > 
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    59
  > cl = changelog.changelog(opener('.hg/store'))
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    60
  > print(len(cl), 'revisions:')
12476
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    61
  > for r in cl:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    62
  >     print(short(cl.node(r)))
12476
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    63
  > EOF
39707
5abc47d4ca6b tests: quote PYTHON usage
Matt Harbison <matt_harbison@yahoo.com>
parents: 39282
diff changeset
    64
  $ "$PYTHON" test.py
12476
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    65
  2 revisions:
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    66
  7c31755bf9b5
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    67
  26333235a41c
16913
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 13970
diff changeset
    68
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 13970
diff changeset
    69
  $ cd ..
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
    70
26017
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
    71
#if no-pure
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
    72
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
    73
Test SEGV caused by bad revision passed to reachableroots() (issue4775):
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
    74
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
    75
  $ cd a
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
    76
39707
5abc47d4ca6b tests: quote PYTHON usage
Matt Harbison <matt_harbison@yahoo.com>
parents: 39282
diff changeset
    77
  $ "$PYTHON" <<EOF
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    78
  > from __future__ import print_function
31250
6d44de27790c vfs: use 'vfs' module directly in 'test-parseindex'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31216
diff changeset
    79
  > from mercurial import changelog, vfs
6d44de27790c vfs: use 'vfs' module directly in 'test-parseindex'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31216
diff changeset
    80
  > cl = changelog.changelog(vfs.vfs('.hg/store'))
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    81
  > print('good heads:')
26017
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
    82
  > for head in [0, len(cl) - 1, -1]:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    83
  >     print('%s: %r' % (head, cl.reachableroots(0, [head], [0])))
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    84
  > print('bad heads:')
26018
c6115c30a376 reachableroots: verify type of each item of heads argument
Yuya Nishihara <yuya@tcha.org>
parents: 26017
diff changeset
    85
  > for head in [len(cl), 10000, -2, -10000, None]:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    86
  >     print('%s:' % head, end=' ')
26017
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
    87
  >     try:
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
    88
  >         cl.reachableroots(0, [head], [0])
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    89
  >         print('uncaught buffer overflow?')
26018
c6115c30a376 reachableroots: verify type of each item of heads argument
Yuya Nishihara <yuya@tcha.org>
parents: 26017
diff changeset
    90
  >     except (IndexError, TypeError) as inst:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    91
  >         print(inst)
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    92
  > print('good roots:')
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
    93
  > for root in [0, len(cl) - 1, -1]:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    94
  >     print('%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root])))
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    95
  > print('out-of-range roots are ignored:')
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
    96
  > for root in [len(cl), 10000, -2, -10000]:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    97
  >     print('%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root])))
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    98
  > print('bad roots:')
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
    99
  > for root in [None]:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
   100
  >     print('%s:' % root, end=' ')
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   101
  >     try:
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   102
  >         cl.reachableroots(root, [len(cl) - 1], [root])
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
   103
  >         print('uncaught error?')
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   104
  >     except TypeError as inst:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
   105
  >         print(inst)
26017
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   106
  > EOF
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   107
  good heads:
26094
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   108
  0: [0]
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   109
  1: [0]
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   110
  -1: []
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   111
  bad heads:
26017
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   112
  2: head out of range
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   113
  10000: head out of range
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   114
  -2: head out of range
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   115
  -10000: head out of range
26018
c6115c30a376 reachableroots: verify type of each item of heads argument
Yuya Nishihara <yuya@tcha.org>
parents: 26017
diff changeset
   116
  None: an integer is required
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   117
  good roots:
26094
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   118
  0: [0]
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   119
  1: [1]
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   120
  -1: [-1]
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   121
  out-of-range roots are ignored:
26094
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   122
  2: []
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   123
  10000: []
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   124
  -2: []
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   125
  -10000: []
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   126
  bad roots:
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   127
  None: an integer is required
26017
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   128
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   129
  $ cd ..
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   130
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   131
Test corrupted p1/p2 fields that could cause SEGV at parsers.c:
25859
1619563959b3 tests: disable test of buffer overflow in parsers.c if --pure
Yuya Nishihara <yuya@tcha.org>
parents: 25810
diff changeset
   132
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   133
  $ mkdir invalidparent
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   134
  $ cd invalidparent
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   135
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   136
  $ hg clone --pull -q --config phases.publish=False ../a limit
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   137
  $ hg clone --pull -q --config phases.publish=False ../a segv
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   138
  $ rm -R limit/.hg/cache segv/.hg/cache
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   139
39707
5abc47d4ca6b tests: quote PYTHON usage
Matt Harbison <matt_harbison@yahoo.com>
parents: 39282
diff changeset
   140
  $ "$PYTHON" <<EOF
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   141
  > data = open("limit/.hg/store/00changelog.i", "rb").read()
38087
307b19c7c043 py3: add b'' prefixes in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38079
diff changeset
   142
  > for n, p in [(b'limit', b'\0\0\0\x02'), (b'segv', b'\0\x01\0\0')]:
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   143
  >     # corrupt p1 at rev0 and p2 at rev1
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   144
  >     d = data[:24] + p + data[28:127 + 28] + p + data[127 + 32:]
38087
307b19c7c043 py3: add b'' prefixes in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38079
diff changeset
   145
  >     open(n + b"/.hg/store/00changelog.i", "wb").write(d)
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   146
  > EOF
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   147
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38089
diff changeset
   148
  $ hg -R limit debugrevlogindex -f1 -c
37283
d4e62df1c73d debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37282
diff changeset
   149
     rev flag     size   link     p1     p2       nodeid
d4e62df1c73d debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37282
diff changeset
   150
       0 0000       62      0      2     -1 7c31755bf9b5
d4e62df1c73d debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37282
diff changeset
   151
       1 0000       65      1      0      2 26333235a41c
37281
806b07d7c7d6 tests: use debugdeltachain where appropriate
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37280
diff changeset
   152
806b07d7c7d6 tests: use debugdeltachain where appropriate
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37280
diff changeset
   153
  $ hg -R limit debugdeltachain -c
806b07d7c7d6 tests: use debugdeltachain where appropriate
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37280
diff changeset
   154
      rev  chain# chainlen     prev   delta       size    rawsize  chainsize     ratio   lindist extradist extraratio
806b07d7c7d6 tests: use debugdeltachain where appropriate
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37280
diff changeset
   155
        0       1        1       -1    base         63         62         63   1.01613        63         0    0.00000
806b07d7c7d6 tests: use debugdeltachain where appropriate
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37280
diff changeset
   156
        1       2        1       -1    base         66         65         66   1.01538        66         0    0.00000
806b07d7c7d6 tests: use debugdeltachain where appropriate
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37280
diff changeset
   157
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38089
diff changeset
   158
  $ hg -R segv debugrevlogindex -f1 -c
37283
d4e62df1c73d debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37282
diff changeset
   159
     rev flag     size   link     p1     p2       nodeid
d4e62df1c73d debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37282
diff changeset
   160
       0 0000       62      0  65536     -1 7c31755bf9b5
d4e62df1c73d debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37282
diff changeset
   161
       1 0000       65      1      0  65536 26333235a41c
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   162
37281
806b07d7c7d6 tests: use debugdeltachain where appropriate
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37280
diff changeset
   163
  $ hg -R segv debugdeltachain -c
806b07d7c7d6 tests: use debugdeltachain where appropriate
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37280
diff changeset
   164
      rev  chain# chainlen     prev   delta       size    rawsize  chainsize     ratio   lindist extradist extraratio
806b07d7c7d6 tests: use debugdeltachain where appropriate
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37280
diff changeset
   165
        0       1        1       -1    base         63         62         63   1.01613        63         0    0.00000
806b07d7c7d6 tests: use debugdeltachain where appropriate
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37280
diff changeset
   166
        1       2        1       -1    base         66         65         66   1.01538        66         0    0.00000
806b07d7c7d6 tests: use debugdeltachain where appropriate
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37280
diff changeset
   167
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   168
  $ cat <<EOF > test.py
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
   169
  > from __future__ import print_function
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   170
  > import sys
31250
6d44de27790c vfs: use 'vfs' module directly in 'test-parseindex'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31216
diff changeset
   171
  > from mercurial import changelog, vfs
6d44de27790c vfs: use 'vfs' module directly in 'test-parseindex'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31216
diff changeset
   172
  > cl = changelog.changelog(vfs.vfs(sys.argv[1]))
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   173
  > n0, n1 = cl.node(0), cl.node(1)
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   174
  > ops = [
26016
c8d41c9c23c7 reachableroots: unify bail cases to raise exception correctly
Yuya Nishihara <yuya@tcha.org>
parents: 25859
diff changeset
   175
  >     ('reachableroots',
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   176
  >      lambda: cl.index.reachableroots2(0, [1], [0], False)),
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   177
  >     ('compute_phases_map_sets', lambda: cl.computephases([[0], []])),
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   178
  >     ('index_headrevs', lambda: cl.headrevs()),
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   179
  >     ('find_gca_candidates', lambda: cl.commonancestorsheads(n0, n1)),
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   180
  >     ('find_deepest', lambda: cl.ancestor(n0, n1)),
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   181
  >     ]
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   182
  > for l, f in ops:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
   183
  >     print(l + ':', end=' ')
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   184
  >     try:
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   185
  >         f()
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
   186
  >         print('uncaught buffer overflow?')
38089
f0fadc5bea21 py3: use `except error as e` instead of `except error, e`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38087
diff changeset
   187
  >     except ValueError as inst:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
   188
  >         print(inst)
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   189
  > EOF
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   190
39707
5abc47d4ca6b tests: quote PYTHON usage
Matt Harbison <matt_harbison@yahoo.com>
parents: 39282
diff changeset
   191
  $ "$PYTHON" test.py limit/.hg/store
26016
c8d41c9c23c7 reachableroots: unify bail cases to raise exception correctly
Yuya Nishihara <yuya@tcha.org>
parents: 25859
diff changeset
   192
  reachableroots: parent out of range
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   193
  compute_phases_map_sets: parent out of range
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   194
  index_headrevs: parent out of range
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   195
  find_gca_candidates: parent out of range
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   196
  find_deepest: parent out of range
39707
5abc47d4ca6b tests: quote PYTHON usage
Matt Harbison <matt_harbison@yahoo.com>
parents: 39282
diff changeset
   197
  $ "$PYTHON" test.py segv/.hg/store
26016
c8d41c9c23c7 reachableroots: unify bail cases to raise exception correctly
Yuya Nishihara <yuya@tcha.org>
parents: 25859
diff changeset
   198
  reachableroots: parent out of range
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   199
  compute_phases_map_sets: parent out of range
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   200
  index_headrevs: parent out of range
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   201
  find_gca_candidates: parent out of range
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   202
  find_deepest: parent out of range
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   203
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   204
  $ cd ..
25859
1619563959b3 tests: disable test of buffer overflow in parsers.c if --pure
Yuya Nishihara <yuya@tcha.org>
parents: 25810
diff changeset
   205
1619563959b3 tests: disable test of buffer overflow in parsers.c if --pure
Yuya Nishihara <yuya@tcha.org>
parents: 25810
diff changeset
   206
#endif