hgext/remotefilelog/repack.py
author Anton Shestakov <av6@dwimlabs.net>
Mon, 09 Jan 2023 18:09:36 +0400
branchstable
changeset 49870 9c7fb04843b5
parent 49284 d44e3c45f0e4
child 50928 d718eddf01d9
permissions -rw-r--r--
tests: optional PEP 657 error location in test-extension.t (issue6781)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
import os
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
import time
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
from mercurial.i18n import _
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
     5
from mercurial.node import short
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
     6
from mercurial import (
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
     7
    encoding,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
     8
    error,
42943
5fadf6103790 remotefilelog: replace repack lock to solve race condition
Boris Feld <boris.feld@octobus.net>
parents: 42842
diff changeset
     9
    lock as lockmod,
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
    mdiff,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    11
    policy,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    12
    scmutil,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    13
    util,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
    vfs,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    15
)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    16
from mercurial.utils import procutil
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    17
from . import (
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    18
    constants,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
    contentstore,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    20
    datapack,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    21
    historypack,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
    metadatastore,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    23
    shallowutil,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    25
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43115
diff changeset
    26
osutil = policy.importmod('osutil')
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    27
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    28
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    29
class RepackAlreadyRunning(error.Abort):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    30
    pass
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    31
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    32
43854
612b4b63fb22 remotefilelog: remove the `ensurestart` usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43849
diff changeset
    33
def backgroundrepack(repo, incremental=True, packsonly=False):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    34
    cmd = [procutil.hgexecutable(), b'-R', repo.origroot, b'repack']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    35
    msg = _(b"(running background repack)\n")
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    36
    if incremental:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    37
        cmd.append(b'--incremental')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    38
        msg = _(b"(running background incremental repack)\n")
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    39
    if packsonly:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    40
        cmd.append(b'--packsonly')
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    41
    repo.ui.warn(msg)
42497
df1419c5756a remotefilelog: tell runbgcommand to not block on child process startup
Augie Fackler <augie@google.com>
parents: 42057
diff changeset
    42
    # We know this command will find a binary, so don't block on it starting.
43849
63bb6dc62f24 remotefilelog: add a developer option to wait for background processes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43115
diff changeset
    43
    kwargs = {}
63bb6dc62f24 remotefilelog: add a developer option to wait for background processes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43115
diff changeset
    44
    if repo.ui.configbool(b'devel', b'remotefilelog.bg-wait'):
63bb6dc62f24 remotefilelog: add a developer option to wait for background processes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43115
diff changeset
    45
        kwargs['record_wait'] = repo.ui.atexit
63bb6dc62f24 remotefilelog: add a developer option to wait for background processes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43115
diff changeset
    46
43854
612b4b63fb22 remotefilelog: remove the `ensurestart` usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43849
diff changeset
    47
    procutil.runbgcommand(cmd, encoding.environ, ensurestart=False, **kwargs)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    48
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    49
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    50
def fullrepack(repo, options=None):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44452
diff changeset
    51
    """If ``packsonly`` is True, stores creating only loose objects are skipped."""
43115
4aa72cdf616f py3: delete b'' prefix from safehasattr arguments
Martin von Zweigbergk <martinvonz@google.com>
parents: 43105
diff changeset
    52
    if util.safehasattr(repo, 'shareddatastores'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    53
        datasource = contentstore.unioncontentstore(*repo.shareddatastores)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    54
        historysource = metadatastore.unionmetadatastore(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    55
            *repo.sharedhistorystores, allowincomplete=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    56
        )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    57
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    58
        packpath = shallowutil.getcachepackpath(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    59
            repo, constants.FILEPACK_CATEGORY
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    60
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    61
        _runrepack(
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    62
            repo,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    63
            datasource,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    64
            historysource,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    65
            packpath,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    66
            constants.FILEPACK_CATEGORY,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    67
            options=options,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    68
        )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    69
43115
4aa72cdf616f py3: delete b'' prefix from safehasattr arguments
Martin von Zweigbergk <martinvonz@google.com>
parents: 43105
diff changeset
    70
    if util.safehasattr(repo.manifestlog, 'datastore'):
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    71
        localdata, shareddata = _getmanifeststores(repo)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    72
        lpackpath, ldstores, lhstores = localdata
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    73
        spackpath, sdstores, shstores = shareddata
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
        # Repack the shared manifest store
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    76
        datasource = contentstore.unioncontentstore(*sdstores)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    77
        historysource = metadatastore.unionmetadatastore(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    78
            *shstores, allowincomplete=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    79
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    80
        _runrepack(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    81
            repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    82
            datasource,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    83
            historysource,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    84
            spackpath,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    85
            constants.TREEPACK_CATEGORY,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    86
            options=options,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    87
        )
40495
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
        # Repack the local manifest store
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    90
        datasource = contentstore.unioncontentstore(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    91
            *ldstores, allowincomplete=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    92
        )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
    93
        historysource = metadatastore.unionmetadatastore(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    94
            *lhstores, allowincomplete=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    95
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    96
        _runrepack(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    97
            repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    98
            datasource,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
    99
            historysource,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   100
            lpackpath,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   101
            constants.TREEPACK_CATEGORY,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   102
            options=options,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   103
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   104
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   105
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   106
def incrementalrepack(repo, options=None):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   107
    """This repacks the repo by looking at the distribution of pack files in the
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   108
    repo and performing the most minimal repack to keep the repo in good shape.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   109
    """
43115
4aa72cdf616f py3: delete b'' prefix from safehasattr arguments
Martin von Zweigbergk <martinvonz@google.com>
parents: 43105
diff changeset
   110
    if util.safehasattr(repo, 'shareddatastores'):
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   111
        packpath = shallowutil.getcachepackpath(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   112
            repo, constants.FILEPACK_CATEGORY
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   113
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   114
        _incrementalrepack(
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   115
            repo,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   116
            repo.shareddatastores,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   117
            repo.sharedhistorystores,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   118
            packpath,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   119
            constants.FILEPACK_CATEGORY,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   120
            options=options,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   121
        )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   122
43115
4aa72cdf616f py3: delete b'' prefix from safehasattr arguments
Martin von Zweigbergk <martinvonz@google.com>
parents: 43105
diff changeset
   123
    if util.safehasattr(repo.manifestlog, 'datastore'):
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   124
        localdata, shareddata = _getmanifeststores(repo)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   125
        lpackpath, ldstores, lhstores = localdata
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   126
        spackpath, sdstores, shstores = shareddata
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   127
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   128
        # Repack the shared manifest store
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   129
        _incrementalrepack(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   130
            repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   131
            sdstores,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   132
            shstores,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   133
            spackpath,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   134
            constants.TREEPACK_CATEGORY,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   135
            options=options,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   136
        )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   137
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   138
        # Repack the local manifest store
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   139
        _incrementalrepack(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   140
            repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   141
            ldstores,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   142
            lhstores,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   143
            lpackpath,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   144
            constants.TREEPACK_CATEGORY,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   145
            allowincompletedata=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   146
            options=options,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   147
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   148
40495
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 _getmanifeststores(repo):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   151
    shareddatastores = repo.manifestlog.shareddatastores
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   152
    localdatastores = repo.manifestlog.localdatastores
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   153
    sharedhistorystores = repo.manifestlog.sharedhistorystores
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   154
    localhistorystores = repo.manifestlog.localhistorystores
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   155
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   156
    sharedpackpath = shallowutil.getcachepackpath(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   157
        repo, constants.TREEPACK_CATEGORY
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   158
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   159
    localpackpath = shallowutil.getlocalpackpath(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   160
        repo.svfs.vfs.base, constants.TREEPACK_CATEGORY
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   161
    )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   162
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   163
    return (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   164
        (localpackpath, localdatastores, localhistorystores),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   165
        (sharedpackpath, shareddatastores, sharedhistorystores),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   166
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   167
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   168
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   169
def _topacks(packpath, files, constructor):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   170
    paths = list(os.path.join(packpath, p) for p in files)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   171
    packs = list(constructor(p) for p in paths)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   172
    return packs
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   173
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   174
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   175
def _deletebigpacks(repo, folder, files):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   176
    """Deletes packfiles that are bigger than ``packs.maxpacksize``.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   177
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   178
    Returns ``files` with the removed files omitted."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   179
    maxsize = repo.ui.configbytes(b"packs", b"maxpacksize")
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   180
    if maxsize <= 0:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   181
        return files
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   182
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   183
    # This only considers datapacks today, but we could broaden it to include
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   184
    # historypacks.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   185
    VALIDEXTS = [b".datapack", b".dataidx"]
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   186
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   187
    # Either an oversize index or datapack will trigger cleanup of the whole
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   188
    # pack:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   189
    oversized = {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   190
        os.path.splitext(path)[0]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   191
        for path, ftype, stat in files
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   192
        if (stat.st_size > maxsize and (os.path.splitext(path)[1] in VALIDEXTS))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   193
    }
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   194
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   195
    for rootfname in oversized:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   196
        rootpath = os.path.join(folder, rootfname)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   197
        for ext in VALIDEXTS:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   198
            path = rootpath + ext
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   199
            repo.ui.debug(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   200
                b'removing oversize packfile %s (%s)\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   201
                % (path, util.bytecount(os.stat(path).st_size))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   202
            )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   203
            os.unlink(path)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   204
    return [row for row in files if os.path.basename(row[0]) not in oversized]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   205
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   206
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   207
def _incrementalrepack(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   208
    repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   209
    datastore,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   210
    historystore,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   211
    packpath,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   212
    category,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   213
    allowincompletedata=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   214
    options=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   215
):
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   216
    shallowutil.mkstickygroupdir(repo.ui, packpath)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   217
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   218
    files = osutil.listdir(packpath, stat=True)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   219
    files = _deletebigpacks(repo, packpath, files)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   220
    datapacks = _topacks(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   221
        packpath, _computeincrementaldatapack(repo.ui, files), datapack.datapack
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   222
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   223
    datapacks.extend(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   224
        s for s in datastore if not isinstance(s, datapack.datapackstore)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   225
    )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   226
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   227
    historypacks = _topacks(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   228
        packpath,
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   229
        _computeincrementalhistorypack(repo.ui, files),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   230
        historypack.historypack,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   231
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   232
    historypacks.extend(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   233
        s
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   234
        for s in historystore
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   235
        if not isinstance(s, historypack.historypackstore)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   236
    )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   237
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   238
    # ``allhistory{files,packs}`` contains all known history packs, even ones we
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   239
    # don't plan to repack. They are used during the datapack repack to ensure
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   240
    # good ordering of nodes.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   241
    allhistoryfiles = _allpackfileswithsuffix(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   242
        files, historypack.PACKSUFFIX, historypack.INDEXSUFFIX
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   243
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   244
    allhistorypacks = _topacks(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   245
        packpath,
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   246
        (f for f, mode, stat in allhistoryfiles),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   247
        historypack.historypack,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   248
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   249
    allhistorypacks.extend(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   250
        s
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   251
        for s in historystore
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   252
        if not isinstance(s, historypack.historypackstore)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   253
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   254
    _runrepack(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   255
        repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   256
        contentstore.unioncontentstore(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   257
            *datapacks, allowincomplete=allowincompletedata
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   258
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   259
        metadatastore.unionmetadatastore(*historypacks, allowincomplete=True),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   260
        packpath,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   261
        category,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   262
        fullhistory=metadatastore.unionmetadatastore(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   263
            *allhistorypacks, allowincomplete=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   264
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   265
        options=options,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   266
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   267
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   268
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   269
def _computeincrementaldatapack(ui, files):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   270
    opts = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   271
        b'gencountlimit': ui.configint(b'remotefilelog', b'data.gencountlimit'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   272
        b'generations': ui.configlist(b'remotefilelog', b'data.generations'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   273
        b'maxrepackpacks': ui.configint(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   274
            b'remotefilelog', b'data.maxrepackpacks'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   275
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   276
        b'repackmaxpacksize': ui.configbytes(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   277
            b'remotefilelog', b'data.repackmaxpacksize'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   278
        ),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   279
        b'repacksizelimit': ui.configbytes(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   280
            b'remotefilelog', b'data.repacksizelimit'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   281
        ),
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   282
    }
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   283
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   284
    packfiles = _allpackfileswithsuffix(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   285
        files, datapack.PACKSUFFIX, datapack.INDEXSUFFIX
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   286
    )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   287
    return _computeincrementalpack(packfiles, opts)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   288
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   289
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   290
def _computeincrementalhistorypack(ui, files):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   291
    opts = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   292
        b'gencountlimit': ui.configint(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   293
            b'remotefilelog', b'history.gencountlimit'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   294
        ),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   295
        b'generations': ui.configlist(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   296
            b'remotefilelog', b'history.generations', [b'100MB']
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   297
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   298
        b'maxrepackpacks': ui.configint(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   299
            b'remotefilelog', b'history.maxrepackpacks'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   300
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   301
        b'repackmaxpacksize': ui.configbytes(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   302
            b'remotefilelog', b'history.repackmaxpacksize', b'400MB'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   303
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   304
        b'repacksizelimit': ui.configbytes(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   305
            b'remotefilelog', b'history.repacksizelimit'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   306
        ),
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   307
    }
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   308
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   309
    packfiles = _allpackfileswithsuffix(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   310
        files, historypack.PACKSUFFIX, historypack.INDEXSUFFIX
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   311
    )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   312
    return _computeincrementalpack(packfiles, opts)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   313
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   314
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   315
def _allpackfileswithsuffix(files, packsuffix, indexsuffix):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   316
    result = []
44452
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 43862
diff changeset
   317
    fileset = {fn for fn, mode, stat in files}
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   318
    for filename, mode, stat in files:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   319
        if not filename.endswith(packsuffix):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   320
            continue
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   321
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   322
        prefix = filename[: -len(packsuffix)]
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   323
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   324
        # Don't process a pack if it doesn't have an index.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   325
        if (prefix + indexsuffix) not in fileset:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   326
            continue
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   327
        result.append((prefix, mode, stat))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   328
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   329
    return result
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   330
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   331
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   332
def _computeincrementalpack(files, opts):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   333
    """Given a set of pack files along with the configuration options, this
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   334
    function computes the list of files that should be packed as part of an
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   335
    incremental repack.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   336
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   337
    It tries to strike a balance between keeping incremental repacks cheap (i.e.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   338
    packing small things when possible, and rolling the packs up to the big ones
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   339
    over time).
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   340
    """
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   341
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   342
    limits = list(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   343
        sorted((util.sizetoint(s) for s in opts[b'generations']), reverse=True)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   344
    )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   345
    limits.append(0)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   346
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   347
    # Group the packs by generation (i.e. by size)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   348
    generations = []
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
   349
    for i in range(len(limits)):
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   350
        generations.append([])
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   351
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   352
    sizes = {}
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   353
    for prefix, mode, stat in files:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   354
        size = stat.st_size
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   355
        if size > opts[b'repackmaxpacksize']:
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   356
            continue
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   357
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   358
        sizes[prefix] = size
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   359
        for i, limit in enumerate(limits):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   360
            if size > limit:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   361
                generations[i].append(prefix)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   362
                break
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   363
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   364
    # Steps for picking what packs to repack:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   365
    # 1. Pick the largest generation with > gencountlimit pack files.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   366
    # 2. Take the smallest three packs.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   367
    # 3. While total-size-of-packs < repacksizelimit: add another pack
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   368
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   369
    # Find the largest generation with more than gencountlimit packs
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   370
    genpacks = []
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   371
    for i, limit in enumerate(limits):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   372
        if len(generations[i]) > opts[b'gencountlimit']:
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   373
            # Sort to be smallest last, for easy popping later
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   374
            genpacks.extend(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   375
                sorted(generations[i], reverse=True, key=lambda x: sizes[x])
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   376
            )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   377
            break
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   378
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   379
    # Take as many packs from the generation as we can
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   380
    chosenpacks = genpacks[-3:]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   381
    genpacks = genpacks[:-3]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   382
    repacksize = sum(sizes[n] for n in chosenpacks)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   383
    while (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   384
        repacksize < opts[b'repacksizelimit']
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   385
        and genpacks
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   386
        and len(chosenpacks) < opts[b'maxrepackpacks']
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   387
    ):
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   388
        chosenpacks.append(genpacks.pop())
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   389
        repacksize += sizes[chosenpacks[-1]]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   390
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   391
    return chosenpacks
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   392
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   393
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   394
def _runrepack(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   395
    repo, data, history, packpath, category, fullhistory=None, options=None
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   396
):
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   397
    shallowutil.mkstickygroupdir(repo.ui, packpath)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   398
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   399
    def isold(repo, filename, node):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   400
        """Check if the file node is older than a limit.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   401
        Unless a limit is specified in the config the default limit is taken.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   402
        """
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   403
        filectx = repo.filectx(filename, fileid=node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   404
        filetime = repo[filectx.linkrev()].date()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   405
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   406
        ttl = repo.ui.configint(b'remotefilelog', b'nodettl')
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   407
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   408
        limit = time.time() - ttl
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   409
        return filetime[0] < limit
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   410
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   411
    garbagecollect = repo.ui.configbool(b'remotefilelog', b'gcrepack')
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   412
    if not fullhistory:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   413
        fullhistory = history
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   414
    packer = repacker(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   415
        repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   416
        data,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   417
        history,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   418
        fullhistory,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   419
        category,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   420
        gc=garbagecollect,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   421
        isold=isold,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   422
        options=options,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   423
    )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   424
41806
118c1ec4f31b remotefilelog: do not specify an explicit version for repack
Kyle Lippincott <spectral@google.com>
parents: 41365
diff changeset
   425
    with datapack.mutabledatapack(repo.ui, packpath) as dpack:
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   426
        with historypack.mutablehistorypack(repo.ui, packpath) as hpack:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   427
            try:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   428
                packer.run(dpack, hpack)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   429
            except error.LockHeld:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   430
                raise RepackAlreadyRunning(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   431
                    _(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   432
                        b"skipping repack - another repack "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   433
                        b"is already running"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   434
                    )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   435
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   436
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   437
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   438
def keepset(repo, keyfn, lastkeepkeys=None):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   439
    """Computes a keepset which is not garbage collected.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   440
    'keyfn' is a function that maps filename, node to a unique key.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   441
    'lastkeepkeys' is an optional argument and if provided the keepset
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   442
    function updates lastkeepkeys with more keys and returns the result.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   443
    """
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   444
    if not lastkeepkeys:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   445
        keepkeys = set()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   446
    else:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   447
        keepkeys = lastkeepkeys
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   448
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   449
    # We want to keep:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   450
    # 1. Working copy parent
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   451
    # 2. Draft commits
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   452
    # 3. Parents of draft commits
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   453
    # 4. Pullprefetch and bgprefetchrevs revsets if specified
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   454
    revs = [b'.', b'draft()', b'parents(draft())']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   455
    prefetchrevs = repo.ui.config(b'remotefilelog', b'pullprefetch', None)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   456
    if prefetchrevs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   457
        revs.append(b'(%s)' % prefetchrevs)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   458
    prefetchrevs = repo.ui.config(b'remotefilelog', b'bgprefetchrevs', None)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   459
    if prefetchrevs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   460
        revs.append(b'(%s)' % prefetchrevs)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   461
    revs = b'+'.join(revs)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   462
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   463
    revs = [b'sort((%s), "topo")' % revs]
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   464
    keep = scmutil.revrange(repo, revs)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   465
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   466
    processed = set()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   467
    lastmanifest = None
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   468
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   469
    # process the commits in toposorted order starting from the oldest
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   470
    for r in reversed(keep._list):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   471
        if repo[r].p1().rev() in processed:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   472
            # if the direct parent has already been processed
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   473
            # then we only need to process the delta
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   474
            m = repo[r].manifestctx().readdelta()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   475
        else:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   476
            # otherwise take the manifest and diff it
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   477
            # with the previous manifest if one exists
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   478
            if lastmanifest:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   479
                m = repo[r].manifest().diff(lastmanifest)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   480
            else:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   481
                m = repo[r].manifest()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   482
        lastmanifest = repo[r].manifest()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   483
        processed.add(r)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   484
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   485
        # populate keepkeys with keys from the current manifest
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   486
        if type(m) is dict:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   487
            # m is a result of diff of two manifests and is a dictionary that
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   488
            # maps filename to ((newnode, newflag), (oldnode, oldflag)) tuple
48913
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   489
            for filename, diff in m.items():
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   490
                if diff[0][0] is not None:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   491
                    keepkeys.add(keyfn(filename, diff[0][0]))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   492
        else:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   493
            # m is a manifest object
48913
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   494
            for filename, filenode in m.items():
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   495
                keepkeys.add(keyfn(filename, filenode))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   496
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   497
    return keepkeys
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   498
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   499
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48935
diff changeset
   500
class repacker:
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   501
    """Class for orchestrating the repack of data and history information into a
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   502
    new format.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   503
    """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   504
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   505
    def __init__(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   506
        self,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   507
        repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   508
        data,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   509
        history,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   510
        fullhistory,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   511
        category,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   512
        gc=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   513
        isold=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   514
        options=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   515
    ):
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   516
        self.repo = repo
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   517
        self.data = data
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   518
        self.history = history
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   519
        self.fullhistory = fullhistory
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   520
        self.unit = constants.getunits(category)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   521
        self.garbagecollect = gc
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   522
        self.options = options
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   523
        if self.garbagecollect:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   524
            if not isold:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   525
                raise ValueError(b"Function 'isold' is not properly specified")
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   526
            # use (filename, node) tuple as a keepset key
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   527
            self.keepkeys = keepset(repo, lambda f, n: (f, n))
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   528
            self.isold = isold
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   529
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   530
    def run(self, targetdata, targethistory):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   531
        ledger = repackledger()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   532
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   533
        with lockmod.lock(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   534
            repacklockvfs(self.repo), b"repacklock", desc=None, timeout=0
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   535
        ):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   536
            self.repo.hook(b'prerepack')
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   537
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   538
            # Populate ledger from source
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   539
            self.data.markledger(ledger, options=self.options)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   540
            self.history.markledger(ledger, options=self.options)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   541
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   542
            # Run repack
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   543
            self.repackdata(ledger, targetdata)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   544
            self.repackhistory(ledger, targethistory)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   545
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   546
            # Call cleanup on each source
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   547
            for source in ledger.sources:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   548
                source.cleanup(ledger)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   549
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   550
    def _chainorphans(self, ui, filename, nodes, orphans, deltabases):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   551
        """Reorderes ``orphans`` into a single chain inside ``nodes`` and
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   552
        ``deltabases``.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   553
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   554
        We often have orphan entries (nodes without a base that aren't
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   555
        referenced by other nodes -- i.e., part of a chain) due to gaps in
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   556
        history. Rather than store them as individual fulltexts, we prefer to
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   557
        insert them as one chain sorted by size.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   558
        """
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   559
        if not orphans:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   560
            return nodes
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   561
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   562
        def getsize(node, default=0):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   563
            meta = self.data.getmeta(filename, node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   564
            if constants.METAKEYSIZE in meta:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   565
                return meta[constants.METAKEYSIZE]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   566
            else:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   567
                return default
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   568
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   569
        # Sort orphans by size; biggest first is preferred, since it's more
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   570
        # likely to be the newest version assuming files grow over time.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   571
        # (Sort by node first to ensure the sort is stable.)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   572
        orphans = sorted(orphans)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   573
        orphans = list(sorted(orphans, key=getsize, reverse=True))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   574
        if ui.debugflag:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   575
            ui.debug(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   576
                b"%s: orphan chain: %s\n"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   577
                % (filename, b", ".join([short(s) for s in orphans]))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   578
            )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   579
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   580
        # Create one contiguous chain and reassign deltabases.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   581
        for i, node in enumerate(orphans):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   582
            if i == 0:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   583
                deltabases[node] = (self.repo.nullid, 0)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   584
            else:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   585
                parent = orphans[i - 1]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   586
                deltabases[node] = (parent, deltabases[parent][1] + 1)
41255
60b3edccf2f7 remotefilelog: use list comprehension instead of filter for py3 portability
Augie Fackler <augie@google.com>
parents: 40843
diff changeset
   587
        nodes = [n for n in nodes if n not in orphans]
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   588
        nodes += orphans
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   589
        return nodes
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   590
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   591
    def repackdata(self, ledger, target):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   592
        ui = self.repo.ui
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   593
        maxchainlen = ui.configint(b'packs', b'maxchainlen', 1000)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   594
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   595
        byfile = {}
48935
2cce2fa5bcf7 py3: replace pycompat.itervalues(x) with x.values()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48913
diff changeset
   596
        for entry in ledger.entries.values():
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   597
            if entry.datasource:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   598
                byfile.setdefault(entry.filename, {})[entry.node] = entry
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   599
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   600
        count = 0
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   601
        repackprogress = ui.makeprogress(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   602
            _(b"repacking data"), unit=self.unit, total=len(byfile)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   603
        )
48913
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   604
        for filename, entries in sorted(byfile.items()):
40843
b80915b52476 remotefilelog: use progress helper in repack
Martin von Zweigbergk <martinvonz@google.com>
parents: 40804
diff changeset
   605
            repackprogress.update(count)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   606
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   607
            ancestors = {}
40613
9769e0f6ffe0 py3: don't use dict.iterkeys()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40526
diff changeset
   608
            nodes = list(node for node in entries)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   609
            nohistory = []
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   610
            buildprogress = ui.makeprogress(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   611
                _(b"building history"), unit=b'nodes', total=len(nodes)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   612
            )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   613
            for i, node in enumerate(nodes):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   614
                if node in ancestors:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   615
                    continue
40843
b80915b52476 remotefilelog: use progress helper in repack
Martin von Zweigbergk <martinvonz@google.com>
parents: 40804
diff changeset
   616
                buildprogress.update(i)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   617
                try:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   618
                    ancestors.update(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   619
                        self.fullhistory.getancestors(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   620
                            filename, node, known=ancestors
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   621
                        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   622
                    )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   623
                except KeyError:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   624
                    # Since we're packing data entries, we may not have the
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   625
                    # corresponding history entries for them. It's not a big
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   626
                    # deal, but the entries won't be delta'd perfectly.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   627
                    nohistory.append(node)
40843
b80915b52476 remotefilelog: use progress helper in repack
Martin von Zweigbergk <martinvonz@google.com>
parents: 40804
diff changeset
   628
            buildprogress.complete()
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   629
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   630
            # Order the nodes children first, so we can produce reverse deltas
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   631
            orderednodes = list(reversed(self._toposort(ancestors)))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   632
            if len(nohistory) > 0:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   633
                ui.debug(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   634
                    b'repackdata: %d nodes without history\n' % len(nohistory)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   635
                )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   636
            orderednodes.extend(sorted(nohistory))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   637
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   638
            # Filter orderednodes to just the nodes we want to serialize (it
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   639
            # currently also has the edge nodes' ancestors).
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   640
            orderednodes = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   641
                filter(lambda node: node in nodes, orderednodes)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   642
            )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   643
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   644
            # Garbage collect old nodes:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   645
            if self.garbagecollect:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   646
                neworderednodes = []
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   647
                for node in orderednodes:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   648
                    # If the node is old and is not in the keepset, we skip it,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   649
                    # and mark as garbage collected
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   650
                    if (filename, node) not in self.keepkeys and self.isold(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   651
                        self.repo, filename, node
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   652
                    ):
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   653
                        entries[node].gced = True
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   654
                        continue
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   655
                    neworderednodes.append(node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   656
                orderednodes = neworderednodes
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   657
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   658
            # Compute delta bases for nodes:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   659
            deltabases = {}
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   660
            nobase = set()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   661
            referenced = set()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   662
            nodes = set(nodes)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   663
            processprogress = ui.makeprogress(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   664
                _(b"processing nodes"), unit=b'nodes', total=len(orderednodes)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   665
            )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   666
            for i, node in enumerate(orderednodes):
40843
b80915b52476 remotefilelog: use progress helper in repack
Martin von Zweigbergk <martinvonz@google.com>
parents: 40804
diff changeset
   667
                processprogress.update(i)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   668
                # Find delta base
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   669
                # TODO: allow delta'ing against most recent descendant instead
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   670
                # of immediate child
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   671
                deltatuple = deltabases.get(node, None)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   672
                if deltatuple is None:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   673
                    deltabase, chainlen = self.repo.nullid, 0
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   674
                    deltabases[node] = (self.repo.nullid, 0)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   675
                    nobase.add(node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   676
                else:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   677
                    deltabase, chainlen = deltatuple
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   678
                    referenced.add(deltabase)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   679
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   680
                # Use available ancestor information to inform our delta choices
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   681
                ancestorinfo = ancestors.get(node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   682
                if ancestorinfo:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   683
                    p1, p2, linknode, copyfrom = ancestorinfo
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   684
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   685
                    # The presence of copyfrom means we're at a point where the
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   686
                    # file was copied from elsewhere. So don't attempt to do any
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   687
                    # deltas with the other file.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   688
                    if copyfrom:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   689
                        p1 = self.repo.nullid
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   690
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   691
                    if chainlen < maxchainlen:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   692
                        # Record this child as the delta base for its parents.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   693
                        # This may be non optimal, since the parents may have
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   694
                        # many children, and this will only choose the last one.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   695
                        # TODO: record all children and try all deltas to find
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   696
                        # best
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   697
                        if p1 != self.repo.nullid:
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   698
                            deltabases[p1] = (node, chainlen + 1)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   699
                        if p2 != self.repo.nullid:
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   700
                            deltabases[p2] = (node, chainlen + 1)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   701
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   702
            # experimental config: repack.chainorphansbysize
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   703
            if ui.configbool(b'repack', b'chainorphansbysize'):
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   704
                orphans = nobase - referenced
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   705
                orderednodes = self._chainorphans(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   706
                    ui, filename, orderednodes, orphans, deltabases
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   707
                )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   708
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   709
            # Compute deltas and write to the pack
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   710
            for i, node in enumerate(orderednodes):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   711
                deltabase, chainlen = deltabases[node]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   712
                # Compute delta
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   713
                # TODO: Optimize the deltachain fetching. Since we're
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   714
                # iterating over the different version of the file, we may
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   715
                # be fetching the same deltachain over and over again.
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   716
                if deltabase != self.repo.nullid:
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   717
                    deltaentry = self.data.getdelta(filename, node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   718
                    delta, deltabasename, origdeltabase, meta = deltaentry
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   719
                    size = meta.get(constants.METAKEYSIZE)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   720
                    if (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   721
                        deltabasename != filename
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   722
                        or origdeltabase != deltabase
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   723
                        or size is None
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   724
                    ):
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   725
                        deltabasetext = self.data.get(filename, deltabase)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   726
                        original = self.data.get(filename, node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   727
                        size = len(original)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   728
                        delta = mdiff.textdiff(deltabasetext, original)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   729
                else:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   730
                    delta = self.data.get(filename, node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   731
                    size = len(delta)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   732
                    meta = self.data.getmeta(filename, node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   733
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   734
                # TODO: don't use the delta if it's larger than the fulltext
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   735
                if constants.METAKEYSIZE not in meta:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   736
                    meta[constants.METAKEYSIZE] = size
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   737
                target.add(filename, node, deltabase, delta, meta)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   738
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   739
                entries[node].datarepacked = True
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   740
40843
b80915b52476 remotefilelog: use progress helper in repack
Martin von Zweigbergk <martinvonz@google.com>
parents: 40804
diff changeset
   741
            processprogress.complete()
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   742
            count += 1
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   743
40843
b80915b52476 remotefilelog: use progress helper in repack
Martin von Zweigbergk <martinvonz@google.com>
parents: 40804
diff changeset
   744
        repackprogress.complete()
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   745
        target.close(ledger=ledger)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   746
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   747
    def repackhistory(self, ledger, target):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   748
        ui = self.repo.ui
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   749
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   750
        byfile = {}
48935
2cce2fa5bcf7 py3: replace pycompat.itervalues(x) with x.values()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48913
diff changeset
   751
        for entry in ledger.entries.values():
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   752
            if entry.historysource:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   753
                byfile.setdefault(entry.filename, {})[entry.node] = entry
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   754
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   755
        progress = ui.makeprogress(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   756
            _(b"repacking history"), unit=self.unit, total=len(byfile)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   757
        )
48913
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   758
        for filename, entries in sorted(byfile.items()):
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   759
            ancestors = {}
40613
9769e0f6ffe0 py3: don't use dict.iterkeys()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40526
diff changeset
   760
            nodes = list(node for node in entries)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   761
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   762
            for node in nodes:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   763
                if node in ancestors:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   764
                    continue
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   765
                ancestors.update(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   766
                    self.history.getancestors(filename, node, known=ancestors)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   767
                )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   768
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   769
            # Order the nodes children first
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   770
            orderednodes = reversed(self._toposort(ancestors))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   771
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   772
            # Write to the pack
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   773
            dontprocess = set()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   774
            for node in orderednodes:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   775
                p1, p2, linknode, copyfrom = ancestors[node]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   776
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   777
                # If the node is marked dontprocess, but it's also in the
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   778
                # explicit entries set, that means the node exists both in this
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   779
                # file and in another file that was copied to this file.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   780
                # Usually this happens if the file was copied to another file,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   781
                # then the copy was deleted, then reintroduced without copy
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   782
                # metadata. The original add and the new add have the same hash
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   783
                # since the content is identical and the parents are null.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   784
                if node in dontprocess and node not in entries:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   785
                    # If copyfrom == filename, it means the copy history
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   786
                    # went to come other file, then came back to this one, so we
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   787
                    # should continue processing it.
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   788
                    if p1 != self.repo.nullid and copyfrom != filename:
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   789
                        dontprocess.add(p1)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   790
                    if p2 != self.repo.nullid:
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   791
                        dontprocess.add(p2)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   792
                    continue
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   793
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   794
                if copyfrom:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   795
                    dontprocess.add(p1)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   796
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   797
                target.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
   798
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   799
                if node in entries:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   800
                    entries[node].historyrepacked = True
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   801
40843
b80915b52476 remotefilelog: use progress helper in repack
Martin von Zweigbergk <martinvonz@google.com>
parents: 40804
diff changeset
   802
            progress.increment()
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   803
40843
b80915b52476 remotefilelog: use progress helper in repack
Martin von Zweigbergk <martinvonz@google.com>
parents: 40804
diff changeset
   804
        progress.complete()
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   805
        target.close(ledger=ledger)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   806
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   807
    def _toposort(self, ancestors):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   808
        def parentfunc(node):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   809
            p1, p2, linknode, copyfrom = ancestors[node]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   810
            parents = []
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   811
            if p1 != self.repo.nullid:
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   812
                parents.append(p1)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   813
            if p2 != self.repo.nullid:
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   814
                parents.append(p2)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   815
            return parents
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   816
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   817
        sortednodes = shallowutil.sortnodes(ancestors.keys(), parentfunc)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   818
        return sortednodes
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   819
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   820
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48935
diff changeset
   821
class repackledger:
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   822
    """Storage for all the bookkeeping that happens during a repack. It contains
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   823
    the list of revisions being repacked, what happened to each revision, and
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   824
    which source store contained which revision originally (for later cleanup).
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   825
    """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   826
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   827
    def __init__(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   828
        self.entries = {}
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   829
        self.sources = {}
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   830
        self.created = set()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   831
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   832
    def markdataentry(self, source, filename, node):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   833
        """Mark the given filename+node revision as having a data rev in the
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   834
        given source.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   835
        """
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   836
        entry = self._getorcreateentry(filename, node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   837
        entry.datasource = True
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   838
        entries = self.sources.get(source)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   839
        if not entries:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   840
            entries = set()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   841
            self.sources[source] = entries
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   842
        entries.add(entry)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   843
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   844
    def markhistoryentry(self, source, filename, node):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   845
        """Mark the given filename+node revision as having a history rev in the
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   846
        given source.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   847
        """
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   848
        entry = self._getorcreateentry(filename, node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   849
        entry.historysource = True
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   850
        entries = self.sources.get(source)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   851
        if not entries:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   852
            entries = set()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   853
            self.sources[source] = entries
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   854
        entries.add(entry)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   855
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   856
    def _getorcreateentry(self, filename, node):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   857
        key = (filename, node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   858
        value = self.entries.get(key)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   859
        if not value:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   860
            value = repackentry(filename, node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   861
            self.entries[key] = value
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   862
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   863
        return value
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   864
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   865
    def addcreated(self, value):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   866
        self.created.add(value)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   867
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   868
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48935
diff changeset
   869
class repackentry:
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44452
diff changeset
   870
    """Simple class representing a single revision entry in the repackledger."""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   871
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   872
    __slots__ = (
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43115
diff changeset
   873
        'filename',
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43115
diff changeset
   874
        'node',
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43115
diff changeset
   875
        'datasource',
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43115
diff changeset
   876
        'historysource',
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43115
diff changeset
   877
        'datarepacked',
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43115
diff changeset
   878
        'historyrepacked',
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43115
diff changeset
   879
        'gced',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   880
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   881
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   882
    def __init__(self, filename, node):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   883
        self.filename = filename
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   884
        self.node = node
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   885
        # If the revision has a data entry in the source
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   886
        self.datasource = False
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   887
        # If the revision has a history entry in the source
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   888
        self.historysource = False
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   889
        # If the revision's data entry was repacked into the repack target
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   890
        self.datarepacked = False
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   891
        # If the revision's history entry was repacked into the repack target
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   892
        self.historyrepacked = False
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   893
        # If garbage collected
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   894
        self.gced = False
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   895
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   896
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   897
def repacklockvfs(repo):
43115
4aa72cdf616f py3: delete b'' prefix from safehasattr arguments
Martin von Zweigbergk <martinvonz@google.com>
parents: 43105
diff changeset
   898
    if util.safehasattr(repo, 'name'):
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   899
        # Lock in the shared cache so repacks across multiple copies of the same
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   900
        # repo are coordinated.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   901
        sharedcachepath = shallowutil.getcachepackpath(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   902
            repo, constants.FILEPACK_CATEGORY
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42943
diff changeset
   903
        )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   904
        return vfs.vfs(sharedcachepath)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   905
    else:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
   906
        return repo.svfs