mercurial/changegroup.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Thu, 07 Mar 2024 04:15:23 +0100
changeset 51536 718f28ea3af4
parent 51395 a0d88b021a98
permissions -rw-r--r--
branchcache: add a "pure topological head" fast path In a narrow but actually quick common case, all topological heads are all on the same branch and all open. In this case, computing the branch map is very simple. We can quickly detect situation where this situation will not change. So we update the V3 format to be able to express this situation and upgrade the update code to detect we remains in that mode. The branch cache is populated with the actual value when the branch map is accessed, but the update_disk method can do the update without needing to populate it.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8226
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
     1
# changegroup.py - Mercurial changegroup manipulation functions
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
     2
#
46819
d4ba4d51f85f contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents: 46794
diff changeset
     3
#  Copyright 2006 Olivia Mackall <olivia@selenic.com>
8226
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
     4
#
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
     5
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9437
diff changeset
     6
# GNU General Public License version 2 or any later version.
3877
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3859
diff changeset
     7
25921
74b303a637bc changegroup: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25831
diff changeset
     8
74b303a637bc changegroup: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25831
diff changeset
     9
import os
74b303a637bc changegroup: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25831
diff changeset
    10
import struct
20933
d3775db748a0 localrepo: move the addchangegroup method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20932
diff changeset
    11
import weakref
25921
74b303a637bc changegroup: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25831
diff changeset
    12
74b303a637bc changegroup: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25831
diff changeset
    13
from .i18n import _
74b303a637bc changegroup: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25831
diff changeset
    14
from .node import (
74b303a637bc changegroup: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25831
diff changeset
    15
    hex,
74b303a637bc changegroup: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25831
diff changeset
    16
    nullrev,
74b303a637bc changegroup: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25831
diff changeset
    17
    short,
74b303a637bc changegroup: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25831
diff changeset
    18
)
43085
eef9a2d67051 py3: manually import pycompat.open into files that need it
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
    19
from .pycompat import open
25921
74b303a637bc changegroup: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25831
diff changeset
    20
74b303a637bc changegroup: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25831
diff changeset
    21
from . import (
74b303a637bc changegroup: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25831
diff changeset
    22
    error,
38794
1d01cf0416a5 changegroup: move file matcher from narrow extension
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38783
diff changeset
    23
    match as matchmod,
25921
74b303a637bc changegroup: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25831
diff changeset
    24
    mdiff,
74b303a637bc changegroup: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25831
diff changeset
    25
    phases,
30925
82f1ef8b4477 py3: convert the mode argument of os.fdopen to unicodes (2 of 2)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30743
diff changeset
    26
    pycompat,
45372
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45371
diff changeset
    27
    requirements,
45552
10284ce3d5ed scmutil: introduce function to check whether repo uses treemanifest or not
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
    28
    scmutil,
42813
268662aac075 interfaces: create a new folder for interfaces and move repository.py in it
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42341
diff changeset
    29
    util,
268662aac075 interfaces: create a new folder for interfaces and move repository.py in it
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42341
diff changeset
    30
)
268662aac075 interfaces: create a new folder for interfaces and move repository.py in it
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42341
diff changeset
    31
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
    32
from .interfaces import repository
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
    33
from .revlogutils import sidedata as sidedatamod
47073
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
    34
from .revlogutils import constants as revlog_constants
47077
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
    35
from .utils import storageutil
1981
736b6c96bbbc make incoming work via ssh (issue139); move chunk code into separate module.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    36
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    37
_CHANGEGROUPV1_DELTA_HEADER = struct.Struct(b"20s20s20s20s")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    38
_CHANGEGROUPV2_DELTA_HEADER = struct.Struct(b"20s20s20s20s20s")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    39
_CHANGEGROUPV3_DELTA_HEADER = struct.Struct(b">20s20s20s20s20sH")
47077
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
    40
_CHANGEGROUPV4_DELTA_HEADER = struct.Struct(b">B20s20s20s20s20sH")
14141
bd1cbfe5db5c bundler: make parsechunk return the base revision of the delta
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14060
diff changeset
    41
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    42
LFS_REQUIREMENT = b'lfs'
37132
a54113fcc8c9 lfs: move the 'supportedoutgoingversions' handling to changegroup.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 37084
diff changeset
    43
35754
fb0be099063f util: move 'readexactly' in the util module
Boris Feld <boris.feld@octobus.net>
parents: 35012
diff changeset
    44
readexactly = util.readexactly
13457
e74fe15dc7fd changegroup: verify all stream reads
Mads Kiilerich <mads@kiilerich.com>
parents: 13456
diff changeset
    45
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
    46
13457
e74fe15dc7fd changegroup: verify all stream reads
Mads Kiilerich <mads@kiilerich.com>
parents: 13456
diff changeset
    47
def getchunk(stream):
e74fe15dc7fd changegroup: verify all stream reads
Mads Kiilerich <mads@kiilerich.com>
parents: 13456
diff changeset
    48
    """return the next chunk from stream as a string"""
e74fe15dc7fd changegroup: verify all stream reads
Mads Kiilerich <mads@kiilerich.com>
parents: 13456
diff changeset
    49
    d = readexactly(stream, 4)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    50
    l = struct.unpack(b">l", d)[0]
1981
736b6c96bbbc make incoming work via ssh (issue139); move chunk code into separate module.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    51
    if l <= 4:
13458
9f2c407caf34 changegroup: don't accept odd chunk headers
Mads Kiilerich <mads@kiilerich.com>
parents: 13457
diff changeset
    52
        if l:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    53
            raise error.Abort(_(b"invalid chunk length %d") % l)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    54
        return b""
13457
e74fe15dc7fd changegroup: verify all stream reads
Mads Kiilerich <mads@kiilerich.com>
parents: 13456
diff changeset
    55
    return readexactly(stream, l - 4)
1981
736b6c96bbbc make incoming work via ssh (issue139); move chunk code into separate module.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    56
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
    57
5368
61462e7d62ed changegroup: avoid large copies
Matt Mackall <mpm@selenic.com>
parents: 3932
diff changeset
    58
def chunkheader(length):
9437
1c4e4004f3a6 Improve some docstrings relating to changegroups and prepush().
Greg Ward <greg-hg@gerg.ca>
parents: 9087
diff changeset
    59
    """return a changegroup chunk header (string)"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    60
    return struct.pack(b">l", length + 4)
1981
736b6c96bbbc make incoming work via ssh (issue139); move chunk code into separate module.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    61
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
    62
1981
736b6c96bbbc make incoming work via ssh (issue139); move chunk code into separate module.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    63
def closechunk():
9437
1c4e4004f3a6 Improve some docstrings relating to changegroups and prepush().
Greg Ward <greg-hg@gerg.ca>
parents: 9087
diff changeset
    64
    """return a changegroup chunk header (string) for a zero-length chunk"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    65
    return struct.pack(b">l", 0)
1981
736b6c96bbbc make incoming work via ssh (issue139); move chunk code into separate module.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    66
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
    67
38981
227ebd88ce5e changegroup: pull _fileheader out of cgpacker
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38980
diff changeset
    68
def _fileheader(path):
227ebd88ce5e changegroup: pull _fileheader out of cgpacker
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38980
diff changeset
    69
    """Obtain a changegroup chunk header for a named path."""
227ebd88ce5e changegroup: pull _fileheader out of cgpacker
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38980
diff changeset
    70
    return chunkheader(len(path)) + path
227ebd88ce5e changegroup: pull _fileheader out of cgpacker
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38980
diff changeset
    71
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
    72
26540
7469067de2ba changegroup: extract the file management part in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26509
diff changeset
    73
def writechunks(ui, chunks, filename, vfs=None):
7469067de2ba changegroup: extract the file management part in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26509
diff changeset
    74
    """Write chunks to a file and return its filename.
3659
025f68f22ae2 move write_bundle to changegroup.py
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    75
26540
7469067de2ba changegroup: extract the file management part in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26509
diff changeset
    76
    The stream is assumed to be a bundle file.
3659
025f68f22ae2 move write_bundle to changegroup.py
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    77
    Existing files will not be overwritten.
025f68f22ae2 move write_bundle to changegroup.py
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    78
    If no filename is specified, a temporary file is created.
025f68f22ae2 move write_bundle to changegroup.py
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    79
    """
025f68f22ae2 move write_bundle to changegroup.py
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    80
    fh = None
025f68f22ae2 move write_bundle to changegroup.py
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    81
    cleanup = None
025f68f22ae2 move write_bundle to changegroup.py
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    82
    try:
025f68f22ae2 move write_bundle to changegroup.py
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    83
        if filename:
20976
c20f4898631e changegroup: add "vfs" argument to "writebundle()" for relative access via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20966
diff changeset
    84
            if vfs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    85
                fh = vfs.open(filename, b"wb")
20976
c20f4898631e changegroup: add "vfs" argument to "writebundle()" for relative access via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20966
diff changeset
    86
            else:
30212
260af19891f2 changegroup: increase write buffer size to 128k
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30211
diff changeset
    87
                # Increase default buffer size because default is usually
260af19891f2 changegroup: increase write buffer size to 128k
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30211
diff changeset
    88
                # small (4k is common on Linux).
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    89
                fh = open(filename, b"wb", 131072)
3659
025f68f22ae2 move write_bundle to changegroup.py
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    90
        else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    91
            fd, filename = pycompat.mkstemp(prefix=b"hg-bundle-", suffix=b".hg")
43503
313e3a279828 cleanup: remove pointless r-prefixes on double-quoted strings
Augie Fackler <augie@google.com>
parents: 43490
diff changeset
    92
            fh = os.fdopen(fd, "wb")
3659
025f68f22ae2 move write_bundle to changegroup.py
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    93
        cleanup = filename
26540
7469067de2ba changegroup: extract the file management part in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26509
diff changeset
    94
        for c in chunks:
7469067de2ba changegroup: extract the file management part in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26509
diff changeset
    95
            fh.write(c)
3659
025f68f22ae2 move write_bundle to changegroup.py
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    96
        cleanup = None
025f68f22ae2 move write_bundle to changegroup.py
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    97
        return filename
025f68f22ae2 move write_bundle to changegroup.py
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    98
    finally:
025f68f22ae2 move write_bundle to changegroup.py
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
    99
        if fh is not None:
025f68f22ae2 move write_bundle to changegroup.py
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
   100
            fh.close()
025f68f22ae2 move write_bundle to changegroup.py
Matt Mackall <mpm@selenic.com>
parents: 2470
diff changeset
   101
        if cleanup is not None:
20976
c20f4898631e changegroup: add "vfs" argument to "writebundle()" for relative access via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20966
diff changeset
   102
            if filename and vfs:
c20f4898631e changegroup: add "vfs" argument to "writebundle()" for relative access via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20966
diff changeset
   103
                vfs.unlink(cleanup)
c20f4898631e changegroup: add "vfs" argument to "writebundle()" for relative access via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20966
diff changeset
   104
            else:
c20f4898631e changegroup: add "vfs" argument to "writebundle()" for relative access via vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20966
diff changeset
   105
                os.unlink(cleanup)
3660
8500a13ec44b create a readbundle function
Matt Mackall <mpm@selenic.com>
parents: 3659
diff changeset
   106
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   107
49611
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   108
def _dbg_ubdl_line(
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   109
    ui,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   110
    indent,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   111
    key,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   112
    base_value=None,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   113
    percentage_base=None,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   114
    percentage_key=None,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   115
):
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   116
    """Print one line of debug_unbundle_debug_info"""
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   117
    line = b"DEBUG-UNBUNDLING: "
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   118
    line += b' ' * (2 * indent)
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   119
    key += b":"
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   120
    padding = b''
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   121
    if base_value is not None:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   122
        assert len(key) + 1 + (2 * indent) <= _KEY_PART_WIDTH
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   123
        line += key.ljust(_KEY_PART_WIDTH - (2 * indent))
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   124
        if isinstance(base_value, float):
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   125
            line += b"%14.3f seconds" % base_value
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   126
        else:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   127
            line += b"%10d" % base_value
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   128
            padding = b'            '
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   129
    else:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   130
        line += key
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   131
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   132
    if percentage_base is not None:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   133
        line += padding
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   134
        padding = b''
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   135
        assert base_value is not None
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   136
        percentage = base_value * 100 // percentage_base
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   137
        if percentage_key is not None:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   138
            line += b" (%3d%% of %s)" % (
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   139
                percentage,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   140
                percentage_key,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   141
            )
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   142
        else:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   143
            line += b" (%3d%%)" % percentage
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   144
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   145
    line += b'\n'
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   146
    ui.write_err(line)
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   147
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   148
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   149
def _sumf(items):
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   150
    # python < 3.8 does not support a `start=0.0` argument to sum
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   151
    # So we have to cheat a bit until we drop support for those version
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   152
    if not items:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   153
        return 0.0
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   154
    return sum(items)
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   155
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   156
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   157
def display_unbundle_debug_info(ui, debug_info):
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   158
    """display an unbundling report from debug information"""
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   159
    cl_info = []
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   160
    mn_info = []
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   161
    fl_info = []
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   162
    _dispatch = [
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   163
        (b'CHANGELOG:', cl_info),
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   164
        (b'MANIFESTLOG:', mn_info),
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   165
        (b'FILELOG:', fl_info),
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   166
    ]
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   167
    for e in debug_info:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   168
        for prefix, info in _dispatch:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   169
            if e["target-revlog"].startswith(prefix):
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   170
                info.append(e)
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   171
                break
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   172
        else:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   173
            assert False, 'unreachable'
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   174
    each_info = [
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   175
        (b'changelog', cl_info),
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   176
        (b'manifests', mn_info),
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   177
        (b'files', fl_info),
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   178
    ]
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   179
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   180
    # General Revision Countss
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   181
    _dbg_ubdl_line(ui, 0, b'revisions', len(debug_info))
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   182
    for key, info in each_info:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   183
        if not info:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   184
            continue
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   185
        _dbg_ubdl_line(ui, 1, key, len(info), len(debug_info))
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   186
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   187
    # General Time spent
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   188
    all_durations = [e['duration'] for e in debug_info]
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   189
    all_durations.sort()
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   190
    total_duration = _sumf(all_durations)
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   191
    _dbg_ubdl_line(ui, 0, b'total-time', total_duration)
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   192
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   193
    for key, info in each_info:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   194
        if not info:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   195
            continue
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   196
        durations = [e['duration'] for e in info]
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   197
        durations.sort()
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   198
        _dbg_ubdl_line(ui, 1, key, _sumf(durations), total_duration)
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   199
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   200
    # Count and cache reuse per delta types
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   201
    each_types = {}
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   202
    for key, info in each_info:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   203
        each_types[key] = types = {
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   204
            b'full': 0,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   205
            b'full-cached': 0,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   206
            b'snapshot': 0,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   207
            b'snapshot-cached': 0,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   208
            b'delta': 0,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   209
            b'delta-cached': 0,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   210
            b'unknown': 0,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   211
            b'unknown-cached': 0,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   212
        }
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   213
        for e in info:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   214
            types[e['type']] += 1
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   215
            if e['using-cached-base']:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   216
                types[e['type'] + b'-cached'] += 1
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   217
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   218
    EXPECTED_TYPES = (b'full', b'snapshot', b'delta', b'unknown')
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   219
    if debug_info:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   220
        _dbg_ubdl_line(ui, 0, b'type-count')
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   221
    for key, info in each_info:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   222
        if info:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   223
            _dbg_ubdl_line(ui, 1, key)
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   224
        t = each_types[key]
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   225
        for tn in EXPECTED_TYPES:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   226
            if t[tn]:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   227
                tc = tn + b'-cached'
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   228
                _dbg_ubdl_line(ui, 2, tn, t[tn])
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   229
                _dbg_ubdl_line(ui, 3, b'cached', t[tc], t[tn])
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   230
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   231
    # time perf delta types and reuse
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   232
    each_type_time = {}
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   233
    for key, info in each_info:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   234
        each_type_time[key] = t = {
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   235
            b'full': [],
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   236
            b'full-cached': [],
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   237
            b'snapshot': [],
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   238
            b'snapshot-cached': [],
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   239
            b'delta': [],
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   240
            b'delta-cached': [],
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   241
            b'unknown': [],
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   242
            b'unknown-cached': [],
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   243
        }
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   244
        for e in info:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   245
            t[e['type']].append(e['duration'])
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   246
            if e['using-cached-base']:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   247
                t[e['type'] + b'-cached'].append(e['duration'])
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   248
        for t_key, value in list(t.items()):
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   249
            value.sort()
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   250
            t[t_key] = _sumf(value)
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   251
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   252
    if debug_info:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   253
        _dbg_ubdl_line(ui, 0, b'type-time')
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   254
    for key, info in each_info:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   255
        if info:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   256
            _dbg_ubdl_line(ui, 1, key)
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   257
        t = each_type_time[key]
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   258
        td = total_duration  # to same space on next lines
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   259
        for tn in EXPECTED_TYPES:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   260
            if t[tn]:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   261
                tc = tn + b'-cached'
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   262
                _dbg_ubdl_line(ui, 2, tn, t[tn], td, b"total")
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   263
                _dbg_ubdl_line(ui, 3, b'cached', t[tc], td, b"total")
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   264
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   265
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48913
diff changeset
   266
class cg1unpacker:
26708
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   267
    """Unpacker for cg1 changegroup streams.
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   268
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   269
    A changegroup unpacker handles the framing of the revision data in
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   270
    the wire format. Most consumers will want to use the apply()
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   271
    method to add the changes from the changegroup to a repository.
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   272
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   273
    If you're forwarding a changegroup unmodified to another consumer,
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   274
    use getchunks(), which returns an iterator of changegroup
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   275
    chunks. This is mostly useful for cases where you need to know the
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   276
    data stream has ended by observing the end of the changegroup.
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   277
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   278
    deltachunk() is useful only if you're applying delta data. Most
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   279
    consumers should prefer apply() instead.
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   280
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   281
    A few other public methods exist. Those are used only for
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   282
    bundlerepo and some debug commands - their use is discouraged.
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   283
    """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   284
22390
e2806b8613ca changegroup: rename bundle-related functions and classes
Sune Foldager <cryo@cyanite.org>
parents: 22070
diff changeset
   285
    deltaheader = _CHANGEGROUPV1_DELTA_HEADER
38896
271854adc3a6 changegroup: make delta header struct formatters actual structs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38895
diff changeset
   286
    deltaheadersize = deltaheader.size
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   287
    version = b'01'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   288
    _grouplistcount = 1  # One list of files after the manifests
27920
da5f23362517 changegroup: cg3 has two empty groups *after* manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 27867
diff changeset
   289
29593
953839de96ab bundle2: store changeset count when creating file bundles
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29371
diff changeset
   290
    def __init__(self, fh, alg, extras=None):
30354
a37a96d838b9 changegroup: use compression engines API
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30339
diff changeset
   291
        if alg is None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   292
            alg = b'UN'
30354
a37a96d838b9 changegroup: use compression engines API
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30339
diff changeset
   293
        if alg not in util.compengines.supportedbundletypes:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   294
            raise error.Abort(_(b'unknown stream compression type: %s') % alg)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   295
        if alg == b'BZ':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   296
            alg = b'_truncatedBZ'
30354
a37a96d838b9 changegroup: use compression engines API
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30339
diff changeset
   297
a37a96d838b9 changegroup: use compression engines API
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30339
diff changeset
   298
        compengine = util.compengines.forbundletype(alg)
a37a96d838b9 changegroup: use compression engines API
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30339
diff changeset
   299
        self._stream = compengine.decompressorreader(fh)
12044
bcc7139521b7 bundlerepo: remove duplication of bundle decompressors
Matt Mackall <mpm@selenic.com>
parents: 12043
diff changeset
   300
        self._type = alg
29593
953839de96ab bundle2: store changeset count when creating file bundles
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29371
diff changeset
   301
        self.extras = extras or {}
12334
50946802593d bundle: refactor progress callback
Matt Mackall <mpm@selenic.com>
parents: 12333
diff changeset
   302
        self.callback = None
26706
8c0c3059f478 changegroup: note why a few methods on cg1unpacker exist
Augie Fackler <augie@google.com>
parents: 26704
diff changeset
   303
8c0c3059f478 changegroup: note why a few methods on cg1unpacker exist
Augie Fackler <augie@google.com>
parents: 26704
diff changeset
   304
    # These methods (compressed, read, seek, tell) all appear to only
8c0c3059f478 changegroup: note why a few methods on cg1unpacker exist
Augie Fackler <augie@google.com>
parents: 26704
diff changeset
   305
    # be used by bundlerepo, but it's a little hard to tell.
12044
bcc7139521b7 bundlerepo: remove duplication of bundle decompressors
Matt Mackall <mpm@selenic.com>
parents: 12043
diff changeset
   306
    def compressed(self):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   307
        return self._type is not None and self._type != b'UN'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   308
12043
bef5effb3db0 bundle: introduce bundle class
Matt Mackall <mpm@selenic.com>
parents: 12042
diff changeset
   309
    def read(self, l):
bef5effb3db0 bundle: introduce bundle class
Matt Mackall <mpm@selenic.com>
parents: 12042
diff changeset
   310
        return self._stream.read(l)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   311
12330
e527b8635881 bundle: make unbundle object seekable
Matt Mackall <mpm@selenic.com>
parents: 12329
diff changeset
   312
    def seek(self, pos):
e527b8635881 bundle: make unbundle object seekable
Matt Mackall <mpm@selenic.com>
parents: 12329
diff changeset
   313
        return self._stream.seek(pos)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   314
12330
e527b8635881 bundle: make unbundle object seekable
Matt Mackall <mpm@selenic.com>
parents: 12329
diff changeset
   315
    def tell(self):
12332
680fe77ab5b8 bundlerepo: use bundle objects everywhere
Matt Mackall <mpm@selenic.com>
parents: 12330
diff changeset
   316
        return self._stream.tell()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   317
12347
6277a9469dff bundlerepo: restore close() method
Matt Mackall <mpm@selenic.com>
parents: 12336
diff changeset
   318
    def close(self):
6277a9469dff bundlerepo: restore close() method
Matt Mackall <mpm@selenic.com>
parents: 12336
diff changeset
   319
        return self._stream.close()
12334
50946802593d bundle: refactor progress callback
Matt Mackall <mpm@selenic.com>
parents: 12333
diff changeset
   320
26707
5ee6bd529300 changegroup: mark cg1unpacker.chunklength as private
Augie Fackler <augie@google.com>
parents: 26706
diff changeset
   321
    def _chunklength(self):
