tests/test-remotefilelog-histpack.py
author Anton Shestakov <av6@dwimlabs.net>
Tue, 04 Jan 2022 23:38:39 +0300
changeset 48702 053a5bf508da
parent 47505 23f5ed6dbcb1
child 48966 6000f5b25c9b
permissions -rwxr-xr-x
discovery: port _postprocessobsolete() changes from evolve, add tests Let's make this function obsolescence-aware as well. Now we check that revisions are not obsolete first, and only then check that they are going to be common after exchange. The tests make sure that rewriting changesets doesn't confuse head computation. They rely on experimental.single-head-per-branch feature to show that remote correctly sees the expected result (i.e. either aborts the push or allows it to succeed). They are ported from evolve as well. Differential Revision: https://phab.mercurial-scm.org/D12098
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47505
23f5ed6dbcb1 run-tests: stop writing a `python3` symlink pointing to python2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
     1
#!/usr/bin/env python
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
from __future__ import absolute_import
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
     3
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
     4
import hashlib
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
     5
import os
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
     6
import random
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
     7
import shutil
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
     8
import stat
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
     9
import struct
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
import sys
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    11
import tempfile
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    12
import unittest
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    13
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
import silenttestrunner
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    15
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
    16
from mercurial.node import sha1nodeconstants
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    17
from mercurial import (
40767
9446d5aa0f32 py3: convert strings to bytes in tests/test-remotefilelog-histpack.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40556
diff changeset
    18
    pycompat,
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
    ui as uimod,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    20
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
    21
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
# Load the local remotefilelog, not the system one
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    23
sys.path[0:0] = [os.path.join(os.path.dirname(__file__), '..')]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
from hgext.remotefilelog import (
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    25
    basepack,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    26
    historypack,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    27
)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    28
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
    29
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    30
class histpacktests(unittest.TestCase):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    31
    def setUp(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    32
        self.tempdirs = []
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    33
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    34
    def tearDown(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    35
        for d in self.tempdirs:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    36
            shutil.rmtree(d)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    37
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    38
    def makeTempDir(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    39
        tempdir = tempfile.mkdtemp()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    40
        self.tempdirs.append(tempdir)
40767
9446d5aa0f32 py3: convert strings to bytes in tests/test-remotefilelog-histpack.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40556
diff changeset
    41
        return pycompat.fsencode(tempdir)
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    42
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    43
    def getHash(self, content):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    44
        return hashlib.sha1(content).digest()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    45
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    46
    def getFakeHash(self):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
    47
        return b''.join(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
    48
            pycompat.bytechr(random.randint(0, 255)) for _ in range(20)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
    49
        )
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    50
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    51
    def createPack(self, revisions=None):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    52
        """Creates and returns a historypack containing the specified revisions.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    53
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    54
        `revisions` is a list of tuples, where each tuple contains a filanem,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    55
        node, p1node, p2node, and linknode.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    56
        """
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    57
        if revisions is None:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
    58
            revisions = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
    59
                (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
    60
                    b"filename",
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
    61
                    self.getFakeHash(),
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
    62
                    sha1nodeconstants.nullid,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
    63
                    sha1nodeconstants.nullid,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
    64
                    self.getFakeHash(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
    65
                    None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
    66
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
    67
            ]
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    68
40767
9446d5aa0f32 py3: convert strings to bytes in tests/test-remotefilelog-histpack.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40556
diff changeset
    69
        packdir = pycompat.fsencode(self.makeTempDir())
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
    70
        packer = historypack.mutablehistorypack(uimod.ui(), packdir, version=2)
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    71
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    72
        for filename, node, p1, p2, linknode, copyfrom in revisions:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    73
            packer.add(filename, node, p1, p2, linknode, copyfrom)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    74
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    75
        path = packer.close()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    76
        return historypack.historypack(path)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    77
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    78
    def testAddSingle(self):
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45849
diff changeset
    79
        """Test putting a single entry into a pack and reading it out."""
41347
4ef28d7e22ae tests: make filenames bytes for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41346
diff changeset
    80
        filename = b"foo"
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    81
        node = self.getFakeHash()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    82
        p1 = self.getFakeHash()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    83
        p2 = self.getFakeHash()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    84
        linknode = self.getFakeHash()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    85
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    86
        revisions = [(filename, node, p1, p2, linknode, None)]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    87
        pack = self.createPack(revisions)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    88
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    89
        actual = pack.getancestors(filename, node)[node]
41346
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
    90
        self.assertEqual(p1, actual[0])
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
    91
        self.assertEqual(p2, actual[1])
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
    92
        self.assertEqual(linknode, actual[2])
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    93
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    94
    def testAddMultiple(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    95
        """Test putting multiple unrelated revisions into a pack and reading
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    96
        them out.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    97
        """
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    98
        revisions = []
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    99
        for i in range(10):
41347
4ef28d7e22ae tests: make filenames bytes for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41346
diff changeset
   100
            filename = b"foo-%d" % i
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   101
            node = self.getFakeHash()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   102
            p1 = self.getFakeHash()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   103
            p2 = self.getFakeHash()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   104
            linknode = self.getFakeHash()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   105
            revisions.append((filename, node, p1, p2, linknode, None))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   106
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   107
        pack = self.createPack(revisions)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   108
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   109
        for filename, node, p1, p2, linknode, copyfrom in revisions:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   110
            actual = pack.getancestors(filename, node)[node]
41346
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   111
            self.assertEqual(p1, actual[0])
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   112
            self.assertEqual(p2, actual[1])
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   113
            self.assertEqual(linknode, actual[2])
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   114
            self.assertEqual(copyfrom, actual[3])
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   115
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   116
    def testAddAncestorChain(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   117
        """Test putting multiple revisions in into a pack and read the ancestor
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   118
        chain.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   119
        """
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   120
        revisions = []
40767
9446d5aa0f32 py3: convert strings to bytes in tests/test-remotefilelog-histpack.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40556
diff changeset
   121
        filename = b"foo"
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   122
        lastnode = sha1nodeconstants.nullid
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   123
        for i in range(10):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   124
            node = self.getFakeHash()
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   125
            revisions.append(
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   126
                (
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   127
                    filename,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   128
                    node,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   129
                    lastnode,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   130
                    sha1nodeconstants.nullid,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   131
                    sha1nodeconstants.nullid,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   132
                    None,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   133
                )
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   134
            )
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   135
            lastnode = node
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   136
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   137
        # revisions must be added in topological order, newest first
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   138
        revisions = list(reversed(revisions))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   139
        pack = self.createPack(revisions)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   140
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   141
        # Test that the chain has all the entries
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   142
        ancestors = pack.getancestors(revisions[0][0], revisions[0][1])
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   143
        for filename, node, p1, p2, linknode, copyfrom in revisions:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   144
            ap1, ap2, alinknode, acopyfrom = ancestors[node]
41346
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   145
            self.assertEqual(ap1, p1)
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   146
            self.assertEqual(ap2, p2)
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   147
            self.assertEqual(alinknode, linknode)
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   148
            self.assertEqual(acopyfrom, copyfrom)
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   149
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   150
    def testPackMany(self):
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45849
diff changeset
   151
        """Pack many related and unrelated ancestors."""
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   152
        # Build a random pack file
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   153
        allentries = {}
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   154
        ancestorcounts = {}
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   155
        revisions = []
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   156
        random.seed(0)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   157
        for i in range(100):
40767
9446d5aa0f32 py3: convert strings to bytes in tests/test-remotefilelog-histpack.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40556
diff changeset
   158
            filename = b"filename-%d" % i
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   159
            entries = []
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   160
            p2 = sha1nodeconstants.nullid
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   161
            linknode = sha1nodeconstants.nullid
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   162
            for j in range(random.randint(1, 100)):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   163
                node = self.getFakeHash()
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   164
                p1 = sha1nodeconstants.nullid
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   165
                if len(entries) > 0:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   166
                    p1 = entries[random.randint(0, len(entries) - 1)]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   167
                entries.append(node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   168
                revisions.append((filename, node, p1, p2, linknode, None))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   169
                allentries[(filename, node)] = (p1, p2, linknode)
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   170
                if p1 == sha1nodeconstants.nullid:
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   171
                    ancestorcounts[(filename, node)] = 1
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   172
                else:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   173
                    newcount = ancestorcounts[(filename, p1)] + 1
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   174
                    ancestorcounts[(filename, node)] = newcount
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   175
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   176
        # Must add file entries in reverse topological order
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   177
        revisions = list(reversed(revisions))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   178
        pack = self.createPack(revisions)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   179
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   180
        # Verify the pack contents
41387
876494fd967d cleanup: delete lots of unused local variables
Martin von Zweigbergk <martinvonz@google.com>
parents: 41348
diff changeset
   181
        for (filename, node) in allentries:
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   182
            ancestors = pack.getancestors(filename, node)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
   183
            self.assertEqual(ancestorcounts[(filename, node)], len(ancestors))
40768
5d1550b9a533 py3: use dict.items() instead of dict.iteritems()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40767
diff changeset
   184
            for anode, (ap1, ap2, alinknode, copyfrom) in ancestors.items():
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   185
                ep1, ep2, elinknode = allentries[(filename, anode)]
41346
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   186
                self.assertEqual(ap1, ep1)
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   187
                self.assertEqual(ap2, ep2)
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   188
                self.assertEqual(alinknode, elinknode)
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   189
                self.assertEqual(copyfrom, None)
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   190
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   191
    def testGetNodeInfo(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   192
        revisions = []
40767
9446d5aa0f32 py3: convert strings to bytes in tests/test-remotefilelog-histpack.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40556
diff changeset
   193
        filename = b"foo"
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   194
        lastnode = sha1nodeconstants.nullid
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   195
        for i in range(10):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   196
            node = self.getFakeHash()
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   197
            revisions.append(
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   198
                (
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   199
                    filename,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   200
                    node,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   201
                    lastnode,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   202
                    sha1nodeconstants.nullid,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   203
                    sha1nodeconstants.nullid,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   204
                    None,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   205
                )
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   206
            )
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   207
            lastnode = node
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   208
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   209
        pack = self.createPack(revisions)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   210
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   211
        # Test that getnodeinfo returns the expected results
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   212
        for filename, node, p1, p2, linknode, copyfrom in revisions:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   213
            ap1, ap2, alinknode, acopyfrom = pack.getnodeinfo(filename, node)
41346
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   214
            self.assertEqual(ap1, p1)
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   215
            self.assertEqual(ap2, p2)
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   216
            self.assertEqual(alinknode, linknode)
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   217
            self.assertEqual(acopyfrom, copyfrom)
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   218
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   219
    def testGetMissing(self):
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45849
diff changeset
   220
        """Test the getmissing() api."""
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   221
        revisions = []
40767
9446d5aa0f32 py3: convert strings to bytes in tests/test-remotefilelog-histpack.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40556
diff changeset
   222
        filename = b"foo"
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   223
        for i in range(10):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   224
            node = self.getFakeHash()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   225
            p1 = self.getFakeHash()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   226
            p2 = self.getFakeHash()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   227
            linknode = self.getFakeHash()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   228
            revisions.append((filename, node, p1, p2, linknode, None))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   229
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   230
        pack = self.createPack(revisions)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   231
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   232
        missing = pack.getmissing([(filename, revisions[0][1])])
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   233
        self.assertFalse(missing)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   234
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
   235
        missing = pack.getmissing(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
   236
            [(filename, revisions[0][1]), (filename, revisions[1][1])]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
   237
        )
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   238
        self.assertFalse(missing)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   239
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   240
        fakenode = self.getFakeHash()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
   241
        missing = pack.getmissing(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
   242
            [(filename, revisions[0][1]), (filename, fakenode)]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
   243
        )
41346
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   244
        self.assertEqual(missing, [(filename, fakenode)])
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   245
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   246
        # Test getmissing on a non-existant filename
41347
4ef28d7e22ae tests: make filenames bytes for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41346
diff changeset
   247
        missing = pack.getmissing([(b"bar", fakenode)])
4ef28d7e22ae tests: make filenames bytes for Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41346
diff changeset
   248
        self.assertEqual(missing, [(b"bar", fakenode)])
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   249
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   250
    def testAddThrows(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   251
        pack = self.createPack()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   252
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   253
        try:
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   254
            pack.add(
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   255
                b'filename',
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   256
                sha1nodeconstants.nullid,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   257
                sha1nodeconstants.nullid,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   258
                sha1nodeconstants.nullid,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   259
                sha1nodeconstants.nullid,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   260
                None,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   261
            )
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   262
            self.assertTrue(False, "historypack.add should throw")
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   263
        except RuntimeError:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   264
            pass
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   265
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   266
    def testBadVersionThrows(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   267
        pack = self.createPack()
41348
abac73eedd4d tests: use bytes for file I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41347
diff changeset
   268
        path = pack.path + b'.histpack'
abac73eedd4d tests: use bytes for file I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41347
diff changeset
   269
        with open(path, 'rb') as f:
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   270
            raw = f.read()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   271
        raw = struct.pack('!B', 255) + raw[1:]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   272
        os.chmod(path, os.stat(path).st_mode | stat.S_IWRITE)
41348
abac73eedd4d tests: use bytes for file I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41347
diff changeset
   273
        with open(path, 'wb+') as f:
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   274
            f.write(raw)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   275
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   276
        try:
43995
37458d8b0c1e tests: drop unused local variable assignments in remotefilelog
Matt Harbison <matt_harbison@yahoo.com>
parents: 43076
diff changeset
   277
            historypack.historypack(pack.path)
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   278
            self.assertTrue(False, "bad version number should have thrown")
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   279
        except RuntimeError:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   280
            pass
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   281
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   282
    def testLargePack(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   283
        """Test creating and reading from a large pack with over X entries.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   284
        This causes it to use a 2^16 fanout table instead."""
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   285
        total = basepack.SMALLFANOUTCUTOFF + 1
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   286
        revisions = []
40783
ba706e3082bd py3: use pycompat.xrange instead of xrange
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40768
diff changeset
   287
        for i in pycompat.xrange(total):
40767
9446d5aa0f32 py3: convert strings to bytes in tests/test-remotefilelog-histpack.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40556
diff changeset
   288
            filename = b"foo-%d" % i
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   289
            node = self.getFakeHash()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   290
            p1 = self.getFakeHash()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   291
            p2 = self.getFakeHash()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   292
            linknode = self.getFakeHash()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   293
            revisions.append((filename, node, p1, p2, linknode, None))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   294
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   295
        pack = self.createPack(revisions)
41346
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   296
        self.assertEqual(pack.params.fanoutprefix, basepack.LARGEFANOUTPREFIX)
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   297
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   298
        for filename, node, p1, p2, linknode, copyfrom in revisions:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   299
            actual = pack.getancestors(filename, node)[node]
41346
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   300
            self.assertEqual(p1, actual[0])
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   301
            self.assertEqual(p2, actual[1])
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   302
            self.assertEqual(linknode, actual[2])
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
   303
            self.assertEqual(copyfrom, actual[3])
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
   304
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
   305
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   306
# TODO:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   307
# histpack store:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   308
# - repack two packs into one
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   309
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   310
if __name__ == '__main__':
41268
878084a495ef tests: also skip remotefilelog *.py tests on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 40783
diff changeset
   311
    if pycompat.iswindows:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41387
diff changeset
   312
        sys.exit(80)  # Skip on Windows
40545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   313
    silenttestrunner.main(__name__)