13459
acbe171c8fbe changegroup: fix typo introduced in 9f2c407caf34
Jim Hague <jim.hague@acm.org>
parents: 13458
diff changeset
   322
        d = readexactly(self._stream, 4)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   323
        l = struct.unpack(b">l", d)[0]
13458
9f2c407caf34 changegroup: don't accept odd chunk headers
Mads Kiilerich <mads@kiilerich.com>
parents: 13457
diff changeset
   324
        if l <= 4:
9f2c407caf34 changegroup: don't accept odd chunk headers
Mads Kiilerich <mads@kiilerich.com>
parents: 13457
diff changeset
   325
            if l:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   326
                raise error.Abort(_(b"invalid chunk length %d") % l)
13458
9f2c407caf34 changegroup: don't accept odd chunk headers
Mads Kiilerich <mads@kiilerich.com>
parents: 13457
diff changeset
   327
            return 0
9f2c407caf34 changegroup: don't accept odd chunk headers
Mads Kiilerich <mads@kiilerich.com>
parents: 13457
diff changeset
   328
        if self.callback:
12334
50946802593d bundle: refactor progress callback
Matt Mackall <mpm@selenic.com>
parents: 12333
diff changeset
   329
            self.callback()
13458
9f2c407caf34 changegroup: don't accept odd chunk headers
Mads Kiilerich <mads@kiilerich.com>
parents: 13457
diff changeset
   330
        return l - 4
12334
50946802593d bundle: refactor progress callback
Matt Mackall <mpm@selenic.com>
parents: 12333
diff changeset
   331
14144
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14143
diff changeset
   332
    def changelogheader(self):
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14143
diff changeset
   333
        """v10 does not have a changelog header chunk"""
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14143
diff changeset
   334
        return {}
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14143
diff changeset
   335
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14143
diff changeset
   336
    def manifestheader(self):
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14143
diff changeset
   337
        """v10 does not have a manifest header chunk"""
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14143
diff changeset
   338
        return {}
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14143
diff changeset
   339
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14143
diff changeset
   340
    def filelogheader(self):
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14143
diff changeset
   341
        """return the header of the filelogs chunk, v10 only has the filename"""
26707
5ee6bd529300 changegroup: mark cg1unpacker.chunklength as private
Augie Fackler <augie@google.com>
parents: 26706
diff changeset
   342
        l = self._chunklength()
14144
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14143
diff changeset
   343
        if not l:
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14143
diff changeset
   344
            return {}
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14143
diff changeset
   345
        fname = readexactly(self._stream, l)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   346
        return {b'filename': fname}
12334
50946802593d bundle: refactor progress callback
Matt Mackall <mpm@selenic.com>
parents: 12333
diff changeset
   347
14141
bd1cbfe5db5c bundler: make parsechunk return the base revision of the delta
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14060
diff changeset
   348
    def _deltaheader(self, headertuple, prevnode):
bd1cbfe5db5c bundler: make parsechunk return the base revision of the delta
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14060
diff changeset
   349
        node, p1, p2, cs = headertuple
bd1cbfe5db5c bundler: make parsechunk return the base revision of the delta
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14060
diff changeset
   350
        if prevnode is None:
bd1cbfe5db5c bundler: make parsechunk return the base revision of the delta
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14060
diff changeset
   351
            deltabase = p1
bd1cbfe5db5c bundler: make parsechunk return the base revision of the delta
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14060
diff changeset
   352
        else:
bd1cbfe5db5c bundler: make parsechunk return the base revision of the delta
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14060
diff changeset
   353
            deltabase = prevnode
27433
12f727a5b434 changegroup: add flags field to cg3 delta header
Mike Edgar <adgar@google.com>
parents: 27432
diff changeset
   354
        flags = 0
47077
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   355
        protocol_flags = 0
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   356
        return node, p1, p2, deltabase, cs, flags, protocol_flags
14141
bd1cbfe5db5c bundler: make parsechunk return the base revision of the delta
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14060
diff changeset
   357
14144
3c3c53d8343a unbundler: separate delta and header parsing
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14143
diff changeset
   358
    def deltachunk(self, prevnode):
47340
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   359
        # Chunkdata: (node, p1, p2, cs, deltabase, delta, flags, sidedata, proto_flags)
26707
5ee6bd529300 changegroup: mark cg1unpacker.chunklength as private
Augie Fackler <augie@google.com>
parents: 26706
diff changeset
   360
        l = self._chunklength()
12336
9d234f7d8a77 bundle: move chunk parsing into unbundle class
Matt Mackall <mpm@selenic.com>
parents: 12335
diff changeset
   361
        if not l:
9d234f7d8a77 bundle: move chunk parsing into unbundle class
Matt Mackall <mpm@selenic.com>
parents: 12335
diff changeset
   362
            return {}
14141
bd1cbfe5db5c bundler: make parsechunk return the base revision of the delta
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14060
diff changeset
   363
        headerdata = readexactly(self._stream, self.deltaheadersize)
38896
271854adc3a6 changegroup: make delta header struct formatters actual structs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38895
diff changeset
   364
        header = self.deltaheader.unpack(headerdata)
14141
bd1cbfe5db5c bundler: make parsechunk return the base revision of the delta
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 14060
diff changeset
   365
        delta = readexactly(self._stream, l - self.deltaheadersize)
47077
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   366
        header = self._deltaheader(header, prevnode)
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   367
        node, p1, p2, deltabase, cs, flags, protocol_flags = header
47340
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   368
        return node, p1, p2, cs, deltabase, delta, flags, {}, protocol_flags
12336
9d234f7d8a77 bundle: move chunk parsing into unbundle class
Matt Mackall <mpm@selenic.com>
parents: 12335
diff changeset
   369
20999
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   370
    def getchunks(self):
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   371
        """returns all the chunks contains in the bundle
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   372
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   373
        Used when you need to forward the binary stream to a file or another
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   374
        network API. To do so, it parse the changegroup data, otherwise it will
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   375
        block in case of sshrepo because it don't know the end of the stream.
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   376
        """
34091
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   377
        # For changegroup 1 and 2, we expect 3 parts: changelog, manifestlog,
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   378
        # and a list of filelogs. For changegroup 3, we expect 4 parts:
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   379
        # changelog, manifestlog, a list of tree manifestlogs, and a list of
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   380
        # filelogs.
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   381
        #
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   382
        # Changelog and manifestlog parts are terminated with empty chunks. The
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   383
        # tree and file parts are a list of entry sections. Each entry section
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   384
        # is a series of chunks terminating in an empty chunk. The list of these
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   385
        # entry sections is terminated in yet another empty chunk, so we know
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   386
        # we've reached the end of the tree/file list when we reach an empty
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   387
        # chunk that was proceeded by no non-empty chunks.
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   388
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   389
        parts = 0
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   390
        while parts < 2 + self._grouplistcount:
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   391
            noentries = True
20999
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   392
            while True:
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   393
                chunk = getchunk(self)
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   394
                if not chunk:
34091
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   395
                    # The first two empty chunks represent the end of the
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   396
                    # changelog and the manifestlog portions. The remaining
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   397
                    # empty chunks represent either A) the end of individual
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   398
                    # tree or file entries in the file list, or B) the end of
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   399
                    # the entire list. It's the end of the entire list if there
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   400
                    # were no entries (i.e. noentries is True).
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   401
                    if parts < 2:
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   402
                        parts += 1
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   403
                    elif noentries:
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   404
                        parts += 1
20999
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   405
                    break
34091
bbdca7e460c0 changegroup: fix to allow empty manifest parts
Durham Goode <durham@fb.com>
parents: 33712
diff changeset
   406
                noentries = False
20999
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   407
                yield chunkheader(len(chunk))
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   408
                pos = 0
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   409
                while pos < len(chunk):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   410
                    next = pos + 2 ** 20
20999
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   411
                    yield chunk[pos:next]
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   412
                    pos = next
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   413
            yield closechunk()
1e28ec9744bf changegroup: move chunk extraction into a getchunks method of unbundle10
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20978
diff changeset
   414
49611
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   415
    def _unpackmanifests(
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   416
        self,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   417
        repo,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   418
        revmap,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   419
        trp,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   420
        prog,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   421
        addrevisioncb=None,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   422
        debug_info=None,
49765
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49611
diff changeset
   423
        delta_base_reuse_policy=None,
49611
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   424
    ):
38346
83534c4ec58b changegroup: use progress helper in apply() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38164
diff changeset
   425
        self.callback = prog.increment
26712
04176eaf911b changegroup: move manifest unpacking into its own method
Augie Fackler <augie@google.com>
parents: 26711
diff changeset
   426
        # no need to check for empty manifest group here:
04176eaf911b changegroup: move manifest unpacking into its own method
Augie Fackler <augie@google.com>
parents: 26711
diff changeset
   427
        # if the result of the merge of 1 and 2 is the same in 3 and 4,
04176eaf911b changegroup: move manifest unpacking into its own method
Augie Fackler <augie@google.com>
parents: 26711
diff changeset
   428
        # no new manifest will be created and the manifest group will
04176eaf911b changegroup: move manifest unpacking into its own method
Augie Fackler <augie@google.com>
parents: 26711
diff changeset
   429
        # be empty during the pull
04176eaf911b changegroup: move manifest unpacking into its own method
Augie Fackler <augie@google.com>
parents: 26711
diff changeset
   430
        self.manifestheader()
34291
1db9abf407c5 revlog: add revmap back to revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34257
diff changeset
   431
        deltas = self.deltaiter()
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   432
        storage = repo.manifestlog.getstorage(b'')
49611
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   433
        storage.addgroup(
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   434
            deltas,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   435
            revmap,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   436
            trp,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   437
            addrevisioncb=addrevisioncb,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   438
            debug_info=debug_info,
49765
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49611
diff changeset
   439
            delta_base_reuse_policy=delta_base_reuse_policy,
49611
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   440
        )
38373
ef692614e601 progress: hide update(None) in a new complete() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 38346
diff changeset
   441
        prog.complete()
28360
11287888ce4b changegroup: exclude submanifests from manifest progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 28281
diff changeset
   442
        self.callback = None
26712
04176eaf911b changegroup: move manifest unpacking into its own method
Augie Fackler <augie@google.com>
parents: 26711
diff changeset
   443
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   444
    def apply(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   445
        self,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   446
        repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   447
        tr,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   448
        srctype,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   449
        url,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   450
        targetphase=phases.draft,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   451
        expectedtotal=None,
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
   452
        sidedata_categories=None,
49765
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49611
diff changeset
   453
        delta_base_reuse_policy=None,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   454
    ):
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   455
        """Add the changegroup returned by source.read() to this repo.
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   456
        srctype is a string like 'push', 'pull', or 'unbundle'.  url is
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   457
        the URL of the repo where this changegroup is coming from.
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   458
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   459
        Return an integer summarizing the change to this repo:
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   460
        - nothing changed or no source: 0
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   461
        - more heads than before: 1+added heads (2..n)
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   462
        - fewer heads than before: -1-removed heads (-2..-n)
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   463
        - number of heads stays the same: 1
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
   464
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
   465
        `sidedata_categories` is an optional set of the remote's sidedata wanted
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
   466
        categories.
49765
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49611
diff changeset
   467
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49611
diff changeset
   468
        `delta_base_reuse_policy` is an optional argument, when set to a value
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49611
diff changeset
   469
        it will control the way the delta contained into the bundle are reused
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49611
diff changeset
   470
        when applied in the revlog.
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49611
diff changeset
   471
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49611
diff changeset
   472
        See `DELTA_BASE_REUSE_*` entry in mercurial.revlogutils.constants.
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   473
        """
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   474
        repo = repo.unfiltered()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   475
49611
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   476
        debug_info = None
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   477
        if repo.ui.configbool(b'debug', b'unbundling-stats'):
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   478
            debug_info = []
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   479
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
   480
        # Only useful if we're adding sidedata categories. If both peers have
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
   481
        # the same categories, then we simply don't do anything.
47075
5554aacd783f sidedata: gate sidedata functionality to revlogv2 in more places
Raphaël Gomès <rgomes@octobus.net>
parents: 47073
diff changeset
   482
        adding_sidedata = (
47263
6c84fc9c9a90 changelogv2: introduce a "changelogv2" feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47216
diff changeset
   483
            (
6c84fc9c9a90 changelogv2: introduce a "changelogv2" feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47216
diff changeset
   484
                requirements.REVLOGV2_REQUIREMENT in repo.requirements
6c84fc9c9a90 changelogv2: introduce a "changelogv2" feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47216
diff changeset
   485
                or requirements.CHANGELOGV2_REQUIREMENT in repo.requirements
6c84fc9c9a90 changelogv2: introduce a "changelogv2" feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47216
diff changeset
   486
            )
47075
5554aacd783f sidedata: gate sidedata functionality to revlogv2 in more places
Raphaël Gomès <rgomes@octobus.net>
parents: 47073
diff changeset
   487
            and self.version == b'04'
5554aacd783f sidedata: gate sidedata functionality to revlogv2 in more places
Raphaël Gomès <rgomes@octobus.net>
parents: 47073
diff changeset
   488
            and srctype == b'pull'
5554aacd783f sidedata: gate sidedata functionality to revlogv2 in more places
Raphaël Gomès <rgomes@octobus.net>
parents: 47073
diff changeset
   489
        )
5554aacd783f sidedata: gate sidedata functionality to revlogv2 in more places
Raphaël Gomès <rgomes@octobus.net>
parents: 47073
diff changeset
   490
        if adding_sidedata:
47085
3aab2330b7d3 sidedata: move sidedata-related utils to the dedicated module
Raphaël Gomès <rgomes@octobus.net>
parents: 47077
diff changeset
   491
            sidedata_helpers = sidedatamod.get_sidedata_helpers(
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
   492
                repo,
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
   493
                sidedata_categories or set(),
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
   494
                pull=True,
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
   495
            )
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
   496
        else:
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
   497
            sidedata_helpers = None
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
   498
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   499
        def csmap(x):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   500
            repo.ui.debug(b"add changeset %s\n" % short(x))
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   501
            return len(cl)
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   502
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   503
        def revmap(x):
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   504
            return cl.rev(x)
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   505
26880
fa7f8b686633 changegroup: fix the scope of a try finally
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26859
diff changeset
   506
        try:
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   507
            # The transaction may already carry source information. In this
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   508
            # case we use the top level data. We overwrite the argument
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   509
            # because we need to use the top level value (if they exist)
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   510
            # in this function.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   511
            srctype = tr.hookargs.setdefault(b'source', srctype)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   512
            tr.hookargs.setdefault(b'url', url)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   513
            repo.hook(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   514
                b'prechangegroup', throw=True, **pycompat.strkwargs(tr.hookargs)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   515
            )
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   516
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   517
            # write changelog data to temp files so concurrent readers
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   518
            # will not see an inconsistent view
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   519
            cl = repo.changelog
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   520
            cl.delayupdate(tr)
51395
a0d88b021a98 unbundle: faster computation of changed heads
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50928
diff changeset
   521
            oldrevcount = len(cl)
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   522
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   523
            trp = weakref.proxy(tr)
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   524
            # pull off the changeset group
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   525
            repo.ui.status(_(b"adding changesets\n"))
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   526
            clstart = len(cl)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   527
            progress = repo.ui.makeprogress(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   528
                _(b'changesets'), unit=_(b'chunks'), total=expectedtotal
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   529
            )
38346
83534c4ec58b changegroup: use progress helper in apply() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38164
diff changeset
   530
            self.callback = progress.increment
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   531
43489
ea0b44255a31 changegroup: avoid shadowing a set with an int
Augie Fackler <augie@google.com>
parents: 43132
diff changeset
   532
            efilesset = set()
46510
fa7ae7aa0efd changegroup: don't convert revisions to node for duplicate handling
Joerg Sonnenberger <joerg@bec.de>
parents: 46509
diff changeset
   533
            duprevs = []
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   534
46509
7a93b7b3dc2d revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents: 46373
diff changeset
   535
            def ondupchangelog(cl, rev):
7a93b7b3dc2d revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents: 46373
diff changeset
   536
                if rev < clstart:
48473
8843c9a8771b pytype: stop excluding changegroup.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 47340
diff changeset
   537
                    duprevs.append(rev)  # pytype: disable=attribute-error
45789
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45788
diff changeset
   538
46509
7a93b7b3dc2d revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents: 46373
diff changeset
   539
            def onchangelog(cl, rev):
46371
0903d6b9b1df repository: introduce register_changeset callback
Joerg Sonnenberger <joerg@bec.de>
parents: 45790
diff changeset
   540
                ctx = cl.changelogrevision(rev)
48473
8843c9a8771b pytype: stop excluding changegroup.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 47340
diff changeset
   541
                assert efilesset is not None  # help pytype
46371
0903d6b9b1df repository: introduce register_changeset callback
Joerg Sonnenberger <joerg@bec.de>
parents: 45790
diff changeset
   542
                efilesset.update(ctx.files)
0903d6b9b1df repository: introduce register_changeset callback
Joerg Sonnenberger <joerg@bec.de>
parents: 45790
diff changeset
   543
                repo.register_changeset(rev, ctx)
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   544
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   545
            self.changelogheader()
34291
1db9abf407c5 revlog: add revmap back to revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34257
diff changeset
   546
            deltas = self.deltaiter()
45788
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45729
diff changeset
   547
            if not cl.addgroup(
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45729
diff changeset
   548
                deltas,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45729
diff changeset
   549
                csmap,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45729
diff changeset
   550
                trp,
46373
711ba0f1057e revlog: decouple caching from addrevision callback for addgroup
Joerg Sonnenberger <joerg@bec.de>
parents: 46371
diff changeset
   551
                alwayscache=True,
45788
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45729
diff changeset
   552
                addrevisioncb=onchangelog,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45729
diff changeset
   553
                duplicaterevisioncb=ondupchangelog,
49611
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   554
                debug_info=debug_info,
49765
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49611
diff changeset
   555
                delta_base_reuse_policy=delta_base_reuse_policy,
45788
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45729
diff changeset
   556
            ):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   557
                repo.ui.develwarn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   558
                    b'applied empty changelog from changegroup',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   559
                    config=b'warn-empty-changegroup',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   560
                )
45788
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 45729
diff changeset
   561
            efiles = len(efilesset)
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   562
            clend = len(cl)
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   563
            changesets = clend - clstart
38373
ef692614e601 progress: hide update(None) in a new complete() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 38346
diff changeset
   564
            progress.complete()
45729
44d84b726c8a unbundle: free temporary objects after use
Joerg Sonnenberger <joerg@bec.de>
parents: 45552
diff changeset
   565
            del deltas
44d84b726c8a unbundle: free temporary objects after use
Joerg Sonnenberger <joerg@bec.de>
parents: 45552
diff changeset
   566
            # TODO Python 2.7 removal
44d84b726c8a unbundle: free temporary objects after use
Joerg Sonnenberger <joerg@bec.de>
parents: 45552
diff changeset
   567
            # del efilesset
44d84b726c8a unbundle: free temporary objects after use
Joerg Sonnenberger <joerg@bec.de>
parents: 45552
diff changeset
   568
            efilesset = None
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   569
            self.callback = None
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   570
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   571
            # Keep track of the (non-changelog) revlogs we've updated and their
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   572
            # range of new revisions for sidedata rewrite.
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   573
            # TODO do something more efficient than keeping the reference to
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   574
            # the revlogs, especially memory-wise.
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   575
            touched_manifests = {}
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   576
            touched_filelogs = {}
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   577
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   578
            # pull off the manifest group
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   579
            repo.ui.status(_(b"adding manifests\n"))
38346
83534c4ec58b changegroup: use progress helper in apply() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38164
diff changeset
   580
            # We know that we'll never have more manifests than we had
83534c4ec58b changegroup: use progress helper in apply() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38164
diff changeset
   581
            # changesets.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   582
            progress = repo.ui.makeprogress(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   583
                _(b'manifests'), unit=_(b'chunks'), total=changesets
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   584
            )
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   585
            on_manifest_rev = None
47073
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   586
            if sidedata_helpers:
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   587
                if revlog_constants.KIND_MANIFESTLOG in sidedata_helpers[1]:
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   588
47073
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   589
                    def on_manifest_rev(manifest, rev):
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   590
                        range = touched_manifests.get(manifest)
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   591
                        if not range:
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   592
                            touched_manifests[manifest] = (rev, rev)
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   593
                        else:
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   594
                            assert rev == range[1] + 1
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   595
                            touched_manifests[manifest] = (range[0], rev)
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   596
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   597
            self._unpackmanifests(
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   598
                repo,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   599
                revmap,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   600
                trp,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   601
                progress,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   602
                addrevisioncb=on_manifest_rev,
49611
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   603
                debug_info=debug_info,
49765
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49611
diff changeset
   604
                delta_base_reuse_policy=delta_base_reuse_policy,
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   605
            )
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   606
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   607
            needfiles = {}
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   608
            if repo.ui.configbool(b'server', b'validate'):
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   609
                cl = repo.changelog
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   610
                ml = repo.manifestlog
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   611
                # validate incoming csets have their manifests
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
   612
                for cset in range(clstart, clend):
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   613
                    mfnode = cl.changelogrevision(cset).manifest
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   614
                    mfest = ml[mfnode].readdelta()
45789
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45788
diff changeset
   615
                    # store file nodes we must see
48913
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   616
                    for f, n in mfest.items():
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   617
                        needfiles.setdefault(f, set()).add(n)
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   618
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   619
            on_filelog_rev = None
47073
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   620
            if sidedata_helpers:
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   621
                if revlog_constants.KIND_FILELOG in sidedata_helpers[1]:
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   622
47073
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   623
                    def on_filelog_rev(filelog, rev):
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   624
                        range = touched_filelogs.get(filelog)
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   625
                        if not range:
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   626
                            touched_filelogs[filelog] = (rev, rev)
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   627
                        else:
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   628
                            assert rev == range[1] + 1
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   629
                            touched_filelogs[filelog] = (range[0], rev)
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   630
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   631
            # process the files
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   632
            repo.ui.status(_(b"adding file changes\n"))
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   633
            newrevs, newfiles = _addchangegroupfiles(
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   634
                repo,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   635
                self,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   636
                revmap,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   637
                trp,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   638
                efiles,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   639
                needfiles,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   640
                addrevisioncb=on_filelog_rev,
49611
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   641
                debug_info=debug_info,
49765
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49611
diff changeset
   642
                delta_base_reuse_policy=delta_base_reuse_policy,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   643
            )
42897
d7304434390f changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42813
diff changeset
   644
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   645
            if sidedata_helpers:
47073
64cd1496bb70 revlog: replace the old `revlog_kind` approach with the new `target` one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   646
                if revlog_constants.KIND_CHANGELOG in sidedata_helpers[1]:
47216
2bd4b5218918 revlog: pass a transaction object to `rewrite_sidedata`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47156
diff changeset
   647
                    cl.rewrite_sidedata(
2bd4b5218918 revlog: pass a transaction object to `rewrite_sidedata`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47156
diff changeset
   648
                        trp, sidedata_helpers, clstart, clend - 1
2bd4b5218918 revlog: pass a transaction object to `rewrite_sidedata`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47156
diff changeset
   649
                    )
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   650
                for mf, (startrev, endrev) in touched_manifests.items():
47216
2bd4b5218918 revlog: pass a transaction object to `rewrite_sidedata`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47156
diff changeset
   651
                    mf.rewrite_sidedata(trp, sidedata_helpers, startrev, endrev)
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   652
                for fl, (startrev, endrev) in touched_filelogs.items():
47216
2bd4b5218918 revlog: pass a transaction object to `rewrite_sidedata`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47156
diff changeset
   653
                    fl.rewrite_sidedata(trp, sidedata_helpers, startrev, endrev)
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   654
42897
d7304434390f changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42813
diff changeset
   655
            # making sure the value exists
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   656
            tr.changes.setdefault(b'changegroup-count-changesets', 0)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   657
            tr.changes.setdefault(b'changegroup-count-revisions', 0)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   658
            tr.changes.setdefault(b'changegroup-count-files', 0)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   659
            tr.changes.setdefault(b'changegroup-count-heads', 0)
42897
d7304434390f changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42813
diff changeset
   660
d7304434390f changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42813
diff changeset
   661
            # some code use bundle operation for internal purpose. They usually
d7304434390f changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42813
diff changeset
   662
            # set `ui.quiet` to do this outside of user sight. Size the report
d7304434390f changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42813
diff changeset
   663
            # of such operation now happens at the end of the transaction, that
d7304434390f changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42813
diff changeset
   664
            # ui.quiet has not direct effect on the output.
d7304434390f changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42813
diff changeset
   665
            #
d7304434390f changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42813
diff changeset
   666
            # To preserve this intend use an inelegant hack, we fail to report
d7304434390f changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42813
diff changeset
   667
            # the change if `quiet` is set. We should probably move to
d7304434390f changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42813
diff changeset
   668
            # something better, but this is a good first step to allow the "end
d7304434390f changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42813
diff changeset
   669
            # of transaction report" to pass tests.
d7304434390f changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42813
diff changeset
   670
            if not repo.ui.quiet:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   671
                tr.changes[b'changegroup-count-changesets'] += changesets
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   672
                tr.changes[b'changegroup-count-revisions'] += newrevs
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   673
                tr.changes[b'changegroup-count-files'] += newfiles
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   674
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   675
            deltaheads = 0
51395
a0d88b021a98 unbundle: faster computation of changed heads
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50928
diff changeset
   676
            newrevcount = len(cl)
a0d88b021a98 unbundle: faster computation of changed heads
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50928
diff changeset
   677
            heads_removed, heads_added = cl.diffheads(oldrevcount, newrevcount)
a0d88b021a98 unbundle: faster computation of changed heads
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50928
diff changeset
   678
            deltaheads += len(heads_added) - len(heads_removed)
a0d88b021a98 unbundle: faster computation of changed heads
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50928
diff changeset
   679
            for h in heads_added:
a0d88b021a98 unbundle: faster computation of changed heads
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50928
diff changeset
   680
                if repo[h].closesbranch():
a0d88b021a98 unbundle: faster computation of changed heads
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50928
diff changeset
   681
                    deltaheads -= 1
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   682
42897
d7304434390f changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42813
diff changeset
   683
            # see previous comment about checking ui.quiet
d7304434390f changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42813
diff changeset
   684
            if not repo.ui.quiet:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   685
                tr.changes[b'changegroup-count-heads'] += deltaheads
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   686
            repo.invalidatevolatilesets()
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   687
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   688
            if changesets > 0:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   689
                if b'node' not in tr.hookargs:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   690
                    tr.hookargs[b'node'] = hex(cl.node(clstart))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   691
                    tr.hookargs[b'node_last'] = hex(cl.node(clend - 1))
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   692
                    hookargs = dict(tr.hookargs)
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   693
                else:
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   694
                    hookargs = dict(tr.hookargs)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   695
                    hookargs[b'node'] = hex(cl.node(clstart))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   696
                    hookargs[b'node_last'] = hex(cl.node(clend - 1))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   697
                repo.hook(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   698
                    b'pretxnchangegroup',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   699
                    throw=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   700
                    **pycompat.strkwargs(hookargs)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   701
                )
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   702
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
   703
            added = range(clstart, clend)
33456
ae052d04b89e phases: rework phase movement code in 'cg.apply' to use 'registernew'
Boris Feld <boris.feld@octobus.net>
parents: 33406
diff changeset
   704
            phaseall = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   705
            if srctype in (b'push', b'serve'):
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   706
                # Old servers can not push the boundary themselves.
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   707
                # New servers won't push the boundary if changeset already
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   708
                # exists locally as secret
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   709
                #
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   710
                # We should not use added here but the list of all change in
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   711
                # the bundle
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   712
                if repo.publishing():
33456
ae052d04b89e phases: rework phase movement code in 'cg.apply' to use 'registernew'
Boris Feld <boris.feld@octobus.net>
parents: 33406
diff changeset
   713
                    targetphase = phaseall = phases.public
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   714
                else:
33456
ae052d04b89e phases: rework phase movement code in 'cg.apply' to use 'registernew'
Boris Feld <boris.feld@octobus.net>
parents: 33406
diff changeset
   715
                    # closer target phase computation
ae052d04b89e phases: rework phase movement code in 'cg.apply' to use 'registernew'
Boris Feld <boris.feld@octobus.net>
parents: 33406
diff changeset
   716
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   717
                    # Those changesets have been pushed from the
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   718
                    # outside, their phases are going to be pushed
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   719
                    # alongside. Therefor `targetphase` is
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   720
                    # ignored.
33456
ae052d04b89e phases: rework phase movement code in 'cg.apply' to use 'registernew'
Boris Feld <boris.feld@octobus.net>
parents: 33406
diff changeset
   721
                    targetphase = phaseall = phases.draft
ae052d04b89e phases: rework phase movement code in 'cg.apply' to use 'registernew'
Boris Feld <boris.feld@octobus.net>
parents: 33406
diff changeset
   722
            if added:
45790
5d65e04b6a80 phases: convert registernew users to use revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45789
diff changeset
   723
                phases.registernew(repo, tr, targetphase, added)
33456
ae052d04b89e phases: rework phase movement code in 'cg.apply' to use 'registernew'
Boris Feld <boris.feld@octobus.net>
parents: 33406
diff changeset
   724
            if phaseall is not None:
46510
fa7ae7aa0efd changegroup: don't convert revisions to node for duplicate handling
Joerg Sonnenberger <joerg@bec.de>
parents: 46509
diff changeset
   725
                if duprevs:
fa7ae7aa0efd changegroup: don't convert revisions to node for duplicate handling
Joerg Sonnenberger <joerg@bec.de>
parents: 46509
diff changeset
   726
                    duprevs.extend(added)
fa7ae7aa0efd changegroup: don't convert revisions to node for duplicate handling
Joerg Sonnenberger <joerg@bec.de>
parents: 46509
diff changeset
   727
                else:
fa7ae7aa0efd changegroup: don't convert revisions to node for duplicate handling
Joerg Sonnenberger <joerg@bec.de>
parents: 46509
diff changeset
   728
                    duprevs = added
fa7ae7aa0efd changegroup: don't convert revisions to node for duplicate handling
Joerg Sonnenberger <joerg@bec.de>
parents: 46509
diff changeset
   729
                phases.advanceboundary(repo, tr, phaseall, [], revs=duprevs)
fa7ae7aa0efd changegroup: don't convert revisions to node for duplicate handling
Joerg Sonnenberger <joerg@bec.de>
parents: 46509
diff changeset
   730
                duprevs = []
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   731
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   732
            if changesets > 0:
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   733
43778
888bd39ed555 lock: pass "success" boolean to _afterlock callbacks
Kyle Lippincott <spectral@google.com>
parents: 43503
diff changeset
   734
                def runhooks(unused_success):
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   735
                    # These hooks run when the lock releases, not when the
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   736
                    # transaction closes. So it's possible for the changelog
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   737
                    # to have changed since we last saw it.
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   738
                    if clstart >= len(repo):
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   739
                        return
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   740
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   741
                    repo.hook(b"changegroup", **pycompat.strkwargs(hookargs))
27867
7ced54ebf972 with: use context manager for transaction in changegroup apply
Bryan O'Sullivan <bryano@fb.com>
parents: 27754
diff changeset
   742
45789
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45788
diff changeset
   743
                    for rev in added:
32931
b08431e1b062 changegroup: delete "if True" and reflow
Martin von Zweigbergk <martinvonz@google.com>
parents: 32930
diff changeset
   744
                        args = hookargs.copy()
45789
09735cde6275 phases: allow registration and boundary advancement with revision sets
Joerg Sonnenberger <joerg@bec.de>
parents: 45788
diff changeset
   745
                        args[b'node'] = hex(cl.node(rev))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   746
                        del args[b'node_last']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   747
                        repo.hook(b"incoming", **pycompat.strkwargs(args))
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   748
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   749
                    repo.ui.log(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   750
                        b"incoming",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   751
                        b"%d incoming changes - new heads: %s\n",
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   752
                        len(added),
51395
a0d88b021a98 unbundle: faster computation of changed heads
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50928
diff changeset
   753
                        b', '.join([hex(c[:6]) for c in heads_added]),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   754
                    )
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   755
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   756
                tr.addpostclose(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   757
                    b'changegroup-runhooks-%020i' % clstart,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   758
                    lambda tr: repo._afterlock(runhooks),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   759
                )
49611
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   760
            if debug_info is not None:
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   761
                display_unbundle_debug_info(repo.ui, debug_info)
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   762
        finally:
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   763
            repo.ui.flush()
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   764
        # never return 0 here:
32870
b441296f8e9c changegroup: rename "dh" to the clearer "deltaheads"
Martin von Zweigbergk <martinvonz@google.com>
parents: 32869
diff changeset
   765
        if deltaheads < 0:
33030
3e102a8dd52c bundle2: record changegroup data in 'op.records' (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 32931
diff changeset
   766
            ret = deltaheads - 1
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   767
        else:
33030
3e102a8dd52c bundle2: record changegroup data in 'op.records' (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 32931
diff changeset
   768
            ret = deltaheads + 1
33461
bb72031f0ea8 changegroup: stop returning and recording added nodes in 'cg.apply'
Boris Feld <boris.feld@octobus.net>
parents: 33456
diff changeset
   769
        return ret
26695
1121fced5b20 changegroup: migrate addchangegroup() to forward to cg?unpacker.apply()
Augie Fackler <augie@google.com>
parents: 26694
diff changeset
   770
34291
1db9abf407c5 revlog: add revmap back to revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34257
diff changeset
   771
    def deltaiter(self):
34148
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34103
diff changeset
   772
        """
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34103
diff changeset
   773
        returns an iterator of the deltas in this changegroup
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34103
diff changeset
   774
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34103
diff changeset
   775
        Useful for passing to the underlying storage system to be stored.
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34103
diff changeset
   776
        """
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34103
diff changeset
   777
        chain = None
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34103
diff changeset
   778
        for chunkdata in iter(lambda: self.deltachunk(chain), {}):
47340
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   779
            # Chunkdata: (node, p1, p2, cs, deltabase, delta, flags, sidedata, proto_flags)
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   780
            yield chunkdata[:8]
34294
05131c963767 changegroup: remove dictionary creation from deltachunk
Durham Goode <durham@fb.com>
parents: 34291
diff changeset
   781
            chain = chunkdata[0]
34148
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34103
diff changeset
   782
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   783
23181
832b7ef275c8 changegroup: introduce cg2packer/unpacker
Sune Foldager <cryo@cyanite.org>
parents: 23178
diff changeset
   784
class cg2unpacker(cg1unpacker):
26708
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   785
    """Unpacker for cg2 streams.
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   786
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   787
    cg2 streams add support for generaldelta, so the delta header
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   788
    format is slightly different. All other features about the data
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   789
    remain the same.
749d913f24b8 changegroup: document the public surface area of cg?unpackers
Augie Fackler <augie@google.com>
parents: 26707
diff changeset
   790
    """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   791
23181
832b7ef275c8 changegroup: introduce cg2packer/unpacker
Sune Foldager <cryo@cyanite.org>
parents: 23178
diff changeset
   792
    deltaheader = _CHANGEGROUPV2_DELTA_HEADER
38896
271854adc3a6 changegroup: make delta header struct formatters actual structs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38895
diff changeset
   793
    deltaheadersize = deltaheader.size
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   794
    version = b'02'
23181
832b7ef275c8 changegroup: introduce cg2packer/unpacker
Sune Foldager <cryo@cyanite.org>
parents: 23178
diff changeset
   795
832b7ef275c8 changegroup: introduce cg2packer/unpacker
Sune Foldager <cryo@cyanite.org>
parents: 23178
diff changeset
   796
    def _deltaheader(self, headertuple, prevnode):
832b7ef275c8 changegroup: introduce cg2packer/unpacker
Sune Foldager <cryo@cyanite.org>
parents: 23178
diff changeset
   797
        node, p1, p2, deltabase, cs = headertuple
27433
12f727a5b434 changegroup: add flags field to cg3 delta header
Mike Edgar <adgar@google.com>
parents: 27432
diff changeset
   798
        flags = 0
47077
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   799
        protocol_flags = 0
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   800
        return node, p1, p2, deltabase, cs, flags, protocol_flags
23181
832b7ef275c8 changegroup: introduce cg2packer/unpacker
Sune Foldager <cryo@cyanite.org>
parents: 23178
diff changeset
   801
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   802
27432
77d25b913f80 changegroup: introduce cg3, which has support for exchanging treemanifests
Augie Fackler <augie@google.com>
parents: 27241
diff changeset
   803
class cg3unpacker(cg2unpacker):
77d25b913f80 changegroup: introduce cg3, which has support for exchanging treemanifests
Augie Fackler <augie@google.com>
parents: 27241
diff changeset
   804
    """Unpacker for cg3 streams.
77d25b913f80 changegroup: introduce cg3, which has support for exchanging treemanifests
Augie Fackler <augie@google.com>
parents: 27241
diff changeset
   805
27433
12f727a5b434 changegroup: add flags field to cg3 delta header
Mike Edgar <adgar@google.com>
parents: 27432
diff changeset
   806
    cg3 streams add support for exchanging treemanifests and revlog
27753
d4071cc73f46 changegroup3: add empty chunk separating directories and files
Martin von Zweigbergk <martinvonz@google.com>
parents: 27752
diff changeset
   807
    flags. It adds the revlog flags to the delta header and an empty chunk
d4071cc73f46 changegroup3: add empty chunk separating directories and files
Martin von Zweigbergk <martinvonz@google.com>
parents: 27752
diff changeset
   808
    separating manifests and files.
27432
77d25b913f80 changegroup: introduce cg3, which has support for exchanging treemanifests
Augie Fackler <augie@google.com>
parents: 27241
diff changeset
   809
    """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   810
27433
12f727a5b434 changegroup: add flags field to cg3 delta header
Mike Edgar <adgar@google.com>
parents: 27432
diff changeset
   811
    deltaheader = _CHANGEGROUPV3_DELTA_HEADER
38896
271854adc3a6 changegroup: make delta header struct formatters actual structs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38895
diff changeset
   812
    deltaheadersize = deltaheader.size
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   813
    version = b'03'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   814
    _grouplistcount = 2  # One list of manifests and one list of files
27432
77d25b913f80 changegroup: introduce cg3, which has support for exchanging treemanifests
Augie Fackler <augie@google.com>
parents: 27241
diff changeset
   815
27433
12f727a5b434 changegroup: add flags field to cg3 delta header
Mike Edgar <adgar@google.com>
parents: 27432
diff changeset
   816
    def _deltaheader(self, headertuple, prevnode):
12f727a5b434 changegroup: add flags field to cg3 delta header
Mike Edgar <adgar@google.com>
parents: 27432
diff changeset
   817
        node, p1, p2, deltabase, cs, flags = headertuple
47077
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   818
        protocol_flags = 0
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   819
        return node, p1, p2, deltabase, cs, flags, protocol_flags
27433
12f727a5b434 changegroup: add flags field to cg3 delta header
Mike Edgar <adgar@google.com>
parents: 27432
diff changeset
   820
49611
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   821
    def _unpackmanifests(
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   822
        self,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   823
        repo,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   824
        revmap,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   825
        trp,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   826
        prog,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   827
        addrevisioncb=None,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   828
        debug_info=None,
49765
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49611
diff changeset
   829
        delta_base_reuse_policy=None,
49611
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   830
    ):
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   831
        super(cg3unpacker, self)._unpackmanifests(
49611
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   832
            repo,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   833
            revmap,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   834
            trp,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   835
            prog,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   836
            addrevisioncb=addrevisioncb,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   837
            debug_info=debug_info,
49765
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49611
diff changeset
   838
            delta_base_reuse_policy=delta_base_reuse_policy,
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   839
        )
29724
4e7be6e33269 changegroup: use `iter(callable, sentinel)` instead of while True
Augie Fackler <augie@google.com>
parents: 29690
diff changeset
   840
        for chunkdata in iter(self.filelogheader, {}):
27754
a09f143daaf4 changegroup3: move treemanifest support into _unpackmanifests()
Martin von Zweigbergk <martinvonz@google.com>
parents: 27753
diff changeset
   841
            # If we get here, there are directory manifests in the changegroup
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   842
            d = chunkdata[b"filename"]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   843
            repo.ui.debug(b"adding %s revisions\n" % d)
34291
1db9abf407c5 revlog: add revmap back to revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34257
diff changeset
   844
            deltas = self.deltaiter()
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   845
            if not repo.manifestlog.getstorage(d).addgroup(
49611
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   846
                deltas,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   847
                revmap,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   848
                trp,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   849
                addrevisioncb=addrevisioncb,
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
   850
                debug_info=debug_info,
49765
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49611
diff changeset
   851
                delta_base_reuse_policy=delta_base_reuse_policy,
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
   852
            ):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   853
                raise error.Abort(_(b"received dir revlog group is empty"))
27754
a09f143daaf4 changegroup3: move treemanifest support into _unpackmanifests()
Martin von Zweigbergk <martinvonz@google.com>
parents: 27753
diff changeset
   854
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   855
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   856
class cg4unpacker(cg3unpacker):
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   857
    """Unpacker for cg4 streams.
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   858
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   859
    cg4 streams add support for exchanging sidedata.
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   860
    """
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   861
47077
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   862
    deltaheader = _CHANGEGROUPV4_DELTA_HEADER
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   863
    deltaheadersize = deltaheader.size
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   864
    version = b'04'
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   865
47077
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   866
    def _deltaheader(self, headertuple, prevnode):
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   867
        protocol_flags, node, p1, p2, deltabase, cs, flags = headertuple
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   868
        return node, p1, p2, deltabase, cs, flags, protocol_flags
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   869
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   870
    def deltachunk(self, prevnode):
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   871
        res = super(cg4unpacker, self).deltachunk(prevnode)
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   872
        if not res:
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   873
            return res
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   874
47340
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   875
        (
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   876
            node,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   877
            p1,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   878
            p2,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   879
            cs,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   880
            deltabase,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   881
            delta,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   882
            flags,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   883
            sidedata,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   884
            protocol_flags,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   885
        ) = res
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   886
        assert not sidedata
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   887
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   888
        sidedata = {}
47077
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   889
        if protocol_flags & storageutil.CG_FLAG_SIDEDATA:
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   890
            sidedata_raw = getchunk(self._stream)
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   891
            sidedata = sidedatamod.deserialize_sidedata(sidedata_raw)
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   892
47340
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   893
        return (
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   894
            node,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   895
            p1,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   896
            p2,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   897
            cs,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   898
            deltabase,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   899
            delta,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   900
            flags,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   901
            sidedata,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   902
            protocol_flags,
3f00665bbea0 changegroup: fix deltachunk API to be consistent from one class to another
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47263
diff changeset
   903
        )
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   904
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
   905
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48913
diff changeset
   906
class headerlessfixup:
12329
7458de933f26 bundle: push chunkbuffer down into decompress
Matt Mackall <mpm@selenic.com>
parents: 12044
diff changeset
   907
    def __init__(self, fh, h):
7458de933f26 bundle: push chunkbuffer down into decompress
Matt Mackall <mpm@selenic.com>
parents: 12044
diff changeset
   908
        self._h = h
7458de933f26 bundle: push chunkbuffer down into decompress
Matt Mackall <mpm@selenic.com>
parents: 12044
diff changeset
   909
        self._fh = fh
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   910
12329
7458de933f26 bundle: push chunkbuffer down into decompress
Matt Mackall <mpm@selenic.com>
parents: 12044
diff changeset
   911
    def read(self, n):
7458de933f26 bundle: push chunkbuffer down into decompress
Matt Mackall <mpm@selenic.com>
parents: 12044
diff changeset
   912
        if self._h:
7458de933f26 bundle: push chunkbuffer down into decompress
Matt Mackall <mpm@selenic.com>
parents: 12044
diff changeset
   913
            d, self._h = self._h[:n], self._h[n:]
7458de933f26 bundle: push chunkbuffer down into decompress
Matt Mackall <mpm@selenic.com>
parents: 12044
diff changeset
   914
            if len(d) < n:
13457
e74fe15dc7fd changegroup: verify all stream reads
Mads Kiilerich <mads@kiilerich.com>
parents: 13456
diff changeset
   915
                d += readexactly(self._fh, n - len(d))
12329
7458de933f26 bundle: push chunkbuffer down into decompress
Matt Mackall <mpm@selenic.com>
parents: 12044
diff changeset
   916
            return d
13457
e74fe15dc7fd changegroup: verify all stream reads
Mads Kiilerich <mads@kiilerich.com>
parents: 13456
diff changeset
   917
        return readexactly(self._fh, n)
12329
7458de933f26 bundle: push chunkbuffer down into decompress
Matt Mackall <mpm@selenic.com>
parents: 12044
diff changeset
   918
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   919
46780
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46718
diff changeset
   920
def _revisiondeltatochunks(repo, delta, headerfn):
39014
d662959dc881 changegroup: emit revisiondelta instances from deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39013
diff changeset
   921
    """Serialize a revisiondelta to changegroup chunks."""
39016
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   922
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   923
    # The captured revision delta may be encoded as a delta against
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   924
    # a base revision or as a full revision. The changegroup format
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   925
    # requires that everything on the wire be deltas. So for full
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   926
    # revisions, we need to invent a header that says to rewrite
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   927
    # data.
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   928
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   929
    if delta.delta is not None:
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   930
        prefix, data = b'', delta.delta
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46927
diff changeset
   931
    elif delta.basenode == repo.nullid:
39016
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   932
        data = delta.revision
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   933
        prefix = mdiff.trivialdiffheader(len(data))
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   934
    else:
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   935
        data = delta.revision
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   936
        prefix = mdiff.replacediffheader(delta.baserevisionsize, len(data))
39016
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   937
39014
d662959dc881 changegroup: emit revisiondelta instances from deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39013
diff changeset
   938
    meta = headerfn(delta)
39016
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   939
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   940
    yield chunkheader(len(meta) + len(prefix) + len(data))
39014
d662959dc881 changegroup: emit revisiondelta instances from deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39013
diff changeset
   941
    yield meta
39016
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   942
    if prefix:
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   943
        yield prefix
39b8277e2115 changegroup: differentiate between fulltext and diff based deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39015
diff changeset
   944
    yield data
39014
d662959dc881 changegroup: emit revisiondelta instances from deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39013
diff changeset
   945
47077
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   946
    if delta.protocol_flags & storageutil.CG_FLAG_SIDEDATA:
46712
e8c11a2c96c0 delta: add sidedata field to revision delta
Raphaël Gomès <rgomes@octobus.net>
parents: 46711
diff changeset
   947
        # Need a separate chunk for sidedata to be able to differentiate
e8c11a2c96c0 delta: add sidedata field to revision delta
Raphaël Gomès <rgomes@octobus.net>
parents: 46711
diff changeset
   948
        # "raw delta" length and sidedata length
47077
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
   949
        sidedata = delta.sidedata
46712
e8c11a2c96c0 delta: add sidedata field to revision delta
Raphaël Gomès <rgomes@octobus.net>
parents: 46711
diff changeset
   950
        yield chunkheader(len(sidedata))
e8c11a2c96c0 delta: add sidedata field to revision delta
Raphaël Gomès <rgomes@octobus.net>
parents: 46711
diff changeset
   951
        yield sidedata
e8c11a2c96c0 delta: add sidedata field to revision delta
Raphaël Gomès <rgomes@octobus.net>
parents: 46711
diff changeset
   952
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   953
38997
812eec3f89cb changegroup: remove _clnodetorev
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38996
diff changeset
   954
def _sortnodesellipsis(store, nodes, cl, lookup):
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
   955
    """Sort nodes for changegroup generation."""
38982
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
   956
    # Ellipses serving mode.
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
   957
    #
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
   958
    # In a perfect world, we'd generate better ellipsis-ified graphs
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
   959
    # for non-changelog revlogs. In practice, we haven't started doing
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
   960
    # that yet, so the resulting DAGs for the manifestlog and filelogs
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
   961
    # are actually full of bogus parentage on all the ellipsis
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
   962
    # nodes. This has the side effect that, while the contents are
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
   963
    # correct, the individual DAGs might be completely out of whack in
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
   964
    # a case like 882681bc3166 and its ancestors (back about 10
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
   965
    # revisions or so) in the main hg repo.
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
   966
    #
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
   967
    # The one invariant we *know* holds is that the new (potentially
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
   968
    # bogus) DAG shape will be valid if we order the nodes in the
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
   969
    # order that they're introduced in dramatis personae by the
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
   970
    # changelog, so what we do is we sort the non-changelog histories
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
   971
    # by the order in which they are used by the changelog.
38997
812eec3f89cb changegroup: remove _clnodetorev
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38996
diff changeset
   972
    key = lambda n: cl.rev(lookup(n))
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
   973
    return sorted(nodes, key=key)
38982
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
   974
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   975
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   976
def _resolvenarrowrevisioninfo(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   977
    cl,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   978
    store,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   979
    ischangelog,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   980
    rev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   981
    linkrev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   982
    linknode,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   983
    clrevtolocalrev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   984
    fullclnodes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   985
    precomputedellipsis,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   986
):
39004
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
   987
    linkparents = precomputedellipsis[linkrev]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
   988
39004
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
   989
    def local(clrev):
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
   990
        """Turn a changelog revnum into a local revnum.
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
   991
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
   992
        The ellipsis dag is stored as revnums on the changelog,
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
   993
        but when we're producing ellipsis entries for
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
   994
        non-changelog revlogs, we need to turn those numbers into
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
   995
        something local. This does that for us, and during the
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
   996
        changelog sending phase will also expand the stored
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
   997
        mappings as needed.
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
   998
        """
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
   999
        if clrev == nullrev:
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1000
            return nullrev
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1001
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1002
        if ischangelog:
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1003
            return clrev
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1004
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1005
        # Walk the ellipsis-ized changelog breadth-first looking for a
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1006
        # change that has been linked from the current revlog.
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1007
        #
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1008
        # For a flat manifest revlog only a single step should be necessary
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1009
        # as all relevant changelog entries are relevant to the flat
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1010
        # manifest.
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1011
        #
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1012
        # For a filelog or tree manifest dirlog however not every changelog
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1013
        # entry will have been relevant, so we need to skip some changelog
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1014
        # nodes even after ellipsis-izing.
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1015
        walk = [clrev]
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1016
        while walk:
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1017
            p = walk[0]
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1018
            walk = walk[1:]
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1019
            if p in clrevtolocalrev:
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1020
                return clrevtolocalrev[p]
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1021
            elif p in fullclnodes:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1022
                walk.extend([pp for pp in cl.parentrevs(p) if pp != nullrev])
39004
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1023
            elif p in precomputedellipsis:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1024
                walk.extend(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1025
                    [pp for pp in precomputedellipsis[p] if pp != nullrev]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1026
                )
39004
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1027
            else:
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1028
                # In this case, we've got an ellipsis with parents
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1029
                # outside the current bundle (likely an
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1030
                # incremental pull). We "know" that we can use the
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1031
                # value of this same revlog at whatever revision
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1032
                # is pointed to by linknode. "Know" is in scare
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1033
                # quotes because I haven't done enough examination
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1034
                # of edge cases to convince myself this is really
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1035
                # a fact - it works for all the (admittedly
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1036
                # thorough) cases in our testsuite, but I would be
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1037
                # somewhat unsurprised to find a case in the wild
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1038
                # where this breaks down a bit. That said, I don't
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1039
                # know if it would hurt anything.
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
  1040
                for i in range(rev, 0, -1):
39004
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1041
                    if store.linkrev(i) == clrev:
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1042
                        return i
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1043
                # We failed to resolve a parent for this node, so
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1044
                # we crash the changegroup construction.
50928
d718eddf01d9 safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49765
diff changeset
  1045
                if hasattr(store, 'target'):
47156
89e11a6da785 revlog: use revlog.display_id in narrow error message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47148
diff changeset
  1046
                    target = store.display_id
47146
bc7d465ea11e manifest: drop the `indexfile` from `manifestrevlog`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47086
diff changeset
  1047
                else:
bc7d465ea11e manifest: drop the `indexfile` from `manifestrevlog`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47086
diff changeset
  1048
                    # some revlog not actually a revlog
47156
89e11a6da785 revlog: use revlog.display_id in narrow error message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47148
diff changeset
  1049
                    target = store._revlog.display_id
47146
bc7d465ea11e manifest: drop the `indexfile` from `manifestrevlog`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47086
diff changeset
  1050
39004
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1051
                raise error.Abort(
46513
c3c7a86e9c24 tests: fix differing output between py2 and py3
Raphaël Gomès <rgomes@octobus.net>
parents: 46510
diff changeset
  1052
                    b"unable to resolve parent while packing '%s' %r"
47146
bc7d465ea11e manifest: drop the `indexfile` from `manifestrevlog`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47086
diff changeset
  1053
                    b' for changeset %r' % (target, rev, clrev)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1054
                )
39004
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1055
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1056
        return nullrev
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1057
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1058
    if not linkparents or (store.parentrevs(rev) == (nullrev, nullrev)):
39004
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1059
        p1, p2 = nullrev, nullrev
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1060
    elif len(linkparents) == 1:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1061
        (p1,) = sorted(local(p) for p in linkparents)
39004
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1062
        p2 = nullrev
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1063
    else:
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1064
        p1, p2 = sorted(local(p) for p in linkparents)
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1065
39018
e793e11e1462 changegroup: introduce requests to define delta generation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39017
diff changeset
  1066
    p1node, p2node = store.node(p1), store.node(p2)
39004
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1067
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1068
    return p1node, p2node, linknode
39004
e11d07cc125c changegroup: make _revisiondeltanarrow() a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39003
diff changeset
  1069
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1070
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1071
def deltagroup(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1072
    repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1073
    store,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1074
    nodes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1075
    ischangelog,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1076
    lookup,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1077
    forcedeltaparentprev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1078
    topic=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1079
    ellipses=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1080
    clrevtolocalrev=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1081
    fullclnodes=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1082
    precomputedellipsis=None,
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1083
    sidedata_helpers=None,
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1084
    debug_info=None,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1085
):
39014
d662959dc881 changegroup: emit revisiondelta instances from deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39013
diff changeset
  1086
    """Calculate deltas for a set of revisions.
39009
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1087
39014
d662959dc881 changegroup: emit revisiondelta instances from deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39013
diff changeset
  1088
    Is a generator of ``revisiondelta`` instances.
39009
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1089
39239
0617a700ef7b changegroup: change topics during generation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39238
diff changeset
  1090
    If topic is not None, progress detail will be generated using this
0617a700ef7b changegroup: change topics during generation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39238
diff changeset
  1091
    topic name (e.g. changesets, manifests, etc).
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1092
47086
8bd769b5c941 sidedata: move documentation about sidedata helpers to sidedata module
Raphaël Gomès <rgomes@octobus.net>
parents: 47085
diff changeset
  1093
    See `revlogutil.sidedata.get_sidedata_helpers` for the doc on
8bd769b5c941 sidedata: move documentation about sidedata helpers to sidedata module
Raphaël Gomès <rgomes@octobus.net>
parents: 47085
diff changeset
  1094
    `sidedata_helpers`.
39009
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1095
    """
39229
2646b8d66b7b changegroup: move node sorting into deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39181
diff changeset
  1096
    if not nodes:
39009
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1097
        return
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1098
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1099
    cl = repo.changelog
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1100
39229
2646b8d66b7b changegroup: move node sorting into deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39181
diff changeset
  1101
    if ischangelog:
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1102
        # `hg log` shows changesets in storage order. To preserve order
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1103
        # across clones, send out changesets in storage order.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1104
        nodesorder = b'storage'
39229
2646b8d66b7b changegroup: move node sorting into deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39181
diff changeset
  1105
    elif ellipses:
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1106
        nodes = _sortnodesellipsis(store, nodes, cl, lookup)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1107
        nodesorder = b'nodes'
39229
2646b8d66b7b changegroup: move node sorting into deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39181
diff changeset
  1108
    else:
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1109
        nodesorder = None
39229
2646b8d66b7b changegroup: move node sorting into deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39181
diff changeset
  1110
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1111
    # Perform ellipses filtering and revision massaging. We do this before
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1112
    # emitrevisions() because a) filtering out revisions creates less work
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1113
    # for emitrevisions() b) dropping revisions would break emitrevisions()'s
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1114
    # assumptions about delta choices and we would possibly send a delta
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1115
    # referencing a missing base revision.
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1116
    #
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1117
    # Also, calling lookup() has side-effects with regards to populating
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1118
    # data structures. If we don't call lookup() for each node or if we call
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1119
    # lookup() after the first pass through each node, things can break -
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1120
    # possibly intermittently depending on the python hash seed! For that
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1121
    # reason, we store a mapping of all linknodes during the initial node
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1122
    # pass rather than use lookup() on the output side.
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1123
    if ellipses:
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1124
        filtered = []
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1125
        adjustedparents = {}
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1126
        linknodes = {}
39009
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1127
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1128
        for node in nodes:
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1129
            rev = store.rev(node)
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1130
            linknode = lookup(node)
39009
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1131
            linkrev = cl.rev(linknode)
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1132
            clrevtolocalrev[linkrev] = rev
39009
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1133
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1134
            # If linknode is in fullclnodes, it means the corresponding
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1135
            # changeset was a full changeset and is being sent unaltered.
39009
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1136
            if linknode in fullclnodes:
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1137
                linknodes[node] = linknode
39018
e793e11e1462 changegroup: introduce requests to define delta generation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39017
diff changeset
  1138
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1139
            # If the corresponding changeset wasn't in the set computed
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1140
            # as relevant to us, it should be dropped outright.
39009
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1141
            elif linkrev not in precomputedellipsis:
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1142
                continue
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1143
39009
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1144
            else:
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1145
                # We could probably do this later and avoid the dict
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1146
                # holding state. But it likely doesn't matter.
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1147
                p1node, p2node, linknode = _resolvenarrowrevisioninfo(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1148
                    cl,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1149
                    store,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1150
                    ischangelog,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1151
                    rev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1152
                    linkrev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1153
                    linknode,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1154
                    clrevtolocalrev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1155
                    fullclnodes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1156
                    precomputedellipsis,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1157
                )
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1158
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1159
                adjustedparents[node] = (p1node, p2node)
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1160
                linknodes[node] = linknode
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1161
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1162
            filtered.append(node)
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1163
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1164
        nodes = filtered
39009
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1165
39018
e793e11e1462 changegroup: introduce requests to define delta generation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39017
diff changeset
  1166
    # We expect the first pass to be fast, so we only engage the progress
e793e11e1462 changegroup: introduce requests to define delta generation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39017
diff changeset
  1167
    # meter for constructing the revision deltas.
e793e11e1462 changegroup: introduce requests to define delta generation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39017
diff changeset
  1168
    progress = None
39239
0617a700ef7b changegroup: change topics during generation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39238
diff changeset
  1169
    if topic is not None:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1170
        progress = repo.ui.makeprogress(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1171
            topic, unit=_(b'chunks'), total=len(nodes)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1172
        )
39018
e793e11e1462 changegroup: introduce requests to define delta generation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39017
diff changeset
  1173
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1174
    configtarget = repo.ui.config(b'devel', b'bundle.delta')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1175
    if configtarget not in (b'', b'p1', b'full'):
46686
26d1ddc3f398 changegroup: convert a warning message to bytes
Matt Harbison <matt_harbison@yahoo.com>
parents: 45790
diff changeset
  1176
        msg = _(b"""config "devel.bundle.delta" as unknown value: %s""")
40432
968dd7e02ac5 changegroup: allow to force delta to be against p1
Boris Feld <boris.feld@octobus.net>
parents: 40430
diff changeset
  1177
        repo.ui.warn(msg % configtarget)
968dd7e02ac5 changegroup: allow to force delta to be against p1
Boris Feld <boris.feld@octobus.net>
parents: 40430
diff changeset
  1178
40430
6a917075535a storage: also use `deltamode argument` for ifiledata
Boris Feld <boris.feld@octobus.net>
parents: 40344
diff changeset
  1179
    deltamode = repository.CG_DELTAMODE_STD
6a917075535a storage: also use `deltamode argument` for ifiledata
Boris Feld <boris.feld@octobus.net>
parents: 40344
diff changeset
  1180
    if forcedeltaparentprev:
6a917075535a storage: also use `deltamode argument` for ifiledata
Boris Feld <boris.feld@octobus.net>
parents: 40344
diff changeset
  1181
        deltamode = repository.CG_DELTAMODE_PREV
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1182
    elif configtarget == b'p1':
40432
968dd7e02ac5 changegroup: allow to force delta to be against p1
Boris Feld <boris.feld@octobus.net>
parents: 40430
diff changeset
  1183
        deltamode = repository.CG_DELTAMODE_P1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1184
    elif configtarget == b'full':
40433
808b762679cd changegroup: add a option to create bundle with full snapshot only
Boris Feld <boris.feld@octobus.net>
parents: 40432
diff changeset
  1185
        deltamode = repository.CG_DELTAMODE_FULL
40430
6a917075535a storage: also use `deltamode argument` for ifiledata
Boris Feld <boris.feld@octobus.net>
parents: 40344
diff changeset
  1186
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1187
    revisions = store.emitrevisions(
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1188
        nodes,
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1189
        nodesorder=nodesorder,
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1190
        revisiondata=True,
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1191
        assumehaveparentrevisions=not ellipses,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1192
        deltamode=deltamode,
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1193
        sidedata_helpers=sidedata_helpers,
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1194
        debug_info=debug_info,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1195
    )
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1196
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1197
    for i, revision in enumerate(revisions):
39018
e793e11e1462 changegroup: introduce requests to define delta generation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39017
diff changeset
  1198
        if progress:
e793e11e1462 changegroup: introduce requests to define delta generation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39017
diff changeset
  1199
            progress.update(i + 1)
e793e11e1462 changegroup: introduce requests to define delta generation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39017
diff changeset
  1200
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1201
        if ellipses:
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1202
            linknode = linknodes[revision.node]
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1203
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1204
            if revision.node in adjustedparents:
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1205
                p1node, p2node = adjustedparents[revision.node]
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1206
                revision.p1node = p1node
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1207
                revision.p2node = p2node
40047
8e398628a3f2 repository: define and use revision flag constants
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
  1208
                revision.flags |= repository.REVISION_FLAG_ELLIPSIS
39865
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1209
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1210
        else:
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1211
            linknode = lookup(revision.node)
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1212
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1213
        revision.linknode = linknode
31b7e8e7132e changegroup: port to emitrevisions() (issue5976)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39861
diff changeset
  1214
        yield revision
39018
e793e11e1462 changegroup: introduce requests to define delta generation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39017
diff changeset
  1215
39009
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1216
    if progress:
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1217
        progress.complete()
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1218
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1219
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1220
def make_debug_info():
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1221
    """ "build a "new" debug_info dictionnary
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1222
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1223
    That dictionnary can be used to gather information about the bundle process
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1224
    """
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1225
    return {
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1226
        'revision-total': 0,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1227
        'revision-changelog': 0,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1228
        'revision-manifest': 0,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1229
        'revision-files': 0,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1230
        'file-count': 0,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1231
        'merge-total': 0,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1232
        'available-delta': 0,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1233
        'available-full': 0,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1234
        'delta-against-prev': 0,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1235
        'delta-full': 0,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1236
        'delta-against-p1': 0,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1237
        'denied-delta-candeltafn': 0,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1238
        'denied-base-not-available': 0,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1239
        'reused-storage-delta': 0,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1240
        'computed-delta': 0,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1241
    }
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1242
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1243
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1244
def merge_debug_info(base, other):
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1245
    """merge the debug information from <other> into <base>
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1246
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1247
    This function can be used to gather lower level information into higher level ones.
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1248
    """
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1249
    for key in (
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1250
        'revision-total',
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1251
        'revision-changelog',
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1252
        'revision-manifest',
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1253
        'revision-files',
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1254
        'merge-total',
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1255
        'available-delta',
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1256
        'available-full',
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1257
        'delta-against-prev',
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1258
        'delta-full',
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1259
        'delta-against-p1',
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1260
        'denied-delta-candeltafn',
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1261
        'denied-base-not-available',
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1262
        'reused-storage-delta',
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1263
        'computed-delta',
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1264
    ):
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1265
        base[key] += other[key]
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1266
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1267
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1268
_KEY_PART_WIDTH = 17
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1269
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1270
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1271
def _dbg_bdl_line(
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1272
    ui,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1273
    indent,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1274
    key,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1275
    base_value=None,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1276
    percentage_base=None,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1277
    percentage_key=None,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1278
    percentage_ref=None,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1279
    extra=None,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1280
):
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1281
    """Print one line of debug_bundle_debug_info"""
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1282
    line = b"DEBUG-BUNDLING: "
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1283
    line += b' ' * (2 * indent)
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1284
    key += b":"
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1285
    if base_value is not None:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1286
        assert len(key) + 1 + (2 * indent) <= _KEY_PART_WIDTH
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1287
        line += key.ljust(_KEY_PART_WIDTH - (2 * indent))
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1288
        line += b"%10d" % base_value
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1289
    else:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1290
        line += key
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1291
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1292
    if percentage_base is not None:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1293
        assert base_value is not None
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1294
        percentage = base_value * 100 // percentage_base
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1295
        if percentage_key is not None:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1296
            line += b" (%d%% of %s %d)" % (
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1297
                percentage,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1298
                percentage_key,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1299
                percentage_ref,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1300
            )
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1301
        else:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1302
            line += b" (%d%%)" % percentage
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1303
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1304
    if extra:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1305
        line += b" "
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1306
        line += extra
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1307
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1308
    line += b'\n'
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1309
    ui.write_err(line)
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1310
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1311
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1312
def display_bundling_debug_info(
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1313
    ui,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1314
    debug_info,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1315
    cl_debug_info,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1316
    mn_debug_info,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1317
    fl_debug_info,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1318
):
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1319
    """display debug information gathered during a bundling through `ui`"""
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1320
    d = debug_info
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1321
    c = cl_debug_info
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1322
    m = mn_debug_info
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1323
    f = fl_debug_info
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1324
    all_info = [
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1325
        (b"changelog", b"cl", c),
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1326
        (b"manifests", b"mn", m),
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1327
        (b"files", b"fl", f),
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1328
    ]
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1329
    _dbg_bdl_line(ui, 0, b'revisions', d['revision-total'])
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1330
    _dbg_bdl_line(ui, 1, b'changelog', d['revision-changelog'])
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1331
    _dbg_bdl_line(ui, 1, b'manifest', d['revision-manifest'])
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1332
    extra = b'(for %d revlogs)' % d['file-count']
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1333
    _dbg_bdl_line(ui, 1, b'files', d['revision-files'], extra=extra)
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1334
    if d['merge-total']:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1335
        _dbg_bdl_line(ui, 1, b'merge', d['merge-total'], d['revision-total'])
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1336
    for k, __, v in all_info:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1337
        if v['merge-total']:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1338
            _dbg_bdl_line(ui, 2, k, v['merge-total'], v['revision-total'])
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1339
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1340
    _dbg_bdl_line(ui, 0, b'deltas')
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1341
    _dbg_bdl_line(
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1342
        ui,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1343
        1,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1344
        b'from-storage',
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1345
        d['reused-storage-delta'],
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1346
        percentage_base=d['available-delta'],
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1347
        percentage_key=b"available",
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1348
        percentage_ref=d['available-delta'],
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1349
    )
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1350
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1351
    if d['denied-delta-candeltafn']:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1352
        _dbg_bdl_line(ui, 2, b'denied-fn', d['denied-delta-candeltafn'])
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1353
    for __, k, v in all_info:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1354
        if v['denied-delta-candeltafn']:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1355
            _dbg_bdl_line(ui, 3, k, v['denied-delta-candeltafn'])
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1356
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1357
    if d['denied-base-not-available']:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1358
        _dbg_bdl_line(ui, 2, b'denied-nb', d['denied-base-not-available'])
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1359
    for k, __, v in all_info:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1360
        if v['denied-base-not-available']:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1361
            _dbg_bdl_line(ui, 3, k, v['denied-base-not-available'])
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1362
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1363
    if d['computed-delta']:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1364
        _dbg_bdl_line(ui, 1, b'computed', d['computed-delta'])
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1365
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1366
    if d['available-full']:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1367
        _dbg_bdl_line(
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1368
            ui,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1369
            2,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1370
            b'full',
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1371
            d['delta-full'],
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1372
            percentage_base=d['available-full'],
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1373
            percentage_key=b"native",
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1374
            percentage_ref=d['available-full'],
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1375
        )
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1376
    for k, __, v in all_info:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1377
        if v['available-full']:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1378
            _dbg_bdl_line(
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1379
                ui,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1380
                3,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1381
                k,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1382
                v['delta-full'],
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1383
                percentage_base=v['available-full'],
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1384
                percentage_key=b"native",
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1385
                percentage_ref=v['available-full'],
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1386
            )
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1387
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1388
    if d['delta-against-prev']:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1389
        _dbg_bdl_line(ui, 2, b'previous', d['delta-against-prev'])
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1390
    for k, __, v in all_info:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1391
        if v['delta-against-prev']:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1392
            _dbg_bdl_line(ui, 3, k, v['delta-against-prev'])
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1393
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1394
    if d['delta-against-p1']:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1395
        _dbg_bdl_line(ui, 2, b'parent-1', d['delta-against-prev'])
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1396
    for k, __, v in all_info:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1397
        if v['delta-against-p1']:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1398
            _dbg_bdl_line(ui, 3, k, v['delta-against-p1'])
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1399
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1400
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48913
diff changeset
  1401
class cgpacker:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1402
    def __init__(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1403
        self,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1404
        repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1405
        oldmatcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1406
        matcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1407
        version,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1408
        builddeltaheader,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1409
        manifestsend,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1410
        forcedeltaparentprev=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1411
        bundlecaps=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1412
        ellipses=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1413
        shallow=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1414
        ellipsisroots=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1415
        fullnodes=None,
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  1416
        remote_sidedata=None,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1417
    ):
19202
0455fc94ae00 bundle-ng: move gengroup into bundler, pass repo object to bundler
Sune Foldager <cryo@cyanite.org>
parents: 19201
diff changeset
  1418
        """Given a source repo, construct a bundler.
32287
df3cf9422e1b changegroup: add bundlecaps back
Durham Goode <durham@fb.com>
parents: 32268
diff changeset
  1419
40344
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  1420
        oldmatcher is a matcher that matches on files the client already has.
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  1421
        These will not be included in the changegroup.
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  1422
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  1423
        matcher is a matcher that matches on files to include in the
38794
1d01cf0416a5 changegroup: move file matcher from narrow extension
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38783
diff changeset
  1424
        changegroup. Used to facilitate sparse changegroups.
1d01cf0416a5 changegroup: move file matcher from narrow extension
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38783
diff changeset
  1425
39017
ef3d3a2f9aa5 changegroup: refactor delta parent code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39016
diff changeset
  1426
        forcedeltaparentprev indicates whether delta parents must be against
ef3d3a2f9aa5 changegroup: refactor delta parent code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39016
diff changeset
  1427
        the previous revision in a delta group. This should only be used for
ef3d3a2f9aa5 changegroup: refactor delta parent code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39016
diff changeset
  1428
        compatibility with changegroup version 1.
38901
23ae0c07a3e1 changegroup: control delta parent behavior via constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38900
diff changeset
  1429
38897
bd64b8b8f0dd changegroup: pass function to build delta header into constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38896
diff changeset
  1430
        builddeltaheader is a callable that constructs the header for a group
bd64b8b8f0dd changegroup: pass function to build delta header into constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38896
diff changeset
  1431
        delta.
bd64b8b8f0dd changegroup: pass function to build delta header into constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38896
diff changeset
  1432
38898
67f37e8a5490 changegroup: pass end of manifests marker into constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38897
diff changeset
  1433
        manifestsend is a chunk to send after manifests have been fully emitted.
67f37e8a5490 changegroup: pass end of manifests marker into constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38897
diff changeset
  1434
38908
1469584ad5fe changegroup: specify ellipses mode explicitly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38907
diff changeset
  1435
        ellipses indicates whether ellipsis serving mode is enabled.
1469584ad5fe changegroup: specify ellipses mode explicitly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38907
diff changeset
  1436
32287
df3cf9422e1b changegroup: add bundlecaps back
Durham Goode <durham@fb.com>
parents: 32268
diff changeset
  1437
        bundlecaps is optional and can be used to specify the set of
df3cf9422e1b changegroup: add bundlecaps back
Durham Goode <durham@fb.com>
parents: 32268
diff changeset
  1438
        capabilities which can be used to build the bundle. While bundlecaps is
df3cf9422e1b changegroup: add bundlecaps back
Durham Goode <durham@fb.com>
parents: 32268
diff changeset
  1439
        unused in core Mercurial, extensions rely on this feature to communicate
df3cf9422e1b changegroup: add bundlecaps back
Durham Goode <durham@fb.com>
parents: 32268
diff changeset
  1440
        capabilities to customize the changegroup packer.
38904
cdb9bc216771 changegroup: declare shallow flag in constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38903
diff changeset
  1441
cdb9bc216771 changegroup: declare shallow flag in constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38903
diff changeset
  1442
        shallow indicates whether shallow data might be sent. The packer may
cdb9bc216771 changegroup: declare shallow flag in constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38903
diff changeset
  1443
        need to pack file contents not introduced by the changes being packed.
38909
1af339c22aeb changegroup: move fullnodes into cgpacker
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38908
diff changeset
  1444
38996
5baafb8fe253 changegroup: rename _fullnodes to _fullclnodes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38995
diff changeset
  1445
        fullnodes is the set of changelog nodes which should not be ellipsis
5baafb8fe253 changegroup: rename _fullnodes to _fullclnodes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38995
diff changeset
  1446
        nodes. We store this rather than the set of nodes that should be
5baafb8fe253 changegroup: rename _fullnodes to _fullclnodes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38995
diff changeset
  1447
        ellipsis because for very large histories we expect this to be
5baafb8fe253 changegroup: rename _fullnodes to _fullclnodes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38995
diff changeset
  1448
        significantly smaller.
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  1449
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  1450
        remote_sidedata is the set of sidedata categories wanted by the remote.
19202
0455fc94ae00 bundle-ng: move gengroup into bundler, pass repo object to bundler
Sune Foldager <cryo@cyanite.org>
parents: 19201
diff changeset
  1451
        """
40344
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  1452
        assert oldmatcher
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  1453
        assert matcher
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  1454
        self._oldmatcher = oldmatcher
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  1455
        self._matcher = matcher
38794
1d01cf0416a5 changegroup: move file matcher from narrow extension
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38783
diff changeset
  1456
38895
d7ac49c2353c changegroup: pass version into constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38894
diff changeset
  1457
        self.version = version
39017
ef3d3a2f9aa5 changegroup: refactor delta parent code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39016
diff changeset
  1458
        self._forcedeltaparentprev = forcedeltaparentprev
38897
bd64b8b8f0dd changegroup: pass function to build delta header into constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38896
diff changeset
  1459
        self._builddeltaheader = builddeltaheader
38898
67f37e8a5490 changegroup: pass end of manifests marker into constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38897
diff changeset
  1460
        self._manifestsend = manifestsend
38908
1469584ad5fe changegroup: specify ellipses mode explicitly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38907
diff changeset
  1461
        self._ellipses = ellipses
38895
d7ac49c2353c changegroup: pass version into constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38894
diff changeset
  1462
32287
df3cf9422e1b changegroup: add bundlecaps back
Durham Goode <durham@fb.com>
parents: 32268
diff changeset
  1463
        # Set of capabilities we can use to build the bundle.
df3cf9422e1b changegroup: add bundlecaps back
Durham Goode <durham@fb.com>
parents: 32268
diff changeset
  1464
        if bundlecaps is None:
df3cf9422e1b changegroup: add bundlecaps back
Durham Goode <durham@fb.com>
parents: 32268
diff changeset
  1465
            bundlecaps = set()
df3cf9422e1b changegroup: add bundlecaps back
Durham Goode <durham@fb.com>
parents: 32268
diff changeset
  1466
        self._bundlecaps = bundlecaps
46713
bc2519513ae0 sidedata-exchange: add `wanted_sidedata` and `sidedata_computers` to repos
Raphaël Gomès <rgomes@octobus.net>
parents: 46712
diff changeset
  1467
        if remote_sidedata is None:
bc2519513ae0 sidedata-exchange: add `wanted_sidedata` and `sidedata_computers` to repos
Raphaël Gomès <rgomes@octobus.net>
parents: 46712
diff changeset
  1468
            remote_sidedata = set()
bc2519513ae0 sidedata-exchange: add `wanted_sidedata` and `sidedata_computers` to repos
Raphaël Gomès <rgomes@octobus.net>
parents: 46712
diff changeset
  1469
        self._remote_sidedata = remote_sidedata
38904
cdb9bc216771 changegroup: declare shallow flag in constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38903
diff changeset
  1470
        self._isshallow = shallow
38996
5baafb8fe253 changegroup: rename _fullnodes to _fullclnodes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38995
diff changeset
  1471
        self._fullclnodes = fullnodes
38900
6e999a2d8fe7 changegroup: control reordering via constructor argument
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38899
diff changeset
  1472
38907
ad4c4cc9a5ac changegroup: pass ellipsis roots into cgpacker constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38906
diff changeset
  1473
        # Maps ellipsis revs to their roots at the changelog level.
ad4c4cc9a5ac changegroup: pass ellipsis roots into cgpacker constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38906
diff changeset
  1474
        self._precomputedellipsis = ellipsisroots
ad4c4cc9a5ac changegroup: pass ellipsis roots into cgpacker constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38906
diff changeset
  1475
19202
0455fc94ae00 bundle-ng: move gengroup into bundler, pass repo object to bundler
Sune Foldager <cryo@cyanite.org>
parents: 19201
diff changeset
  1476
        self._repo = repo
38900
6e999a2d8fe7 changegroup: control reordering via constructor argument
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38899
diff changeset
  1477
23748
4ab66de46a96 bundle: when verbose, show what takes up the space in the generated bundle
Mads Kiilerich <madski@unity3d.com>
parents: 23382
diff changeset
  1478
        if self._repo.ui.verbose and not self._repo.ui.debugflag:
4ab66de46a96 bundle: when verbose, show what takes up the space in the generated bundle
Mads Kiilerich <madski@unity3d.com>
parents: 23382
diff changeset
  1479
            self._verbosenote = self._repo.ui.note
4ab66de46a96 bundle: when verbose, show what takes up the space in the generated bundle
Mads Kiilerich <madski@unity3d.com>
parents: 23382
diff changeset
  1480
        else:
4ab66de46a96 bundle: when verbose, show what takes up the space in the generated bundle
Mads Kiilerich <madski@unity3d.com>
parents: 23382
diff changeset
  1481
            self._verbosenote = lambda s: None
4ab66de46a96 bundle: when verbose, show what takes up the space in the generated bundle
Mads Kiilerich <madski@unity3d.com>
parents: 23382
diff changeset
  1482
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1483
    def generate(
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1484
        self,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1485
        commonrevs,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1486
        clnodes,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1487
        fastpathlinkrev,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1488
        source,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1489
        changelog=True,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1490
    ):
39672
a1942015c10e changegroup: add functionality to skip adding changelog data to changegroup
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39670
diff changeset
  1491
        """Yield a sequence of changegroup byte chunks.
a1942015c10e changegroup: add functionality to skip adding changelog data to changegroup
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39670
diff changeset
  1492
        If changelog is False, changelog data won't be added to changegroup
a1942015c10e changegroup: add functionality to skip adding changelog data to changegroup
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39670
diff changeset
  1493
        """
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1494
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1495
        debug_info = None
19202
0455fc94ae00 bundle-ng: move gengroup into bundler, pass repo object to bundler
Sune Foldager <cryo@cyanite.org>
parents: 19201
diff changeset
  1496
        repo = self._repo
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1497
        if repo.ui.configbool(b'debug', b'bundling-stats'):
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1498
            debug_info = make_debug_info()
24978
f52560c64953 changegroup: drop _changelog and _manifest properties
Martin von Zweigbergk <martinvonz@google.com>
parents: 24977
diff changeset
  1499
        cl = repo.changelog
19204
e9c5b1c246dc bundle-ng: move bundle generation to changegroup.py
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 19202
diff changeset
  1500
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1501
        self._verbosenote(_(b'uncompressed size of bundle content:\n'))
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1502
        size = 0
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1503
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1504
        sidedata_helpers = None
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1505
        if self.version == b'04':
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1506
            remote_sidedata = self._remote_sidedata
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1507
            if source == b'strip':
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1508
                # We're our own remote when stripping, get the no-op helpers
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1509
                # TODO a better approach would be for the strip bundle to
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1510
                # correctly advertise its sidedata categories directly.
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1511
                remote_sidedata = repo._wanted_sidedata
47085
3aab2330b7d3 sidedata: move sidedata-related utils to the dedicated module
Raphaël Gomès <rgomes@octobus.net>
parents: 47077
diff changeset
  1512
            sidedata_helpers = sidedatamod.get_sidedata_helpers(
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1513
                repo,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1514
                remote_sidedata,
47085
3aab2330b7d3 sidedata: move sidedata-related utils to the dedicated module
Raphaël Gomès <rgomes@octobus.net>
parents: 47077
diff changeset
  1515
            )
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1516
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1517
        cl_debug_info = None
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1518
        if debug_info is not None:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1519
            cl_debug_info = make_debug_info()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1520
        clstate, deltas = self._generatechangelog(
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1521
            cl,
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1522
            clnodes,
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1523
            generate=changelog,
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1524
            sidedata_helpers=sidedata_helpers,
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1525
            debug_info=cl_debug_info,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1526
        )
39014
d662959dc881 changegroup: emit revisiondelta instances from deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39013
diff changeset
  1527
        for delta in deltas:
46780
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46718
diff changeset
  1528
            for chunk in _revisiondeltatochunks(
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46718
diff changeset
  1529
                self._repo, delta, self._builddeltaheader
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46718
diff changeset
  1530
            ):
41448
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1531
                size += len(chunk)
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1532
                yield chunk
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1533
39010
fcdab6629dde changegroup: emit delta group close chunk outside of deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39009
diff changeset
  1534
        close = closechunk()
fcdab6629dde changegroup: emit delta group close chunk outside of deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39009
diff changeset
  1535
        size += len(close)
fcdab6629dde changegroup: emit delta group close chunk outside of deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39009
diff changeset
  1536
        yield closechunk()
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1537
        if debug_info is not None:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1538
            merge_debug_info(debug_info, cl_debug_info)
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1539
            debug_info['revision-changelog'] = cl_debug_info['revision-total']
39010
fcdab6629dde changegroup: emit delta group close chunk outside of deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39009
diff changeset
  1540
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1541
        self._verbosenote(_(b'%8.i (changelog)\n') % size)
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1542
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1543
        clrevorder = clstate[b'clrevorder']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1544
        manifests = clstate[b'manifests']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1545
        changedfiles = clstate[b'changedfiles']
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1546
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1547
        if debug_info is not None:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1548
            debug_info['file-count'] = len(changedfiles)
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1549
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1550
        # We need to make sure that the linkrev in the changegroup refers to
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1551
        # the first changeset that introduced the manifest or file revision.
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1552
        # The fastpath is usually safer than the slowpath, because the filelogs
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1553
        # are walked in revlog order.
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1554
        #
39861
db5501d93bcf changegroup: remove reordering control (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39733
diff changeset
  1555
        # When taking the slowpath when the manifest revlog uses generaldelta,
db5501d93bcf changegroup: remove reordering control (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39733
diff changeset
  1556
        # the manifest may be walked in the "wrong" order. Without 'clrevorder',
db5501d93bcf changegroup: remove reordering control (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39733
diff changeset
  1557
        # we would get an incorrect linkrev (see fix in cc0ff93d0c0c).
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1558
        #
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1559
        # When taking the fastpath, we are only vulnerable to reordering
39861
db5501d93bcf changegroup: remove reordering control (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39733
diff changeset
  1560
        # of the changelog itself. The changelog never uses generaldelta and is
db5501d93bcf changegroup: remove reordering control (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39733
diff changeset
  1561
        # never reordered. To handle this case, we simply take the slowpath,
db5501d93bcf changegroup: remove reordering control (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39733
diff changeset
  1562
        # which already has the 'clrevorder' logic. This was also fixed in
db5501d93bcf changegroup: remove reordering control (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39733
diff changeset
  1563
        # cc0ff93d0c0c.
db5501d93bcf changegroup: remove reordering control (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39733
diff changeset
  1564
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1565
        # Treemanifests don't work correctly with fastpathlinkrev
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1566
        # either, because we don't discover which directory nodes to
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1567
        # send along with files. This could probably be fixed.
45552
10284ce3d5ed scmutil: introduce function to check whether repo uses treemanifest or not
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
  1568
        fastpathlinkrev = fastpathlinkrev and not scmutil.istreemanifest(repo)
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1569
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1570
        fnodes = {}  # needed file nodes
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1571
39011
2ebdd265fe8c changegroup: move size tracking and end of manifests to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39010
diff changeset
  1572
        size = 0
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1573
        mn_debug_info = None
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1574
        if debug_info is not None:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1575
            mn_debug_info = make_debug_info()
39012
c921ad9cae08 changegroup: move manifest chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39011
diff changeset
  1576
        it = self.generatemanifests(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1577
            commonrevs,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1578
            clrevorder,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1579
            fastpathlinkrev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1580
            manifests,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1581
            fnodes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1582
            source,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1583
            clstate[b'clrevtomanifestrev'],
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1584
            sidedata_helpers=sidedata_helpers,
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1585
            debug_info=mn_debug_info,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1586
        )
39012
c921ad9cae08 changegroup: move manifest chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39011
diff changeset
  1587
39233
8b9b93bf70b1 changegroup: rename dir to tree to avoid shadowing a built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39231
diff changeset
  1588
        for tree, deltas in it:
8b9b93bf70b1 changegroup: rename dir to tree to avoid shadowing a built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39231
diff changeset
  1589
            if tree:
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  1590
                assert self.version in (b'03', b'04')
39233
8b9b93bf70b1 changegroup: rename dir to tree to avoid shadowing a built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39231
diff changeset
  1591
                chunk = _fileheader(tree)
39012
c921ad9cae08 changegroup: move manifest chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39011
diff changeset
  1592
                size += len(chunk)
c921ad9cae08 changegroup: move manifest chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39011
diff changeset
  1593
                yield chunk
c921ad9cae08 changegroup: move manifest chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39011
diff changeset
  1594
39014
d662959dc881 changegroup: emit revisiondelta instances from deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39013
diff changeset
  1595
            for delta in deltas:
46780
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46718
diff changeset
  1596
                chunks = _revisiondeltatochunks(
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46718
diff changeset
  1597
                    self._repo, delta, self._builddeltaheader
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46718
diff changeset
  1598
                )
39014
d662959dc881 changegroup: emit revisiondelta instances from deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39013
diff changeset
  1599
                for chunk in chunks:
d662959dc881 changegroup: emit revisiondelta instances from deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39013
diff changeset
  1600
                    size += len(chunk)
d662959dc881 changegroup: emit revisiondelta instances from deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39013
diff changeset
  1601
                    yield chunk
39012
c921ad9cae08 changegroup: move manifest chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39011
diff changeset
  1602
c921ad9cae08 changegroup: move manifest chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39011
diff changeset
  1603
            close = closechunk()
c921ad9cae08 changegroup: move manifest chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39011
diff changeset
  1604
            size += len(close)
c921ad9cae08 changegroup: move manifest chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39011
diff changeset
  1605
            yield close
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1606
        if debug_info is not None:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1607
            merge_debug_info(debug_info, mn_debug_info)
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1608
            debug_info['revision-manifest'] = mn_debug_info['revision-total']
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1609
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1610
        self._verbosenote(_(b'%8.i (manifests)\n') % size)
39011
2ebdd265fe8c changegroup: move size tracking and end of manifests to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39010
diff changeset
  1611
        yield self._manifestsend
2ebdd265fe8c changegroup: move size tracking and end of manifests to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39010
diff changeset
  1612
38983
fbbda9ff3deb changegroup: pass mfdicts properly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38982
diff changeset
  1613
        mfdicts = None
fbbda9ff3deb changegroup: pass mfdicts properly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38982
diff changeset
  1614
        if self._ellipses and self._isshallow:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1615
            mfdicts = [
46624
357d2ea95ce9 changegroup: use the local variable instead of reaching through self
Raphaël Gomès <rgomes@octobus.net>
parents: 46513
diff changeset
  1616
                (repo.manifestlog[n].read(), lr)
43106
d783f945a701 py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43085
diff changeset
  1617
                for (n, lr) in pycompat.iteritems(manifests)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1618
            ]
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1619
39238
cc957b9dc335 changegroup: rename mfs to manifests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39237
diff changeset
  1620
        manifests.clear()
44452
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 44306
diff changeset
  1621
        clrevs = {cl.rev(x) for x in clnodes}
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1622
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1623
        fl_debug_info = None
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1624
        if debug_info is not None:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1625
            fl_debug_info = make_debug_info()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1626
        it = self.generatefiles(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1627
            changedfiles,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1628
            commonrevs,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1629
            source,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1630
            mfdicts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1631
            fastpathlinkrev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1632
            fnodes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1633
            clrevs,
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1634
            sidedata_helpers=sidedata_helpers,
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1635
            debug_info=fl_debug_info,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1636
        )
39013
c4a2d19d393a changegroup: move file chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39012
diff changeset
  1637
39014
d662959dc881 changegroup: emit revisiondelta instances from deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39013
diff changeset
  1638
        for path, deltas in it:
39013
c4a2d19d393a changegroup: move file chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39012
diff changeset
  1639
            h = _fileheader(path)
c4a2d19d393a changegroup: move file chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39012
diff changeset
  1640
            size = len(h)
c4a2d19d393a changegroup: move file chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39012
diff changeset
  1641
            yield h
c4a2d19d393a changegroup: move file chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39012
diff changeset
  1642
39014
d662959dc881 changegroup: emit revisiondelta instances from deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39013
diff changeset
  1643
            for delta in deltas:
46780
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46718
diff changeset
  1644
                chunks = _revisiondeltatochunks(
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46718
diff changeset
  1645
                    self._repo, delta, self._builddeltaheader
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46718
diff changeset
  1646
                )
39014
d662959dc881 changegroup: emit revisiondelta instances from deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39013
diff changeset
  1647
                for chunk in chunks:
d662959dc881 changegroup: emit revisiondelta instances from deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39013
diff changeset
  1648
                    size += len(chunk)
d662959dc881 changegroup: emit revisiondelta instances from deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39013
diff changeset
  1649
                    yield chunk
39013
c4a2d19d393a changegroup: move file chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39012
diff changeset
  1650
c4a2d19d393a changegroup: move file chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39012
diff changeset
  1651
            close = closechunk()
c4a2d19d393a changegroup: move file chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39012
diff changeset
  1652
            size += len(close)
c4a2d19d393a changegroup: move file chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39012
diff changeset
  1653
            yield close
c4a2d19d393a changegroup: move file chunk emission to generate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39012
diff changeset
  1654
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1655
            self._verbosenote(_(b'%8.i  %s\n') % (size, path))
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1656
39002
eb8a0139ace3 changegroup: inline _close()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39001
diff changeset
  1657
        yield closechunk()
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1658
        if debug_info is not None:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1659
            merge_debug_info(debug_info, fl_debug_info)
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1660
            debug_info['revision-files'] = fl_debug_info['revision-total']
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1661
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1662
        if debug_info is not None:
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1663
            display_bundling_debug_info(
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1664
                repo.ui,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1665
                debug_info,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1666
                cl_debug_info,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1667
                mn_debug_info,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1668
                fl_debug_info,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1669
            )
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1670
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1671
        if clnodes:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1672
            repo.hook(b'outgoing', node=hex(clnodes[0]), source=source)
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1673
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1674
    def _generatechangelog(
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1675
        self,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1676
        cl,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1677
        nodes,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1678
        generate=True,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1679
        sidedata_helpers=None,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1680
        debug_info=None,
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1681
    ):
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1682
        """Generate data for changelog chunks.
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1683
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1684
        Returns a 2-tuple of a dict containing state and an iterable of
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1685
        byte chunks. The state will not be fully populated until the
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1686
        chunk stream has been fully consumed.
41448
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1687
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1688
        if generate is False, the state will be fully populated and no chunk
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1689
        stream will be yielded
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1690
47086
8bd769b5c941 sidedata: move documentation about sidedata helpers to sidedata module
Raphaël Gomès <rgomes@octobus.net>
parents: 47085
diff changeset
  1691
        See `revlogutil.sidedata.get_sidedata_helpers` for the doc on
8bd769b5c941 sidedata: move documentation about sidedata helpers to sidedata module
Raphaël Gomès <rgomes@octobus.net>
parents: 47085
diff changeset
  1692
        `sidedata_helpers`.
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1693
        """
23381
cc0ff93d0c0c changegroup: fix file linkrevs during reorders (issue4462)
Durham Goode <durham@fb.com>
parents: 23226
diff changeset
  1694
        clrevorder = {}
39238
cc957b9dc335 changegroup: rename mfs to manifests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39237
diff changeset
  1695
        manifests = {}
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1696
        mfl = self._repo.manifestlog
28241
a4286175ecba changegroup: drop special-casing of flat manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 28240
diff changeset
  1697
        changedfiles = set()
38998
40374b4a780f changegroup: track changelog to manifest revision map explicitly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38997
diff changeset
  1698
        clrevtomanifestrev = {}
19204
e9c5b1c246dc bundle-ng: move bundle generation to changegroup.py
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 19202
diff changeset
  1699
41445
73a33fe625bb changegroup: initialize the state variable a bit earlier
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41365
diff changeset
  1700
        state = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1701
            b'clrevorder': clrevorder,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1702
            b'manifests': manifests,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1703
            b'changedfiles': changedfiles,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1704
            b'clrevtomanifestrev': clrevtomanifestrev,
41445
73a33fe625bb changegroup: initialize the state variable a bit earlier
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41365
diff changeset
  1705
        }
73a33fe625bb changegroup: initialize the state variable a bit earlier
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41365
diff changeset
  1706
41448
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1707
        if not (generate or self._ellipses):
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1708
            # sort the nodes in storage order
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1709
            nodes = sorted(nodes, key=cl.rev)
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1710
            for node in nodes:
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1711
                c = cl.changelogrevision(node)
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1712
                clrevorder[node] = len(clrevorder)
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1713
                # record the first changeset introducing this manifest version
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1714
                manifests.setdefault(c.manifest, node)
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1715
                # Record a complete list of potentially-changed files in
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1716
                # this manifest.
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1717
                changedfiles.update(c.files)
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1718
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1719
            return state, ()
fa7d61f9c512 changegroup: don't try to build changelog chunks if not required
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41445
diff changeset
  1720
38890
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1721
        # Callback for the changelog, used to collect changed files and
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1722
        # manifest nodes.
19207
a67e1380dfbd bundle-ng: simplify lookup and state handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 19206
diff changeset
  1723
        # Returns the linkrev node (identity in the changelog case).
a67e1380dfbd bundle-ng: simplify lookup and state handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 19206
diff changeset
  1724
        def lookupcl(x):
39237
3634ed953a42 changegroup: clean up changelog callback
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39236
diff changeset
  1725
            c = cl.changelogrevision(x)
23381
cc0ff93d0c0c changegroup: fix file linkrevs during reorders (issue4462)
Durham Goode <durham@fb.com>
parents: 23226
diff changeset
  1726
            clrevorder[x] = len(clrevorder)
38890
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1727
38908
1469584ad5fe changegroup: specify ellipses mode explicitly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38907
diff changeset
  1728
            if self._ellipses:
39238
cc957b9dc335 changegroup: rename mfs to manifests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39237
diff changeset
  1729
                # Only update manifests if x is going to be sent. Otherwise we
38890
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1730
                # end up with bogus linkrevs specified for manifests and
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1731
                # we skip some manifest nodes that we should otherwise
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1732
                # have sent.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1733
                if (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1734
                    x in self._fullclnodes
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1735
                    or cl.rev(x) in self._precomputedellipsis
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1736
                ):
39237
3634ed953a42 changegroup: clean up changelog callback
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39236
diff changeset
  1737
                    manifestnode = c.manifest
38890
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1738
                    # Record the first changeset introducing this manifest
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1739
                    # version.
39238
cc957b9dc335 changegroup: rename mfs to manifests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39237
diff changeset
  1740
                    manifests.setdefault(manifestnode, x)
38890
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1741
                    # Set this narrow-specific dict so we have the lowest
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1742
                    # manifest revnum to look up for this cl revnum. (Part of
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1743
                    # mapping changelog ellipsis parents to manifest ellipsis
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1744
                    # parents)
39237
3634ed953a42 changegroup: clean up changelog callback
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39236
diff changeset
  1745
                    clrevtomanifestrev.setdefault(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1746
                        cl.rev(x), mfl.rev(manifestnode)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1747
                    )
38890
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1748
                # We can't trust the changed files list in the changeset if the
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1749
                # client requested a shallow clone.
38904
cdb9bc216771 changegroup: declare shallow flag in constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38903
diff changeset
  1750
                if self._isshallow:
39237
3634ed953a42 changegroup: clean up changelog callback
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39236
diff changeset
  1751
                    changedfiles.update(mfl[c.manifest].read().keys())
38890
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1752
                else:
39237
3634ed953a42 changegroup: clean up changelog callback
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39236
diff changeset
  1753
                    changedfiles.update(c.files)
38890
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1754
            else:
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1755
                # record the first changeset introducing this manifest version
39238
cc957b9dc335 changegroup: rename mfs to manifests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39237
diff changeset
  1756
                manifests.setdefault(c.manifest, x)
38890
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1757
                # Record a complete list of potentially-changed files in
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1758
                # this manifest.
39237
3634ed953a42 changegroup: clean up changelog callback
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39236
diff changeset
  1759
                changedfiles.update(c.files)
38890
d706c77449f9 changegroup: move generate() modifications from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38889
diff changeset
  1760
19207
a67e1380dfbd bundle-ng: simplify lookup and state handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 19206
diff changeset
  1761
            return x
19204
e9c5b1c246dc bundle-ng: move bundle generation to changegroup.py
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 19202
diff changeset
  1762
39009
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1763
        gen = deltagroup(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1764
            self._repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1765
            cl,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1766
            nodes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1767
            True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1768
            lookupcl,
39017
ef3d3a2f9aa5 changegroup: refactor delta parent code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39016
diff changeset
  1769
            self._forcedeltaparentprev,
39009
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1770
            ellipses=self._ellipses,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1771
            topic=_(b'changesets'),
39009
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1772
            clrevtolocalrev={},
9e8eb2b444e5 changegroup: extract cgpacker.group() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39008
diff changeset
  1773
            fullclnodes=self._fullclnodes,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1774
            precomputedellipsis=self._precomputedellipsis,
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1775
            sidedata_helpers=sidedata_helpers,
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1776
            debug_info=debug_info,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1777
        )
28227
1c36cc8e7870 changegroup: extract generatemanifests()
Martin von Zweigbergk <martinvonz@google.com>
parents: 27953
diff changeset
  1778
38976
f7228c907ef4 changegroup: factor changelog chunk generation into own function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38975
diff changeset
  1779
        return state, gen
28227
1c36cc8e7870 changegroup: extract generatemanifests()
Martin von Zweigbergk <martinvonz@google.com>
parents: 27953
diff changeset
  1780
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1781
    def generatemanifests(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1782
        self,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1783
        commonrevs,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1784
        clrevorder,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1785
        fastpathlinkrev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1786
        manifests,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1787
        fnodes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1788
        source,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1789
        clrevtolocalrev,
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1790
        sidedata_helpers=None,
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1791
        debug_info=None,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1792
    ):
34149
75cc1f1e11f2 changegroup: add source parameter to generatemanifests
Durham Goode <durham@fb.com>
parents: 34148
diff changeset
  1793
        """Returns an iterator of changegroup chunks containing manifests.
75cc1f1e11f2 changegroup: add source parameter to generatemanifests
Durham Goode <durham@fb.com>
parents: 34148
diff changeset
  1794
75cc1f1e11f2 changegroup: add source parameter to generatemanifests
Durham Goode <durham@fb.com>
parents: 34148
diff changeset
  1795
        `source` is unused here, but is used by extensions like remotefilelog to
75cc1f1e11f2 changegroup: add source parameter to generatemanifests
Durham Goode <durham@fb.com>
parents: 34148
diff changeset
  1796
        change what is sent based in pulls vs pushes, etc.
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1797
47086
8bd769b5c941 sidedata: move documentation about sidedata helpers to sidedata module
Raphaël Gomès <rgomes@octobus.net>
parents: 47085
diff changeset
  1798
        See `revlogutil.sidedata.get_sidedata_helpers` for the doc on
8bd769b5c941 sidedata: move documentation about sidedata helpers to sidedata module
Raphaël Gomès <rgomes@octobus.net>
parents: 47085
diff changeset
  1799
        `sidedata_helpers`.
34149
75cc1f1e11f2 changegroup: add source parameter to generatemanifests
Durham Goode <durham@fb.com>
parents: 34148
diff changeset
  1800
        """
28227
1c36cc8e7870 changegroup: extract generatemanifests()
Martin von Zweigbergk <martinvonz@google.com>
parents: 27953
diff changeset
  1801
        repo = self._repo
30294
bce79dfcf5e4 manifest: get rid of manifest.readshallowfast
Durham Goode <durham@fb.com>
parents: 30268
diff changeset
  1802
        mfl = repo.manifestlog
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1803
        tmfnodes = {b'': manifests}
28227
1c36cc8e7870 changegroup: extract generatemanifests()
Martin von Zweigbergk <martinvonz@google.com>
parents: 27953
diff changeset
  1804
19207
a67e1380dfbd bundle-ng: simplify lookup and state handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 19206
diff changeset
  1805
        # Callback for the manifest, used to collect linkrevs for filelog
a67e1380dfbd bundle-ng: simplify lookup and state handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 19206
diff changeset
  1806
        # revisions.
a67e1380dfbd bundle-ng: simplify lookup and state handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 19206
diff changeset
  1807
        # Returns the linkrev node (collected in lookupcl).
39233
8b9b93bf70b1 changegroup: rename dir to tree to avoid shadowing a built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39231
diff changeset
  1808
        def makelookupmflinknode(tree, nodes):
28231
3faba927dd93 changegroup: introduce makelookupmflinknode(dir)
Martin von Zweigbergk <martinvonz@google.com>
parents: 28230
diff changeset
  1809
            if fastpathlinkrev:
39233
8b9b93bf70b1 changegroup: rename dir to tree to avoid shadowing a built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39231
diff changeset
  1810
                assert not tree
46787
70f8c64812db typing: fix directives mangled by black
Matt Harbison <matt_harbison@yahoo.com>
parents: 46686
diff changeset
  1811
70f8c64812db typing: fix directives mangled by black
Matt Harbison <matt_harbison@yahoo.com>
parents: 46686
diff changeset
  1812
                # pytype: disable=unsupported-operands
70f8c64812db typing: fix directives mangled by black
Matt Harbison <matt_harbison@yahoo.com>
parents: 46686
diff changeset
  1813
                return manifests.__getitem__
70f8c64812db typing: fix directives mangled by black
Matt Harbison <matt_harbison@yahoo.com>
parents: 46686
diff changeset
  1814
                # pytype: enable=unsupported-operands
28231
3faba927dd93 changegroup: introduce makelookupmflinknode(dir)
Martin von Zweigbergk <martinvonz@google.com>
parents: 28230
diff changeset
  1815
27239
65c47779bcb5 changegroup: remove one special case from lookupmflinknode
Augie Fackler <augie@google.com>
parents: 27238
diff changeset
  1816
            def lookupmflinknode(x):
65c47779bcb5 changegroup: remove one special case from lookupmflinknode
Augie Fackler <augie@google.com>
parents: 27238
diff changeset
  1817
                """Callback for looking up the linknode for manifests.
27219
beb60a898dd0 changegroup: document manifest linkrev callback some more
Augie Fackler <augie@google.com>
parents: 27218
diff changeset
  1818
27239
65c47779bcb5 changegroup: remove one special case from lookupmflinknode
Augie Fackler <augie@google.com>
parents: 27238
diff changeset
  1819
                Returns the linkrev node for the specified manifest.
27219
beb60a898dd0 changegroup: document manifest linkrev callback some more
Augie Fackler <augie@google.com>
parents: 27218
diff changeset
  1820
27239
65c47779bcb5 changegroup: remove one special case from lookupmflinknode
Augie Fackler <augie@google.com>
parents: 27238
diff changeset
  1821
                SIDE EFFECT:
65c47779bcb5 changegroup: remove one special case from lookupmflinknode
Augie Fackler <augie@google.com>
parents: 27238
diff changeset
  1822
27432
77d25b913f80 changegroup: introduce cg3, which has support for exchanging treemanifests
Augie Fackler <augie@google.com>
parents: 27241
diff changeset
  1823
                1) fclnodes gets populated with the list of relevant
77d25b913f80 changegroup: introduce cg3, which has support for exchanging treemanifests
Augie Fackler <augie@google.com>
parents: 27241
diff changeset
  1824
                   file nodes if we're not using fastpathlinkrev
77d25b913f80 changegroup: introduce cg3, which has support for exchanging treemanifests
Augie Fackler <augie@google.com>
parents: 27241
diff changeset
  1825
                2) When treemanifests are in use, collects treemanifest nodes
77d25b913f80 changegroup: introduce cg3, which has support for exchanging treemanifests
Augie Fackler <augie@google.com>
parents: 27241
diff changeset
  1826
                   to send
27219
beb60a898dd0 changegroup: document manifest linkrev callback some more
Augie Fackler <augie@google.com>
parents: 27218
diff changeset
  1827
27432
77d25b913f80 changegroup: introduce cg3, which has support for exchanging treemanifests
Augie Fackler <augie@google.com>
parents: 27241
diff changeset
  1828
                Note that this means manifests must be completely sent to
77d25b913f80 changegroup: introduce cg3, which has support for exchanging treemanifests
Augie Fackler <augie@google.com>
parents: 27241
diff changeset
  1829
                the client before you can trust the list of files and
77d25b913f80 changegroup: introduce cg3, which has support for exchanging treemanifests
Augie Fackler <augie@google.com>
parents: 27241
diff changeset
  1830
                treemanifests to send.
27239
65c47779bcb5 changegroup: remove one special case from lookupmflinknode
Augie Fackler <augie@google.com>
parents: 27238
diff changeset
  1831
                """
35012
d80380ba8e7d changegroup: use any node, not min(), in treemanifest's generatemanifests
Kyle Lippincott <spectral@google.com>
parents: 34734
diff changeset
  1832
                clnode = nodes[x]
39233
8b9b93bf70b1 changegroup: rename dir to tree to avoid shadowing a built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39231
diff changeset
  1833
                mdata = mfl.get(tree, x).readfast(shallow=True)
28241
a4286175ecba changegroup: drop special-casing of flat manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 28240
diff changeset
  1834
                for p, n, fl in mdata.iterentries():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1835
                    if fl == b't':  # subdirectory manifest
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1836
                        subtree = tree + p + b'/'
39233
8b9b93bf70b1 changegroup: rename dir to tree to avoid shadowing a built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39231
diff changeset
  1837
                        tmfclnodes = tmfnodes.setdefault(subtree, {})
28241
a4286175ecba changegroup: drop special-casing of flat manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 28240
diff changeset
  1838
                        tmfclnode = tmfclnodes.setdefault(n, clnode)
a4286175ecba changegroup: drop special-casing of flat manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 28240
diff changeset
  1839
                        if clrevorder[clnode] < clrevorder[tmfclnode]:
a4286175ecba changegroup: drop special-casing of flat manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 28240
diff changeset
  1840
                            tmfclnodes[n] = clnode
a4286175ecba changegroup: drop special-casing of flat manifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 28240
diff changeset
  1841
                    else:
39233
8b9b93bf70b1 changegroup: rename dir to tree to avoid shadowing a built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39231
diff changeset
  1842
                        f = tree + p
28240
1ac8ce137377 changegroup: fix treemanifests on merges
Martin von Zweigbergk <martinvonz@google.com>
parents: 28232
diff changeset
  1843
                        fclnodes = fnodes.setdefault(f, {})
1ac8ce137377 changegroup: fix treemanifests on merges
Martin von Zweigbergk <martinvonz@google.com>
parents: 28232
diff changeset
  1844
                        fclnode = fclnodes.setdefault(n, clnode)
1ac8ce137377 changegroup: fix treemanifests on merges
Martin von Zweigbergk <martinvonz@google.com>
parents: 28232
diff changeset
  1845
                        if clrevorder[clnode] < clrevorder[fclnode]:
1ac8ce137377 changegroup: fix treemanifests on merges
Martin von Zweigbergk <martinvonz@google.com>
parents: 28232
diff changeset
  1846
                            fclnodes[n] = clnode
27239
65c47779bcb5 changegroup: remove one special case from lookupmflinknode
Augie Fackler <augie@google.com>
parents: 27238
diff changeset
  1847
                return clnode
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1848
28231
3faba927dd93 changegroup: introduce makelookupmflinknode(dir)
Martin von Zweigbergk <martinvonz@google.com>
parents: 28230
diff changeset
  1849
            return lookupmflinknode
19206
6308896b1d4a bundle-ng: simplify bundle10.generate
Sune Foldager <cryo@cyanite.org>
parents: 19204
diff changeset
  1850
28232
829d369fc5a8 changegroup: write root manifests and subdir manifests in a single loop
Martin von Zweigbergk <martinvonz@google.com>
parents: 28231
diff changeset
  1851
        while tmfnodes:
39233
8b9b93bf70b1 changegroup: rename dir to tree to avoid shadowing a built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39231
diff changeset
  1852
            tree, nodes = tmfnodes.popitem()
40664
dba590f27c7a changegroup: avoid instantiating storage if we are not using it
Kyle Lippincott <spectral@google.com>
parents: 40433
diff changeset
  1853
42341
27d6956d386b match: use '' instead of '.' for root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41767
diff changeset
  1854
            should_visit = self._matcher.visitdir(tree[:-1])
40664
dba590f27c7a changegroup: avoid instantiating storage if we are not using it
Kyle Lippincott <spectral@google.com>
parents: 40433
diff changeset
  1855
            if tree and not should_visit:
dba590f27c7a changegroup: avoid instantiating storage if we are not using it
Kyle Lippincott <spectral@google.com>
parents: 40433
diff changeset
  1856
                continue
dba590f27c7a changegroup: avoid instantiating storage if we are not using it
Kyle Lippincott <spectral@google.com>
parents: 40433
diff changeset
  1857
39244
73cf21b2e8a6 manifest: add getstorage() to manifestlog and use it globally
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39243
diff changeset
  1858
            store = mfl.getstorage(tree)
39007
39f5c7afdc25 changegroup: inline _prune() into call sites
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39006
diff changeset
  1859
40664
dba590f27c7a changegroup: avoid instantiating storage if we are not using it
Kyle Lippincott <spectral@google.com>
parents: 40433
diff changeset
  1860
            if not should_visit:
39733
5adc5fe41a7d changegroup: reintroduce some comments that have gotten lost over the years
Augie Fackler <augie@google.com>
parents: 39732
diff changeset
  1861
                # No nodes to send because this directory is out of
5adc5fe41a7d changegroup: reintroduce some comments that have gotten lost over the years
Augie Fackler <augie@google.com>
parents: 39732
diff changeset
  1862
                # the client's view of the repository (probably
40664
dba590f27c7a changegroup: avoid instantiating storage if we are not using it
Kyle Lippincott <spectral@google.com>
parents: 40433
diff changeset
  1863
                # because of narrow clones). Do this even for the root
dba590f27c7a changegroup: avoid instantiating storage if we are not using it
Kyle Lippincott <spectral@google.com>
parents: 40433
diff changeset
  1864
                # directory (tree=='')
39007
39f5c7afdc25 changegroup: inline _prune() into call sites
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39006
diff changeset
  1865
                prunednodes = []
39f5c7afdc25 changegroup: inline _prune() into call sites
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39006
diff changeset
  1866
            else:
39733
5adc5fe41a7d changegroup: reintroduce some comments that have gotten lost over the years
Augie Fackler <augie@google.com>
parents: 39732
diff changeset
  1867
                # Avoid sending any manifest nodes we can prove the
5adc5fe41a7d changegroup: reintroduce some comments that have gotten lost over the years
Augie Fackler <augie@google.com>
parents: 39732
diff changeset
  1868
                # client already has by checking linkrevs. See the
5adc5fe41a7d changegroup: reintroduce some comments that have gotten lost over the years
Augie Fackler <augie@google.com>
parents: 39732
diff changeset
  1869
                # related comment in generatefiles().
39732
e03c1a63155c changegroup: tease out a temporary prune method for manifests
Augie Fackler <augie@google.com>
parents: 39731
diff changeset
  1870
                prunednodes = self._prunemanifests(store, nodes, commonrevs)
40664
dba590f27c7a changegroup: avoid instantiating storage if we are not using it
Kyle Lippincott <spectral@google.com>
parents: 40433
diff changeset
  1871
39233
8b9b93bf70b1 changegroup: rename dir to tree to avoid shadowing a built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39231
diff changeset
  1872
            if tree and not prunednodes:
39005
d56a6b78de3b changegroup: invert conditional and dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39004
diff changeset
  1873
                continue
d56a6b78de3b changegroup: invert conditional and dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39004
diff changeset
  1874
39233
8b9b93bf70b1 changegroup: rename dir to tree to avoid shadowing a built-in
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39231
diff changeset
  1875
            lookupfn = makelookupmflinknode(tree, nodes)
38982
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
  1876
39014
d662959dc881 changegroup: emit revisiondelta instances from deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39013
diff changeset
  1877
            deltas = deltagroup(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1878
                self._repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1879
                store,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1880
                prunednodes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1881
                False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1882
                lookupfn,
39861
db5501d93bcf changegroup: remove reordering control (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39733
diff changeset
  1883
                self._forcedeltaparentprev,
39008
8c84f1ef949e changegroup: pass all state into group()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39007
diff changeset
  1884
                ellipses=self._ellipses,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1885
                topic=_(b'manifests'),
39008
8c84f1ef949e changegroup: pass all state into group()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39007
diff changeset
  1886
                clrevtolocalrev=clrevtolocalrev,
8c84f1ef949e changegroup: pass all state into group()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39007
diff changeset
  1887
                fullclnodes=self._fullclnodes,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1888
                precomputedellipsis=self._precomputedellipsis,
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1889
                sidedata_helpers=sidedata_helpers,
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1890
                debug_info=debug_info,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1891
            )
39008
8c84f1ef949e changegroup: pass all state into group()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39007
diff changeset
  1892
42341
27d6956d386b match: use '' instead of '.' for root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41767
diff changeset
  1893
            if not self._oldmatcher.visitdir(store.tree[:-1]):
40344
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  1894
                yield tree, deltas
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  1895
            else:
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  1896
                # 'deltas' is a generator and we need to consume it even if
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  1897
                # we are not going to send it because a side-effect is that
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  1898
                # it updates tmdnodes (via lookupfn)
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  1899
                for d in deltas:
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  1900
                    pass
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  1901
                if not tree:
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  1902
                    yield tree, []
39010
fcdab6629dde changegroup: emit delta group close chunk outside of deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39009
diff changeset
  1903
39732
e03c1a63155c changegroup: tease out a temporary prune method for manifests
Augie Fackler <augie@google.com>
parents: 39731
diff changeset
  1904
    def _prunemanifests(self, store, nodes, commonrevs):
41767
1c1c4ef8b72e changegroup: move non-pruning of non-ellipsis manifests to _prunemanifests()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41719
diff changeset
  1905
        if not self._ellipses:
1c1c4ef8b72e changegroup: move non-pruning of non-ellipsis manifests to _prunemanifests()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41719
diff changeset
  1906
            # In non-ellipses case and large repositories, it is better to
1c1c4ef8b72e changegroup: move non-pruning of non-ellipsis manifests to _prunemanifests()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41719
diff changeset
  1907
            # prevent calling of store.rev and store.linkrev on a lot of
1c1c4ef8b72e changegroup: move non-pruning of non-ellipsis manifests to _prunemanifests()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41719
diff changeset
  1908
            # nodes as compared to sending some extra data
1c1c4ef8b72e changegroup: move non-pruning of non-ellipsis manifests to _prunemanifests()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41719
diff changeset
  1909
            return nodes.copy()
39732
e03c1a63155c changegroup: tease out a temporary prune method for manifests
Augie Fackler <augie@google.com>
parents: 39731
diff changeset
  1910
        # This is split out as a separate method to allow filtering
e03c1a63155c changegroup: tease out a temporary prune method for manifests
Augie Fackler <augie@google.com>
parents: 39731
diff changeset
  1911
        # commonrevs in extension code.
e03c1a63155c changegroup: tease out a temporary prune method for manifests
Augie Fackler <augie@google.com>
parents: 39731
diff changeset
  1912
        #
e03c1a63155c changegroup: tease out a temporary prune method for manifests
Augie Fackler <augie@google.com>
parents: 39731
diff changeset
  1913
        # TODO(augie): this shouldn't be required, instead we should
e03c1a63155c changegroup: tease out a temporary prune method for manifests
Augie Fackler <augie@google.com>
parents: 39731
diff changeset
  1914
        # make filtering of revisions to send delegated to the store
e03c1a63155c changegroup: tease out a temporary prune method for manifests
Augie Fackler <augie@google.com>
parents: 39731
diff changeset
  1915
        # layer.
e03c1a63155c changegroup: tease out a temporary prune method for manifests
Augie Fackler <augie@google.com>
parents: 39731
diff changeset
  1916
        frev, flr = store.rev, store.linkrev
e03c1a63155c changegroup: tease out a temporary prune method for manifests
Augie Fackler <augie@google.com>
parents: 39731
diff changeset
  1917
        return [n for n in nodes if flr(frev(n)) not in commonrevs]
e03c1a63155c changegroup: tease out a temporary prune method for manifests
Augie Fackler <augie@google.com>
parents: 39731
diff changeset
  1918
24897
5c35a6040352 changegroup: document that 'source' parameter exists for extensions
Martin von Zweigbergk <martinvonz@google.com>
parents: 24896
diff changeset
  1919
    # The 'source' parameter is useful for extensions
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1920
    def generatefiles(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1921
        self,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1922
        changedfiles,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1923
        commonrevs,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1924
        source,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1925
        mfdicts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1926
        fastpathlinkrev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1927
        fnodes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1928
        clrevs,
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  1929
        sidedata_helpers=None,
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  1930
        debug_info=None,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1931
    ):
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1932
        changedfiles = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1933
            f
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1934
            for f in changedfiles
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1935
            if self._matcher(f) and not self._oldmatcher(f)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1936
        ]
38889
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1937
38999
b83e9c503f2f changegroup: define linknodes callbacks in generatefiles()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38998
diff changeset
  1938
        if not fastpathlinkrev:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1939
38999
b83e9c503f2f changegroup: define linknodes callbacks in generatefiles()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38998
diff changeset
  1940
            def normallinknodes(unused, fname):
b83e9c503f2f changegroup: define linknodes callbacks in generatefiles()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38998
diff changeset
  1941
                return fnodes.get(fname, {})
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1942
38999
b83e9c503f2f changegroup: define linknodes callbacks in generatefiles()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38998
diff changeset
  1943
        else:
b83e9c503f2f changegroup: define linknodes callbacks in generatefiles()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38998
diff changeset
  1944
            cln = self._repo.changelog.node
b83e9c503f2f changegroup: define linknodes callbacks in generatefiles()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38998
diff changeset
  1945
b83e9c503f2f changegroup: define linknodes callbacks in generatefiles()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38998
diff changeset
  1946
            def normallinknodes(store, fname):
b83e9c503f2f changegroup: define linknodes callbacks in generatefiles()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38998
diff changeset
  1947
                flinkrev = store.linkrev
b83e9c503f2f changegroup: define linknodes callbacks in generatefiles()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38998
diff changeset
  1948
                fnode = store.node
b83e9c503f2f changegroup: define linknodes callbacks in generatefiles()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38998
diff changeset
  1949
                revs = ((r, flinkrev(r)) for r in store)
44452
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 44306
diff changeset
  1950
                return {fnode(r): cln(lr) for r, lr in revs if lr in clrevs}
38999
b83e9c503f2f changegroup: define linknodes callbacks in generatefiles()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38998
diff changeset
  1951
39001
a6e1ff40e335 changegroup: pass clrevtolocalrev to each group
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39000
diff changeset
  1952
        clrevtolocalrev = {}
a6e1ff40e335 changegroup: pass clrevtolocalrev to each group
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39000
diff changeset
  1953
38904
cdb9bc216771 changegroup: declare shallow flag in constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38903
diff changeset
  1954
        if self._isshallow:
38889
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1955
            # In a shallow clone, the linknodes callback needs to also include
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1956
            # those file nodes that are in the manifests we sent but weren't
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1957
            # introduced by those manifests.
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1958
            commonctxs = [self._repo[c] for c in commonrevs]
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1959
            clrev = self._repo.changelog.rev
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1960
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1961
            def linknodes(flog, fname):
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1962
                for c in commonctxs:
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1963
                    try:
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1964
                        fnode = c.filenode(fname)
39001
a6e1ff40e335 changegroup: pass clrevtolocalrev to each group
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39000
diff changeset
  1965
                        clrevtolocalrev[c.rev()] = flog.rev(fnode)
38889
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1966
                    except error.ManifestLookupError:
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1967
                        pass
38999
b83e9c503f2f changegroup: define linknodes callbacks in generatefiles()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38998
diff changeset
  1968
                links = normallinknodes(flog, fname)
38889
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1969
                if len(links) != len(mfdicts):
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1970
                    for mf, lr in mfdicts:
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1971
                        fnode = mf.get(fname, None)
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1972
                        if fnode in links:
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1973
                            links[fnode] = min(links[fnode], lr, key=clrev)
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1974
                        elif fnode:
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1975
                            links[fnode] = lr
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1976
                return links
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1977
38999
b83e9c503f2f changegroup: define linknodes callbacks in generatefiles()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38998
diff changeset
  1978
        else:
b83e9c503f2f changegroup: define linknodes callbacks in generatefiles()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38998
diff changeset
  1979
            linknodes = normallinknodes
38889
a06aab274aef changegroup: move generatefiles() from narrow
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38888
diff changeset
  1980
19334
95a49112e7ab bundle: move file chunk generation to it's own function
Durham Goode <durham@fb.com>
parents: 19325
diff changeset
  1981
        repo = self._repo
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1982
        progress = repo.ui.makeprogress(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1983
            _(b'files'), unit=_(b'files'), total=len(changedfiles)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1984
        )
19334
95a49112e7ab bundle: move file chunk generation to it's own function
Durham Goode <durham@fb.com>
parents: 19325
diff changeset
  1985
        for i, fname in enumerate(sorted(changedfiles)):
95a49112e7ab bundle: move file chunk generation to it's own function
Durham Goode <durham@fb.com>
parents: 19325
diff changeset
  1986
            filerevlog = repo.file(fname)
95a49112e7ab bundle: move file chunk generation to it's own function
Durham Goode <durham@fb.com>
parents: 19325
diff changeset
  1987
            if not filerevlog:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1988
                raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1989
                    _(b"empty or missing file data for %s") % fname
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  1990
                )
19334
95a49112e7ab bundle: move file chunk generation to it's own function
Durham Goode <durham@fb.com>
parents: 19325
diff changeset
  1991
39001
a6e1ff40e335 changegroup: pass clrevtolocalrev to each group
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39000
diff changeset
  1992
            clrevtolocalrev.clear()
a6e1ff40e335 changegroup: pass clrevtolocalrev to each group
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39000
diff changeset
  1993
19334
95a49112e7ab bundle: move file chunk generation to it's own function
Durham Goode <durham@fb.com>
parents: 19325
diff changeset
  1994
            linkrevnodes = linknodes(filerevlog, fname)
51395
a0d88b021a98 unbundle: faster computation of changed heads
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50928
diff changeset
  1995
19207
a67e1380dfbd bundle-ng: simplify lookup and state handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 19206
diff changeset
  1996
            # Lookup for filenodes, we collected the linkrev nodes above in the
a67e1380dfbd bundle-ng: simplify lookup and state handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 19206
diff changeset
  1997
            # fastpath case and with lookupmf in the slowpath case.
a67e1380dfbd bundle-ng: simplify lookup and state handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 19206
diff changeset
  1998
            def lookupfilelog(x):
a67e1380dfbd bundle-ng: simplify lookup and state handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 19206
diff changeset
  1999
                return linkrevnodes[x]
a67e1380dfbd bundle-ng: simplify lookup and state handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 19206
diff changeset
  2000
39007
39f5c7afdc25 changegroup: inline _prune() into call sites
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39006
diff changeset
  2001
            frev, flr = filerevlog.rev, filerevlog.linkrev
39733
5adc5fe41a7d changegroup: reintroduce some comments that have gotten lost over the years
Augie Fackler <augie@google.com>
parents: 39732
diff changeset
  2002
            # Skip sending any filenode we know the client already
5adc5fe41a7d changegroup: reintroduce some comments that have gotten lost over the years
Augie Fackler <augie@google.com>
parents: 39732
diff changeset
  2003
            # has. This avoids over-sending files relatively
5adc5fe41a7d changegroup: reintroduce some comments that have gotten lost over the years
Augie Fackler <augie@google.com>
parents: 39732
diff changeset
  2004
            # inexpensively, so it's not a problem if we under-filter
5adc5fe41a7d changegroup: reintroduce some comments that have gotten lost over the years
Augie Fackler <augie@google.com>
parents: 39732
diff changeset
  2005
            # here.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2006
            filenodes = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2007
                n for n in linkrevnodes if flr(frev(n)) not in commonrevs
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2008
            ]
39007
39f5c7afdc25 changegroup: inline _prune() into call sites
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39006
diff changeset
  2009
39020
0b5f534df82a changegroup: invert conditional and dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39019
diff changeset
  2010
            if not filenodes:
0b5f534df82a changegroup: invert conditional and dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39019
diff changeset
  2011
                continue
38982
037debbf869c changegroup: pass sorted revisions into group() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38981
diff changeset
  2012
39020
0b5f534df82a changegroup: invert conditional and dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39019
diff changeset
  2013
            progress.update(i + 1, item=fname)
39008
8c84f1ef949e changegroup: pass all state into group()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39007
diff changeset
  2014
39020
0b5f534df82a changegroup: invert conditional and dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39019
diff changeset
  2015
            deltas = deltagroup(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2016
                self._repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2017
                filerevlog,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2018
                filenodes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2019
                False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2020
                lookupfilelog,
39861
db5501d93bcf changegroup: remove reordering control (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39733
diff changeset
  2021
                self._forcedeltaparentprev,
39020
0b5f534df82a changegroup: invert conditional and dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39019
diff changeset
  2022
                ellipses=self._ellipses,
0b5f534df82a changegroup: invert conditional and dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39019
diff changeset
  2023
                clrevtolocalrev=clrevtolocalrev,
0b5f534df82a changegroup: invert conditional and dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39019
diff changeset
  2024
                fullclnodes=self._fullclnodes,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2025
                precomputedellipsis=self._precomputedellipsis,
46715
45f0d5297698 changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents: 46713
diff changeset
  2026
                sidedata_helpers=sidedata_helpers,
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  2027
                debug_info=debug_info,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2028
            )
39020
0b5f534df82a changegroup: invert conditional and dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39019
diff changeset
  2029
0b5f534df82a changegroup: invert conditional and dedent
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39019
diff changeset
  2030
            yield fname, deltas
39010
fcdab6629dde changegroup: emit delta group close chunk outside of deltagroup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39009
diff changeset
  2031
38410
1c5c4a5dd86d changegroup: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38382
diff changeset
  2032
        progress.complete()
19200
4cfdec944edf bundle-ng: move group into the bundler
Sune Foldager <cryo@cyanite.org>
parents: 19199
diff changeset
  2033
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2034
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2035
def _makecg1packer(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2036
    repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2037
    oldmatcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2038
    matcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2039
    bundlecaps,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2040
    ellipses=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2041
    shallow=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2042
    ellipsisroots=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2043
    fullnodes=None,
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2044
    remote_sidedata=None,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2045
):
38897
bd64b8b8f0dd changegroup: pass function to build delta header into constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38896
diff changeset
  2046
    builddeltaheader = lambda d: _CHANGEGROUPV1_DELTA_HEADER.pack(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2047
        d.node, d.p1node, d.p2node, d.linknode
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2048
    )
27432
77d25b913f80 changegroup: introduce cg3, which has support for exchanging treemanifests
Augie Fackler <augie@google.com>
parents: 27241
diff changeset
  2049
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2050
    return cgpacker(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2051
        repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2052
        oldmatcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2053
        matcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2054
        b'01',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2055
        builddeltaheader=builddeltaheader,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2056
        manifestsend=b'',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2057
        forcedeltaparentprev=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2058
        bundlecaps=bundlecaps,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2059
        ellipses=ellipses,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2060
        shallow=shallow,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2061
        ellipsisroots=ellipsisroots,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2062
        fullnodes=fullnodes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2063
    )
38894
19344024a8e1 changegroup: define functions for creating changegroup packers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38893
diff changeset
  2064
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2065
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2066
def _makecg2packer(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2067
    repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2068
    oldmatcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2069
    matcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2070
    bundlecaps,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2071
    ellipses=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2072
    shallow=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2073
    ellipsisroots=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2074
    fullnodes=None,
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2075
    remote_sidedata=None,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2076
):
38897
bd64b8b8f0dd changegroup: pass function to build delta header into constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38896
diff changeset
  2077
    builddeltaheader = lambda d: _CHANGEGROUPV2_DELTA_HEADER.pack(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2078
        d.node, d.p1node, d.p2node, d.basenode, d.linknode
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2079
    )
38897
bd64b8b8f0dd changegroup: pass function to build delta header into constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38896
diff changeset
  2080
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2081
    return cgpacker(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2082
        repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2083
        oldmatcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2084
        matcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2085
        b'02',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2086
        builddeltaheader=builddeltaheader,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2087
        manifestsend=b'',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2088
        bundlecaps=bundlecaps,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2089
        ellipses=ellipses,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2090
        shallow=shallow,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2091
        ellipsisroots=ellipsisroots,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2092
        fullnodes=fullnodes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2093
    )
38894
19344024a8e1 changegroup: define functions for creating changegroup packers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38893
diff changeset
  2094
38897
bd64b8b8f0dd changegroup: pass function to build delta header into constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38896
diff changeset
  2095
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2096
def _makecg3packer(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2097
    repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2098
    oldmatcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2099
    matcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2100
    bundlecaps,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2101
    ellipses=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2102
    shallow=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2103
    ellipsisroots=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2104
    fullnodes=None,
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2105
    remote_sidedata=None,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2106
):
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2107
    builddeltaheader = lambda d: _CHANGEGROUPV3_DELTA_HEADER.pack(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2108
        d.node, d.p1node, d.p2node, d.basenode, d.linknode, d.flags
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2109
    )
38894
19344024a8e1 changegroup: define functions for creating changegroup packers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38893
diff changeset
  2110
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2111
    return cgpacker(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2112
        repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2113
        oldmatcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2114
        matcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2115
        b'03',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2116
        builddeltaheader=builddeltaheader,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2117
        manifestsend=closechunk(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2118
        bundlecaps=bundlecaps,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2119
        ellipses=ellipses,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2120
        shallow=shallow,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2121
        ellipsisroots=ellipsisroots,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2122
        fullnodes=fullnodes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2123
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2124
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2125
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2126
def _makecg4packer(
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2127
    repo,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2128
    oldmatcher,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2129
    matcher,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2130
    bundlecaps,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2131
    ellipses=False,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2132
    shallow=False,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2133
    ellipsisroots=None,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2134
    fullnodes=None,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2135
    remote_sidedata=None,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2136
):
47077
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
  2137
    # Sidedata is in a separate chunk from the delta to differentiate
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
  2138
    # "raw delta" and sidedata.
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
  2139
    def builddeltaheader(d):
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
  2140
        return _CHANGEGROUPV4_DELTA_HEADER.pack(
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
  2141
            d.protocol_flags,
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
  2142
            d.node,
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
  2143
            d.p1node,
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
  2144
            d.p2node,
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
  2145
            d.basenode,
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
  2146
            d.linknode,
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
  2147
            d.flags,
119790e1c67c cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents: 47076
diff changeset
  2148
        )
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2149
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2150
    return cgpacker(
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2151
        repo,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2152
        oldmatcher,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2153
        matcher,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2154
        b'04',
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2155
        builddeltaheader=builddeltaheader,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2156
        manifestsend=closechunk(),
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2157
        bundlecaps=bundlecaps,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2158
        ellipses=ellipses,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2159
        shallow=shallow,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2160
        ellipsisroots=ellipsisroots,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2161
        fullnodes=fullnodes,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2162
        remote_sidedata=remote_sidedata,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2163
    )
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2164
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2165
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2166
_packermap = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2167
    b'01': (_makecg1packer, cg1unpacker),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2168
    # cg2 adds support for exchanging generaldelta
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2169
    b'02': (_makecg2packer, cg2unpacker),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2170
    # cg3 adds support for exchanging revlog flags and treemanifests
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2171
    b'03': (_makecg3packer, cg3unpacker),
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2172
    # ch4 adds support for exchanging sidedata
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2173
    b'04': (_makecg4packer, cg4unpacker),
26709
42733e956887 changegroup: reformat packermap and add comment
Augie Fackler <augie@google.com>
parents: 26708
diff changeset
  2174
}
23168
a92ba36a1a9d changegroup: add a "packermap" dictionary to track different packer versions
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22971
diff changeset
  2175
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2176
30627
7ace5304fec5 changegroup: pass 'repo' to allsupportedversions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30626
diff changeset
  2177
def allsupportedversions(repo):
27928
c0f11347b107 changegroup: don't support versions 01 and 02 with treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 27920
diff changeset
  2178
    versions = set(_packermap.keys())
43059
4bbc9569e722 changegroup: use positive logic for treemanifest changegroup3 logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42897
diff changeset
  2179
    needv03 = False
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2180
    if (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2181
        repo.ui.configbool(b'experimental', b'changegroup3')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2182
        or repo.ui.configbool(b'experimental', b'treemanifest')
45552
10284ce3d5ed scmutil: introduce function to check whether repo uses treemanifest or not
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
  2183
        or scmutil.istreemanifest(repo)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2184
    ):
43059
4bbc9569e722 changegroup: use positive logic for treemanifest changegroup3 logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42897
diff changeset
  2185
        # we keep version 03 because we need to to exchange treemanifest data
4bbc9569e722 changegroup: use positive logic for treemanifest changegroup3 logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42897
diff changeset
  2186
        #
4bbc9569e722 changegroup: use positive logic for treemanifest changegroup3 logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42897
diff changeset
  2187
        # we also keep vresion 01 and 02, because it is possible for repo to
4bbc9569e722 changegroup: use positive logic for treemanifest changegroup3 logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42897
diff changeset
  2188
        # contains both normal and tree manifest at the same time. so using
4bbc9569e722 changegroup: use positive logic for treemanifest changegroup3 logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42897
diff changeset
  2189
        # older version to pull data is viable
4bbc9569e722 changegroup: use positive logic for treemanifest changegroup3 logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42897
diff changeset
  2190
        #
4bbc9569e722 changegroup: use positive logic for treemanifest changegroup3 logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42897
diff changeset
  2191
        # (or even to push subset of history)
4bbc9569e722 changegroup: use positive logic for treemanifest changegroup3 logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42897
diff changeset
  2192
        needv03 = True
4bbc9569e722 changegroup: use positive logic for treemanifest changegroup3 logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42897
diff changeset
  2193
    if not needv03:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2194
        versions.discard(b'03')
47076
08e26ef4ad35 changegroup: don't limit cgv4 to revlogv2 repos
Raphaël Gomès <rgomes@octobus.net>
parents: 47075
diff changeset
  2195
    want_v4 = (
08e26ef4ad35 changegroup: don't limit cgv4 to revlogv2 repos
Raphaël Gomès <rgomes@octobus.net>
parents: 47075
diff changeset
  2196
        repo.ui.configbool(b'experimental', b'changegroup4')
08e26ef4ad35 changegroup: don't limit cgv4 to revlogv2 repos
Raphaël Gomès <rgomes@octobus.net>
parents: 47075
diff changeset
  2197
        or requirements.REVLOGV2_REQUIREMENT in repo.requirements
47263
6c84fc9c9a90 changelogv2: introduce a "changelogv2" feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47216
diff changeset
  2198
        or requirements.CHANGELOGV2_REQUIREMENT in repo.requirements
47076
08e26ef4ad35 changegroup: don't limit cgv4 to revlogv2 repos
Raphaël Gomès <rgomes@octobus.net>
parents: 47075
diff changeset
  2199
    )
08e26ef4ad35 changegroup: don't limit cgv4 to revlogv2 repos
Raphaël Gomès <rgomes@octobus.net>
parents: 47075
diff changeset
  2200
    if not want_v4:
08e26ef4ad35 changegroup: don't limit cgv4 to revlogv2 repos
Raphaël Gomès <rgomes@octobus.net>
parents: 47075
diff changeset
  2201
        versions.discard(b'04')
27953
88609cfa3745 changegroup: fix pulling to treemanifest repo from flat repo (issue5066)
Martin von Zweigbergk <martinvonz@google.com>
parents: 27946
diff changeset
  2202
    return versions
88609cfa3745 changegroup: fix pulling to treemanifest repo from flat repo (issue5066)
Martin von Zweigbergk <martinvonz@google.com>
parents: 27946
diff changeset
  2203
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2204
27953
88609cfa3745 changegroup: fix pulling to treemanifest repo from flat repo (issue5066)
Martin von Zweigbergk <martinvonz@google.com>
parents: 27946
diff changeset
  2205
# Changegroup versions that can be applied to the repo
88609cfa3745 changegroup: fix pulling to treemanifest repo from flat repo (issue5066)
Martin von Zweigbergk <martinvonz@google.com>
parents: 27946
diff changeset
  2206
def supportedincomingversions(repo):
30628
a001cd7296a5 changegroup: simplify logic around enabling changegroup 03
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30627
diff changeset
  2207
    return allsupportedversions(repo)
27953
88609cfa3745 changegroup: fix pulling to treemanifest repo from flat repo (issue5066)
Martin von Zweigbergk <martinvonz@google.com>
parents: 27946
diff changeset
  2208
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2209
27953
88609cfa3745 changegroup: fix pulling to treemanifest repo from flat repo (issue5066)
Martin von Zweigbergk <martinvonz@google.com>
parents: 27946
diff changeset
  2210
# Changegroup versions that can be created from the repo
88609cfa3745 changegroup: fix pulling to treemanifest repo from flat repo (issue5066)
Martin von Zweigbergk <martinvonz@google.com>
parents: 27946
diff changeset
  2211
def supportedoutgoingversions(repo):
30627
7ace5304fec5 changegroup: pass 'repo' to allsupportedversions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30626
diff changeset
  2212
    versions = allsupportedversions(repo)
45552
10284ce3d5ed scmutil: introduce function to check whether repo uses treemanifest or not
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45372
diff changeset
  2213
    if scmutil.istreemanifest(repo):
27928
c0f11347b107 changegroup: don't support versions 01 and 02 with treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 27920
diff changeset
  2214
        # Versions 01 and 02 support only flat manifests and it's just too
c0f11347b107 changegroup: don't support versions 01 and 02 with treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 27920
diff changeset
  2215
        # expensive to convert between the flat manifest and tree manifest on
c0f11347b107 changegroup: don't support versions 01 and 02 with treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 27920
diff changeset
  2216
        # the fly. Since tree manifests are hashed differently, all of history
c0f11347b107 changegroup: don't support versions 01 and 02 with treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 27920
diff changeset
  2217
        # would have to be converted. Instead, we simply don't even pretend to
c0f11347b107 changegroup: don't support versions 01 and 02 with treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 27920
diff changeset
  2218
        # support versions 01 and 02.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2219
        versions.discard(b'01')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2220
        versions.discard(b'02')
45372
77b8588dd84e requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45371
diff changeset
  2221
    if requirements.NARROW_REQUIREMENT in repo.requirements:
36465
94709406f10d narrow: move changegroup.supportedoutgoingversions() override to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 36464
diff changeset
  2222
        # Versions 01 and 02 don't support revlog flags, and we need to
94709406f10d narrow: move changegroup.supportedoutgoingversions() override to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 36464
diff changeset
  2223
        # support that for stripping and unbundling to work.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2224
        versions.discard(b'01')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2225
        versions.discard(b'02')
37132
a54113fcc8c9 lfs: move the 'supportedoutgoingversions' handling to changegroup.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 37084
diff changeset
  2226
    if LFS_REQUIREMENT in repo.requirements:
a54113fcc8c9 lfs: move the 'supportedoutgoingversions' handling to changegroup.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 37084
diff changeset
  2227
        # Versions 01 and 02 don't support revlog flags, and we need to
a54113fcc8c9 lfs: move the 'supportedoutgoingversions' handling to changegroup.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 37084
diff changeset
  2228
        # mark LFS entries with REVIDX_EXTSTORED.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2229
        versions.discard(b'01')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2230
        versions.discard(b'02')
37132
a54113fcc8c9 lfs: move the 'supportedoutgoingversions' handling to changegroup.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 37084
diff changeset
  2231
27752
29cfc474c5fd changegroup3: introduce experimental.changegroup3 boolean config
Martin von Zweigbergk <martinvonz@google.com>
parents: 27751
diff changeset
  2232
    return versions
27751
a40e2f7fe49d changegroup: hide packermap behind methods
Martin von Zweigbergk <martinvonz@google.com>
parents: 27739
diff changeset
  2233
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2234
34144
91f0677dc920 repair: preserve phase also when not using generaldelta (issue5678)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33461
diff changeset
  2235
def localversion(repo):
91f0677dc920 repair: preserve phase also when not using generaldelta (issue5678)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33461
diff changeset
  2236
    # Finds the best version to use for bundles that are meant to be used
91f0677dc920 repair: preserve phase also when not using generaldelta (issue5678)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33461
diff changeset
  2237
    # locally, such as those from strip and shelve, and temporary bundles.
91f0677dc920 repair: preserve phase also when not using generaldelta (issue5678)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33461
diff changeset
  2238
    return max(supportedoutgoingversions(repo))
91f0677dc920 repair: preserve phase also when not using generaldelta (issue5678)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33461
diff changeset
  2239
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2240
27929
3b2ac2115464 changegroup: introduce safeversion()
Martin von Zweigbergk <martinvonz@google.com>
parents: 27928
diff changeset
  2241
def safeversion(repo):
3b2ac2115464 changegroup: introduce safeversion()
Martin von Zweigbergk <martinvonz@google.com>
parents: 27928
diff changeset
  2242
    # Finds the smallest version that it's safe to assume clients of the repo
27931
1289a122cf3f shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 27929
diff changeset
  2243
    # will support. For example, all hg versions that support generaldelta also
1289a122cf3f shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents: 27929
diff changeset
  2244
    # support changegroup 02.
27953
88609cfa3745 changegroup: fix pulling to treemanifest repo from flat repo (issue5066)
Martin von Zweigbergk <martinvonz@google.com>
parents: 27946
diff changeset
  2245
    versions = supportedoutgoingversions(repo)
46627
f4c325bf80fc requirements: also add a generaldelta constant
Raphaël Gomès <rgomes@octobus.net>
parents: 46624
diff changeset
  2246
    if requirements.GENERALDELTA_REQUIREMENT in repo.requirements:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2247
        versions.discard(b'01')
27929
3b2ac2115464 changegroup: introduce safeversion()
Martin von Zweigbergk <martinvonz@google.com>
parents: 27928
diff changeset
  2248
    assert versions
3b2ac2115464 changegroup: introduce safeversion()
Martin von Zweigbergk <martinvonz@google.com>
parents: 27928
diff changeset
  2249
    return min(versions)
3b2ac2115464 changegroup: introduce safeversion()
Martin von Zweigbergk <martinvonz@google.com>
parents: 27928
diff changeset
  2250
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2251
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2252
def getbundler(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2253
    version,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2254
    repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2255
    bundlecaps=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2256
    oldmatcher=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2257
    matcher=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2258
    ellipses=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2259
    shallow=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2260
    ellipsisroots=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2261
    fullnodes=None,
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2262
    remote_sidedata=None,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2263
):
27953
88609cfa3745 changegroup: fix pulling to treemanifest repo from flat repo (issue5066)
Martin von Zweigbergk <martinvonz@google.com>
parents: 27946
diff changeset
  2264
    assert version in supportedoutgoingversions(repo)
38794
1d01cf0416a5 changegroup: move file matcher from narrow extension
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38783
diff changeset
  2265
40344
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  2266
    if matcher is None:
41676
0531dff73d0b match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41673
diff changeset
  2267
        matcher = matchmod.always()
40344
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  2268
    if oldmatcher is None:
41676
0531dff73d0b match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41673
diff changeset
  2269
        oldmatcher = matchmod.never()
38794
1d01cf0416a5 changegroup: move file matcher from narrow extension
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38783
diff changeset
  2270
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2271
    if version == b'01' and not matcher.always():
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2272
        raise error.ProgrammingError(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
  2273
            b'version 01 changegroups do not support sparse file matchers'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2274
        )
38794
1d01cf0416a5 changegroup: move file matcher from narrow extension
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38783
diff changeset
  2275
38908
1469584ad5fe changegroup: specify ellipses mode explicitly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38907
diff changeset
  2276
    if ellipses and version in (b'01', b'02'):
1469584ad5fe changegroup: specify ellipses mode explicitly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38907
diff changeset
  2277
        raise error.Abort(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2278
            _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2279
                b'ellipsis nodes require at least cg3 on client and server, '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2280
                b'but negotiated version %s'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2281
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2282
            % version
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2283
        )
38908
1469584ad5fe changegroup: specify ellipses mode explicitly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38907
diff changeset
  2284
38794
1d01cf0416a5 changegroup: move file matcher from narrow extension
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38783
diff changeset
  2285
    # Requested files could include files not in the local store. So
1d01cf0416a5 changegroup: move file matcher from narrow extension
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38783
diff changeset
  2286
    # filter those out.
40344
2c5835b4246b narrow: when widening, don't include manifests the client already has
Martin von Zweigbergk <martinvonz@google.com>
parents: 40082
diff changeset
  2287
    matcher = repo.narrowmatch(matcher)
38794
1d01cf0416a5 changegroup: move file matcher from narrow extension
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38783
diff changeset
  2288
38894
19344024a8e1 changegroup: define functions for creating changegroup packers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38893
diff changeset
  2289
    fn = _packermap[version][0]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2290
    return fn(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2291
        repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2292
        oldmatcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2293
        matcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2294
        bundlecaps,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2295
        ellipses=ellipses,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2296
        shallow=shallow,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2297
        ellipsisroots=ellipsisroots,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2298
        fullnodes=fullnodes,
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2299
        remote_sidedata=remote_sidedata,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2300
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2301
27751
a40e2f7fe49d changegroup: hide packermap behind methods
Martin von Zweigbergk <martinvonz@google.com>
parents: 27739
diff changeset
  2302
29593
953839de96ab bundle2: store changeset count when creating file bundles
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29371
diff changeset
  2303
def getunbundler(version, fh, alg, extras=None):
953839de96ab bundle2: store changeset count when creating file bundles
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29371
diff changeset
  2304
    return _packermap[version][1](fh, alg, extras=extras)
27751
a40e2f7fe49d changegroup: hide packermap behind methods
Martin von Zweigbergk <martinvonz@google.com>
parents: 27739
diff changeset
  2305
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2306
20926
7c1ed40e3325 localrepo: move the changegroupinfo method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20925
diff changeset
  2307
def _changegroupinfo(repo, nodes, source):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2308
    if repo.ui.verbose or source == b'bundle':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2309
        repo.ui.status(_(b"%d changesets found\n") % len(nodes))
20926
7c1ed40e3325 localrepo: move the changegroupinfo method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20925
diff changeset
  2310
    if repo.ui.debugflag:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2311
        repo.ui.debug(b"list of changesets:\n")
20926
7c1ed40e3325 localrepo: move the changegroupinfo method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20925
diff changeset
  2312
        for node in nodes:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2313
            repo.ui.debug(b"%s\n" % hex(node))
20926
7c1ed40e3325 localrepo: move the changegroupinfo method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20925
diff changeset
  2314
34096
f85dfde1731a changegroup: replace getsubset with makechangegroup
Durham Goode <durham@fb.com>
parents: 34091
diff changeset
  2315
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2316
def makechangegroup(
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  2317
    repo,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  2318
    outgoing,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  2319
    version,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  2320
    source,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  2321
    fastpath=False,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  2322
    bundlecaps=None,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2323
):
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2324
    cgstream = makestream(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2325
        repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2326
        outgoing,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2327
        version,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2328
        source,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2329
        fastpath=fastpath,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2330
        bundlecaps=bundlecaps,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2331
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2332
    return getunbundler(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2333
        version,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2334
        util.chunkbuffer(cgstream),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2335
        None,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2336
        {b'clcount': len(outgoing.missing)},
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2337
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2338
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2339
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2340
def makestream(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2341
    repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2342
    outgoing,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2343
    version,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2344
    source,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2345
    fastpath=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2346
    bundlecaps=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2347
    matcher=None,
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2348
    remote_sidedata=None,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2349
):
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2350
    bundler = getbundler(
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2351
        version,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2352
        repo,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2353
        bundlecaps=bundlecaps,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2354
        matcher=matcher,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2355
        remote_sidedata=remote_sidedata,
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents: 46627
diff changeset
  2356
    )
34103
92f1e2be8ab6 changegroup: rename getsubsetraw to makestream
Durham Goode <durham@fb.com>
parents: 34101
diff changeset
  2357
20925
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20675
diff changeset
  2358
    repo = repo.unfiltered()
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20675
diff changeset
  2359
    commonrevs = outgoing.common
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20675
diff changeset
  2360
    csets = outgoing.missing
45144
c93dd9d9f1e6 discovery: change users of `outgoing.missingheads` to `outgoing.ancestorsof`
Manuel Jacob <me@manueljacob.de>
parents: 44452
diff changeset
  2361
    heads = outgoing.ancestorsof
20925
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20675
diff changeset
  2362
    # We go through the fast path if we get told to, or if all (unfiltered
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20675
diff changeset
  2363
    # heads have been requested (since we then know there all linkrevs will
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20675
diff changeset
  2364
    # be pulled by the client).
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20675
diff changeset
  2365
    heads.sort()
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20675
diff changeset
  2366
    fastpathlinkrev = fastpath or (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2367
        repo.filtername is None and heads == sorted(repo.heads())
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2368
    )
20925
5174c48ed8d8 localrepo: move the _changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20675
diff changeset
  2369
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2370
    repo.hook(b'preoutgoing', throw=True, source=source)
20926
7c1ed40e3325 localrepo: move the changegroupinfo method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20925
diff changeset
  2371
    _changegroupinfo(repo, csets, source)
49610
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  2372
    return bundler.generate(
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  2373
        commonrevs,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  2374
        csets,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  2375
        fastpathlinkrev,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  2376
        source,
9cac281eb9c0 debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49284
diff changeset
  2377
    )
23177
706547a14b8b changegroup: introduce "raw" versions of some commands
Sune Foldager <cryo@cyanite.org>
parents: 23168
diff changeset
  2378
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2379
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
  2380
def _addchangegroupfiles(
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
  2381
    repo,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
  2382
    source,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
  2383
    revmap,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
  2384
    trp,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
  2385
    expectedfiles,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
  2386
    needfiles,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
  2387
    addrevisioncb=None,
49611
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
  2388
    debug_info=None,
49765
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49611
diff changeset
  2389
    delta_base_reuse_policy=None,
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
  2390
):
20932
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2391
    revisions = 0
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2392
    files = 0
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2393
    progress = repo.ui.makeprogress(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2394
        _(b'files'), unit=_(b'files'), total=expectedfiles
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2395
    )
29724
4e7be6e33269 changegroup: use `iter(callable, sentinel)` instead of while True
Augie Fackler <augie@google.com>
parents: 29690
diff changeset
  2396
    for chunkdata in iter(source.filelogheader, {}):
28361
277a22cd8741 changegroup: progress for added files is not measured in "chunks"
Martin von Zweigbergk <martinvonz@google.com>
parents: 28360
diff changeset
  2397
        files += 1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2398
        f = chunkdata[b"filename"]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2399
        repo.ui.debug(b"adding %s revisions\n" % f)
38382
daa08d45740f changegroup: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38373
diff changeset
  2400
        progress.increment()
27754
a09f143daaf4 changegroup3: move treemanifest support into _unpackmanifests()
Martin von Zweigbergk <martinvonz@google.com>
parents: 27753
diff changeset
  2401
        fl = repo.file(f)
20932
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2402
        o = len(fl)
24120
a450e0a2ba0a revlog: in addgroup, reject ill-formed deltas based on censored nodes
Mike Edgar <adgar@google.com>
parents: 23897
diff changeset
  2403
        try:
34291
1db9abf407c5 revlog: add revmap back to revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34257
diff changeset
  2404
            deltas = source.deltaiter()
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
  2405
            added = fl.addgroup(
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
  2406
                deltas,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
  2407
                revmap,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
  2408
                trp,
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
  2409
                addrevisioncb=addrevisioncb,
49611
35d4c2124073 debug: add an option to display statistic about a unbundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49610
diff changeset
  2410
                debug_info=debug_info,
49765
152d9c011bcd changegroup: add `delta_base_reuse_policy` argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49611
diff changeset
  2411
                delta_base_reuse_policy=delta_base_reuse_policy,
46718
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
  2412
            )
ba8e508a8e69 sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents: 46715
diff changeset
  2413
            if not added:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2414
                raise error.Abort(_(b"received file revlog group is empty"))
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25624
diff changeset
  2415
        except error.CensoredBaseError as e:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2416
            raise error.Abort(_(b"received delta base is censored: %s") % e)
27754
a09f143daaf4 changegroup3: move treemanifest support into _unpackmanifests()
Martin von Zweigbergk <martinvonz@google.com>
parents: 27753
diff changeset
  2417
        revisions += len(fl) - o
20932
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2418
        if f in needfiles:
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2419
            needs = needfiles[f]
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
  2420
            for new in range(o, len(fl)):
20932
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2421
                n = fl.node(new)
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2422
                if n in needs:
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2423
                    needs.remove(n)
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2424
                else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2425
                    raise error.Abort(_(b"received spurious file revlog entry"))
20932
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2426
            if not needs:
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2427
                del needfiles[f]
38382
daa08d45740f changegroup: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38373
diff changeset
  2428
    progress.complete()
20932
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2429
48913
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
  2430
    for f, needs in needfiles.items():
20932
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2431
        fl = repo.file(f)
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2432
        for n in needs:
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2433
            try:
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2434
                fl.rev(n)
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2435
            except error.LookupError:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26540
diff changeset
  2436
                raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2437
                    _(b'missing file data for %s:%s - run hg verify')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2438
                    % (f, hex(n))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43059
diff changeset
  2439
                )
20932
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2440
0ac83e4e4f7c localrepo: move the addchangegroupfiles method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20931
diff changeset
  2441
    return revisions, files