hgext/infinitepush/__init__.py
author Sandu Turcan <idlsoft@gmail.com>
Tue, 03 May 2022 21:44:30 -0400
branchstable
changeset 49241 6b10151b9621
parent 47873 c424ff4807e6
child 48875 6000f5b25c9b
permissions -rw-r--r--
narrow_widen_acl: enforce narrowacl in narrow_widen (SEC) Reviewer note: this was sent by the author as a simple bugfix, but can be considered a security patch, since it allows users to access things outside of the ACL, hence the (SEC) prefix. However, this affects the `narrow` extention which is still marked as experimental and has relatively few users aside from large companies with their own security layers on top from what we can gather. We feel (Alphare: or at least, I feel) like pinging the packaging list is enough in this case.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     1
# Infinite push
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     2
#
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     3
# Copyright 2016 Facebook, Inc.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     4
#
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     7
""" store some pushes in a remote blob store on the server (EXPERIMENTAL)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     8
43111
e5d535621ee1 infinitepush: mark extension as likely to be deleted
Augie Fackler <augie@google.com>
parents: 43105
diff changeset
     9
IMPORTANT: if you use this extension, please contact
e5d535621ee1 infinitepush: mark extension as likely to be deleted
Augie Fackler <augie@google.com>
parents: 43105
diff changeset
    10
mercurial-devel@mercurial-scm.org ASAP. This extension is believed to
e5d535621ee1 infinitepush: mark extension as likely to be deleted
Augie Fackler <augie@google.com>
parents: 43105
diff changeset
    11
be unused and barring learning of users of this functionality, we will
e5d535621ee1 infinitepush: mark extension as likely to be deleted
Augie Fackler <augie@google.com>
parents: 43105
diff changeset
    12
delete this code at the end of 2020.
e5d535621ee1 infinitepush: mark extension as likely to be deleted
Augie Fackler <augie@google.com>
parents: 43105
diff changeset
    13
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    14
    [infinitepush]
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    15
    # Server-side and client-side option. Pattern of the infinitepush bookmark
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    16
    branchpattern = PATTERN
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    17
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    18
    # Server or client
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    19
    server = False
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    20
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    21
    # Server-side option. Possible values: 'disk' or 'sql'. Fails if not set
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    22
    indextype = disk
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    23
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    24
    # Server-side option. Used only if indextype=sql.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    25
    # Format: 'IP:PORT:DB_NAME:USER:PASSWORD'
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    26
    sqlhost = IP:PORT:DB_NAME:USER:PASSWORD
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    27
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    28
    # Server-side option. Used only if indextype=disk.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    29
    # Filesystem path to the index store
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    30
    indexpath = PATH
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    31
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    32
    # Server-side option. Possible values: 'disk' or 'external'
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    33
    # Fails if not set
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    34
    storetype = disk
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    35
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    36
    # Server-side option.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    37
    # Path to the binary that will save bundle to the bundlestore
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    38
    # Formatted cmd line will be passed to it (see `put_args`)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    39
    put_binary = put
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    40
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    41
    # Serser-side option. Used only if storetype=external.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    42
    # Format cmd-line string for put binary. Placeholder: {filename}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    43
    put_args = {filename}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    44
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    45
    # Server-side option.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    46
    # Path to the binary that get bundle from the bundlestore.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    47
    # Formatted cmd line will be passed to it (see `get_args`)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    48
    get_binary = get
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    49
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    50
    # Serser-side option. Used only if storetype=external.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    51
    # Format cmd-line string for get binary. Placeholders: {filename} {handle}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    52
    get_args = {filename} {handle}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    53
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    54
    # Server-side option
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    55
    logfile = FIlE
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    56
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    57
    # Server-side option
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    58
    loglevel = DEBUG
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    59
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    60
    # Server-side option. Used only if indextype=sql.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    61
    # Sets mysql wait_timeout option.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    62
    waittimeout = 300
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    63
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    64
    # Server-side option. Used only if indextype=sql.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    65
    # Sets mysql innodb_lock_wait_timeout option.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    66
    locktimeout = 120
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    67
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    68
    # Server-side option. Used only if indextype=sql.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    69
    # Name of the repository
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    70
    reponame = ''
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    71
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    72
    # Client-side option. Used by --list-remote option. List of remote scratch
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    73
    # patterns to list if no patterns are specified.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    74
    defaultremotepatterns = ['*']
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    75
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    76
    # Instructs infinitepush to forward all received bundle2 parts to the
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    77
    # bundle for storage. Defaults to False.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    78
    storeallparts = True
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    79
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
    80
    # routes each incoming push to the bundlestore. defaults to False
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
    81
    pushtobundlestore = True
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
    82
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    83
    [remotenames]
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    84
    # Client-side option
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    85
    # This option should be set only if remotenames extension is enabled.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    86
    # Whether remote bookmarks are tracked by remotenames extension.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    87
    bookmarks = True
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    88
"""
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    89
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    90
from __future__ import absolute_import
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    91
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    92
import collections
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    93
import contextlib
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    94
import errno
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    95
import functools
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    96
import logging
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    97
import os
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    98
import random
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    99
import re
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   100
import socket
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   101
import subprocess
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   102
import time
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   103
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   104
from mercurial.node import (
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   105
    bin,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   106
    hex,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   107
)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   108
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   109
from mercurial.i18n import _
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   110
43089
c59eb1560c44 py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43085
diff changeset
   111
from mercurial.pycompat import (
c59eb1560c44 py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43085
diff changeset
   112
    getattr,
c59eb1560c44 py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43085
diff changeset
   113
    open,
c59eb1560c44 py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43085
diff changeset
   114
)
43085
eef9a2d67051 py3: manually import pycompat.open into files that need it
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
   115
37204
0d6c12668691 inifnitepush: use utils.{stringutil|procutil}.* instead of util.*
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37203
diff changeset
   116
from mercurial.utils import (
0d6c12668691 inifnitepush: use utils.{stringutil|procutil}.* instead of util.*
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37203
diff changeset
   117
    procutil,
0d6c12668691 inifnitepush: use utils.{stringutil|procutil}.* instead of util.*
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37203
diff changeset
   118
    stringutil,
46908
4452cb788404 urlutil: extract `parseurl` from `hg` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46720
diff changeset
   119
    urlutil,
37204
0d6c12668691 inifnitepush: use utils.{stringutil|procutil}.* instead of util.*
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37203
diff changeset
   120
)
0d6c12668691 inifnitepush: use utils.{stringutil|procutil}.* instead of util.*
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37203
diff changeset
   121
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   122
from mercurial import (
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   123
    bundle2,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   124
    changegroup,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   125
    commands,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   126
    discovery,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   127
    encoding,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   128
    error,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   129
    exchange,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   130
    extensions,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   131
    hg,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   132
    localrepo,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   133
    phases,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   134
    pushkey,
37577
e7eea8582afa py3: use pycompat.{strkwargs|byteskwargs} in infinitepush
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37239
diff changeset
   135
    pycompat,
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   136
    registrar,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   137
    util,
37612
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   138
    wireprototypes,
37614
a81d02ea65db wireproto: move version 1 peer functionality to standalone module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   139
    wireprotov1peer,
37785
b4d85bc122bd wireproto: rename wireproto to wireprotov1server (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37615
diff changeset
   140
    wireprotov1server,
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   141
)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   142
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   143
from . import (
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   144
    bundleparts,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   145
    common,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   146
)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   147
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   148
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   149
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   150
# be specifying the version(s) of Mercurial they are tested with, or
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   151
# leave the attribute unspecified.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   152
testedwith = b'ships-with-hg-core'
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   153
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   154
configtable = {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   155
configitem = registrar.configitem(configtable)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   156
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   157
configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   158
    b'infinitepush',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   159
    b'server',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   160
    default=False,
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   161
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   162
configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   163
    b'infinitepush',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   164
    b'storetype',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   165
    default=b'',
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   166
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   167
configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   168
    b'infinitepush',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   169
    b'indextype',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   170
    default=b'',
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   171
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   172
configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   173
    b'infinitepush',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   174
    b'indexpath',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   175
    default=b'',
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   176
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   177
configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   178
    b'infinitepush',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   179
    b'storeallparts',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   180
    default=False,
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   181
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   182
configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   183
    b'infinitepush',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   184
    b'reponame',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   185
    default=b'',
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   186
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   187
configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   188
    b'scratchbranch',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   189
    b'storepath',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   190
    default=b'',
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   191
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   192
configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   193
    b'infinitepush',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   194
    b'branchpattern',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   195
    default=b'',
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   196
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   197
configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   198
    b'infinitepush',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   199
    b'pushtobundlestore',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   200
    default=False,
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
   201
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   202
configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   203
    b'experimental',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   204
    b'server-bundlestore-bookmark',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   205
    default=b'',
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   206
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   207
configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   208
    b'experimental',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   209
    b'infinitepush-scratchpush',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   210
    default=False,
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   211
)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   212
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   213
experimental = b'experimental'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   214
configbookmark = b'server-bundlestore-bookmark'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   215
configscratchpush = b'infinitepush-scratchpush'
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   216
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   217
scratchbranchparttype = bundleparts.scratchbranchparttype
37188
de4c2f3af97f infinitepush: remove backupcommands.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37187
diff changeset
   218
revsetpredicate = registrar.revsetpredicate()
de4c2f3af97f infinitepush: remove backupcommands.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37187
diff changeset
   219
templatekeyword = registrar.templatekeyword()
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   220
_scratchbranchmatcher = lambda x: False
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43363
diff changeset
   221
_maybehash = re.compile('^[a-f0-9]+$').search
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   222
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   223
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   224
def _buildexternalbundlestore(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   225
    put_args = ui.configlist(b'infinitepush', b'put_args', [])
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   226
    put_binary = ui.config(b'infinitepush', b'put_binary')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   227
    if not put_binary:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   228
        raise error.Abort(b'put binary is not specified')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   229
    get_args = ui.configlist(b'infinitepush', b'get_args', [])
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   230
    get_binary = ui.config(b'infinitepush', b'get_binary')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   231
    if not get_binary:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   232
        raise error.Abort(b'get binary is not specified')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   233
    from . import store
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   234
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   235
    return store.externalbundlestore(put_binary, put_args, get_binary, get_args)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   236
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   237
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   238
def _buildsqlindex(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   239
    sqlhost = ui.config(b'infinitepush', b'sqlhost')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   240
    if not sqlhost:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   241
        raise error.Abort(_(b'please set infinitepush.sqlhost'))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   242
    host, port, db, user, password = sqlhost.split(b':')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   243
    reponame = ui.config(b'infinitepush', b'reponame')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   244
    if not reponame:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   245
        raise error.Abort(_(b'please set infinitepush.reponame'))
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   246
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   247
    logfile = ui.config(b'infinitepush', b'logfile', b'')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   248
    waittimeout = ui.configint(b'infinitepush', b'waittimeout', 300)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   249
    locktimeout = ui.configint(b'infinitepush', b'locktimeout', 120)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   250
    from . import sqlindexapi
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   251
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   252
    return sqlindexapi.sqlindexapi(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   253
        reponame,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   254
        host,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   255
        port,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   256
        db,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   257
        user,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   258
        password,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   259
        logfile,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   260
        _getloglevel(ui),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   261
        waittimeout=waittimeout,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   262
        locktimeout=locktimeout,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   263
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   264
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   265
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   266
def _getloglevel(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   267
    loglevel = ui.config(b'infinitepush', b'loglevel', b'DEBUG')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   268
    numeric_loglevel = getattr(logging, loglevel.upper(), None)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   269
    if not isinstance(numeric_loglevel, int):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   270
        raise error.Abort(_(b'invalid log level %s') % loglevel)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   271
    return numeric_loglevel
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   272
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   273
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   274
def _tryhoist(ui, remotebookmark):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   275
    """returns a bookmarks with hoisted part removed
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   276
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   277
    Remotenames extension has a 'hoist' config that allows to use remote
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   278
    bookmarks without specifying remote path. For example, 'hg update master'
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   279
    works as well as 'hg update remote/master'. We want to allow the same in
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   280
    infinitepush.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   281
    """
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   282
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   283
    if common.isremotebooksenabled(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   284
        hoist = ui.config(b'remotenames', b'hoistedpeer') + b'/'
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   285
        if remotebookmark.startswith(hoist):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   286
            return remotebookmark[len(hoist) :]
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   287
    return remotebookmark
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   288
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   289
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   290
class bundlestore(object):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   291
    def __init__(self, repo):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   292
        self._repo = repo
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   293
        storetype = self._repo.ui.config(b'infinitepush', b'storetype')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   294
        if storetype == b'disk':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   295
            from . import store
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   296
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   297
            self.store = store.filebundlestore(self._repo.ui, self._repo)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   298
        elif storetype == b'external':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   299
            self.store = _buildexternalbundlestore(self._repo.ui)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   300
        else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   301
            raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   302
                _(b'unknown infinitepush store type specified %s') % storetype
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   303
            )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   304
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   305
        indextype = self._repo.ui.config(b'infinitepush', b'indextype')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   306
        if indextype == b'disk':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   307
            from . import fileindexapi
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   308
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   309
            self.index = fileindexapi.fileindexapi(self._repo)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   310
        elif indextype == b'sql':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   311
            self.index = _buildsqlindex(self._repo.ui)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   312
        else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   313
            raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   314
                _(b'unknown infinitepush index type specified %s') % indextype
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   315
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   316
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   317
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   318
def _isserver(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   319
    return ui.configbool(b'infinitepush', b'server')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   320
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   321
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   322
def reposetup(ui, repo):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   323
    if _isserver(ui) and repo.local():
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   324
        repo.bundlestore = bundlestore(repo)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   325
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   326
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   327
def extsetup(ui):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   328
    commonsetup(ui)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   329
    if _isserver(ui):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   330
        serverextsetup(ui)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   331
    else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   332
        clientextsetup(ui)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   333
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   334
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   335
def commonsetup(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   336
    wireprotov1server.commands[b'listkeyspatterns'] = (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   337
        wireprotolistkeyspatterns,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   338
        b'namespace patterns',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   339
    )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   340
    scratchbranchpat = ui.config(b'infinitepush', b'branchpattern')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   341
    if scratchbranchpat:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   342
        global _scratchbranchmatcher
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   343
        kind, pat, _scratchbranchmatcher = stringutil.stringmatcher(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   344
            scratchbranchpat
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   345
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   346
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   347
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   348
def serverextsetup(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   349
    origpushkeyhandler = bundle2.parthandlermapping[b'pushkey']
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   350
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   351
    def newpushkeyhandler(*args, **kwargs):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   352
        bundle2pushkey(origpushkeyhandler, *args, **kwargs)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   353
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   354
    newpushkeyhandler.params = origpushkeyhandler.params
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   355
    bundle2.parthandlermapping[b'pushkey'] = newpushkeyhandler
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   356
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   357
    orighandlephasehandler = bundle2.parthandlermapping[b'phase-heads']
41759
aaad36b88298 cleanup: use () to wrap long lines instead of \
Augie Fackler <augie@google.com>
parents: 40252
diff changeset
   358
    newphaseheadshandler = lambda *args, **kwargs: bundle2handlephases(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   359
        orighandlephasehandler, *args, **kwargs
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   360
    )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   361
    newphaseheadshandler.params = orighandlephasehandler.params
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   362
    bundle2.parthandlermapping[b'phase-heads'] = newphaseheadshandler
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   363
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   364
    extensions.wrapfunction(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   365
        localrepo.localrepository, b'listkeys', localrepolistkeys
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   366
    )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   367
    wireprotov1server.commands[b'lookup'] = (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   368
        _lookupwrap(wireprotov1server.commands[b'lookup'][0]),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   369
        b'key',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   370
    )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   371
    extensions.wrapfunction(exchange, b'getbundlechunks', getbundlechunks)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   372
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   373
    extensions.wrapfunction(bundle2, b'processparts', processparts)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   374
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   375
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   376
def clientextsetup(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   377
    entry = extensions.wrapcommand(commands.table, b'push', _push)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   378
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   379
    entry[1].append(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   380
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   381
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   382
            b'bundle-store',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   383
            None,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   384
            _(b'force push to go to bundle store (EXPERIMENTAL)'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   385
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   386
    )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   387
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   388
    extensions.wrapcommand(commands.table, b'pull', _pull)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   389
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   390
    extensions.wrapfunction(discovery, b'checkheads', _checkheads)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   391
37614
a81d02ea65db wireproto: move version 1 peer functionality to standalone module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   392
    wireprotov1peer.wirepeer.listkeyspatterns = listkeyspatterns
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   393
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   394
    partorder = exchange.b2partsgenorder
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   395
    index = partorder.index(b'changeset')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   396
    partorder.insert(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   397
        index, partorder.pop(partorder.index(scratchbranchparttype))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   398
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   399
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   400
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   401
def _checkheads(orig, pushop):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   402
    if pushop.ui.configbool(experimental, configscratchpush, False):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   403
        return
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   404
    return orig(pushop)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   405
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   406
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   407
def wireprotolistkeyspatterns(repo, proto, namespace, patterns):
37612
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   408
    patterns = wireprototypes.decodelist(patterns)
43105
649d3ac37a12 py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43089
diff changeset
   409
    d = pycompat.iteritems(repo.listkeys(encoding.tolocal(namespace), patterns))
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   410
    return pushkey.encodekeys(d)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   411
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   412
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   413
def localrepolistkeys(orig, self, namespace, patterns=None):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   414
    if namespace == b'bookmarks' and patterns:
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   415
        index = self.bundlestore.index
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   416
        results = {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   417
        bookmarks = orig(self, namespace)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   418
        for pattern in patterns:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   419
            results.update(index.getbookmarks(pattern))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   420
            if pattern.endswith(b'*'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   421
                pattern = b're:^' + pattern[:-1] + b'.*'
37204
0d6c12668691 inifnitepush: use utils.{stringutil|procutil}.* instead of util.*
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37203
diff changeset
   422
            kind, pat, matcher = stringutil.stringmatcher(pattern)
43105
649d3ac37a12 py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43089
diff changeset
   423
            for bookmark, node in pycompat.iteritems(bookmarks):
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   424
                if matcher(bookmark):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   425
                    results[bookmark] = node
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   426
        return results
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   427
    else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   428
        return orig(self, namespace)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   429
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   430
37615
f3dc8239e3a9 peer: scatter module to the wind (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37614
diff changeset
   431
@wireprotov1peer.batchable
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   432
def listkeyspatterns(self, namespace, patterns):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   433
    if not self.capable(b'pushkey'):
47873
c424ff4807e6 wireprotov1peer: update all rpcs to use the new batchable scheme
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46943
diff changeset
   434
        return {}, None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   435
    self.ui.debug(b'preparing listkeys for "%s"\n' % namespace)
47873
c424ff4807e6 wireprotov1peer: update all rpcs to use the new batchable scheme
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46943
diff changeset
   436
c424ff4807e6 wireprotov1peer: update all rpcs to use the new batchable scheme
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46943
diff changeset
   437
    def decode(d):
c424ff4807e6 wireprotov1peer: update all rpcs to use the new batchable scheme
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46943
diff changeset
   438
        self.ui.debug(
c424ff4807e6 wireprotov1peer: update all rpcs to use the new batchable scheme
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46943
diff changeset
   439
            b'received listkey for "%s": %i bytes\n' % (namespace, len(d))
c424ff4807e6 wireprotov1peer: update all rpcs to use the new batchable scheme
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46943
diff changeset
   440
        )
c424ff4807e6 wireprotov1peer: update all rpcs to use the new batchable scheme
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46943
diff changeset
   441
        return pushkey.decodekeys(d)
c424ff4807e6 wireprotov1peer: update all rpcs to use the new batchable scheme
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46943
diff changeset
   442
c424ff4807e6 wireprotov1peer: update all rpcs to use the new batchable scheme
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46943
diff changeset
   443
    return {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   444
        b'namespace': encoding.fromlocal(namespace),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   445
        b'patterns': wireprototypes.encodelist(patterns),
47873
c424ff4807e6 wireprotov1peer: update all rpcs to use the new batchable scheme
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 46943
diff changeset
   446
    }, decode
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   447
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   448
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   449
def _readbundlerevs(bundlerepo):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   450
    return list(bundlerepo.revs(b'bundle()'))
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   451
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   452
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   453
def _includefilelogstobundle(bundlecaps, bundlerepo, bundlerevs, ui):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   454
    """Tells remotefilelog to include all changed files to the changegroup
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   455
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   456
    By default remotefilelog doesn't include file content to the changegroup.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   457
    But we need to include it if we are fetching from bundlestore.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   458
    """
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   459
    changedfiles = set()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   460
    cl = bundlerepo.changelog
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   461
    for r in bundlerevs:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   462
        # [3] means changed files
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   463
        changedfiles.update(cl.read(r)[3])
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   464
    if not changedfiles:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   465
        return bundlecaps
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   466
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   467
    changedfiles = b'\0'.join(changedfiles)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   468
    newcaps = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   469
    appended = False
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   470
    for cap in bundlecaps or []:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   471
        if cap.startswith(b'excludepattern='):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   472
            newcaps.append(b'\0'.join((cap, changedfiles)))
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   473
            appended = True
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   474
        else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   475
            newcaps.append(cap)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   476
    if not appended:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   477
        # Not found excludepattern cap. Just append it
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   478
        newcaps.append(b'excludepattern=' + changedfiles)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   479
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   480
    return newcaps
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   481
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   482
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   483
def _rebundle(bundlerepo, bundleroots, unknownhead):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   484
    """
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   485
    Bundle may include more revision then user requested. For example,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   486
    if user asks for revision but bundle also consists its descendants.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   487
    This function will filter out all revision that user is not requested.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   488
    """
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   489
    parts = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   490
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   491
    version = b'02'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   492
    outgoing = discovery.outgoing(
45144
c93dd9d9f1e6 discovery: change users of `outgoing.missingheads` to `outgoing.ancestorsof`
Manuel Jacob <me@manueljacob.de>
parents: 43550
diff changeset
   493
        bundlerepo, commonheads=bundleroots, ancestorsof=[unknownhead]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   494
    )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   495
    cgstream = changegroup.makestream(bundlerepo, outgoing, version, b'pull')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   496
    cgstream = util.chunkbuffer(cgstream).read()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   497
    cgpart = bundle2.bundlepart(b'changegroup', data=cgstream)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   498
    cgpart.addparam(b'version', version)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   499
    parts.append(cgpart)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   500
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   501
    return parts
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   502
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   503
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   504
def _getbundleroots(oldrepo, bundlerepo, bundlerevs):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   505
    cl = bundlerepo.changelog
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   506
    bundleroots = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   507
    for rev in bundlerevs:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   508
        node = cl.node(rev)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   509
        parents = cl.parents(node)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   510
        for parent in parents:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   511
            # include all revs that exist in the main repo
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   512
            # to make sure that bundle may apply client-side
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   513
            if parent in oldrepo:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   514
                bundleroots.append(parent)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   515
    return bundleroots
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   516
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   517
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   518
def _needsrebundling(head, bundlerepo):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   519
    bundleheads = list(bundlerepo.revs(b'heads(bundle())'))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   520
    return not (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   521
        len(bundleheads) == 1 and bundlerepo[bundleheads[0]].node() == head
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   522
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   523
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   524
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   525
def _generateoutputparts(head, bundlerepo, bundleroots, bundlefile):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   526
    """generates bundle that will be send to the user
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   527
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   528
    returns tuple with raw bundle string and bundle type
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
   529
    """
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   530
    parts = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   531
    if not _needsrebundling(head, bundlerepo):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   532
        with util.posixfile(bundlefile, b"rb") as f:
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   533
            unbundler = exchange.readbundle(bundlerepo.ui, f, bundlefile)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   534
            if isinstance(unbundler, changegroup.cg1unpacker):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   535
                part = bundle2.bundlepart(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   536
                    b'changegroup', data=unbundler._stream.read()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   537
                )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   538
                part.addparam(b'version', b'01')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   539
                parts.append(part)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   540
            elif isinstance(unbundler, bundle2.unbundle20):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   541
                haschangegroup = False
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   542
                for part in unbundler.iterparts():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   543
                    if part.type == b'changegroup':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   544
                        haschangegroup = True
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   545
                    newpart = bundle2.bundlepart(part.type, data=part.read())
43105
649d3ac37a12 py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43089
diff changeset
   546
                    for key, value in pycompat.iteritems(part.params):
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   547
                        newpart.addparam(key, value)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   548
                    parts.append(newpart)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   549
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   550
                if not haschangegroup:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   551
                    raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   552
                        b'unexpected bundle without changegroup part, '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   553
                        + b'head: %s' % hex(head),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   554
                        hint=b'report to administrator',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   555
                    )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   556
            else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   557
                raise error.Abort(b'unknown bundle type')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   558
    else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   559
        parts = _rebundle(bundlerepo, bundleroots, head)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   560
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   561
    return parts
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   562
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   563
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   564
def getbundlechunks(orig, repo, source, heads=None, bundlecaps=None, **kwargs):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   565
    heads = heads or []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   566
    # newheads are parents of roots of scratch bundles that were requested
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   567
    newphases = {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   568
    scratchbundles = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   569
    newheads = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   570
    scratchheads = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   571
    nodestobundle = {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   572
    allbundlestocleanup = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   573
    try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   574
        for head in heads:
43550
a936a3455bb1 index: use `index.has_node` in `infinitypush`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43506
diff changeset
   575
            if not repo.changelog.index.has_node(head):
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   576
                if head not in nodestobundle:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   577
                    newbundlefile = common.downloadbundle(repo, head)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   578
                    bundlepath = b"bundle:%s+%s" % (repo.root, newbundlefile)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   579
                    bundlerepo = hg.repository(repo.ui, bundlepath)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   580
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   581
                    allbundlestocleanup.append((bundlerepo, newbundlefile))
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   582
                    bundlerevs = set(_readbundlerevs(bundlerepo))
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   583
                    bundlecaps = _includefilelogstobundle(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   584
                        bundlecaps, bundlerepo, bundlerevs, repo.ui
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   585
                    )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   586
                    cl = bundlerepo.changelog
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   587
                    bundleroots = _getbundleroots(repo, bundlerepo, bundlerevs)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   588
                    for rev in bundlerevs:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   589
                        node = cl.node(rev)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   590
                        newphases[hex(node)] = str(phases.draft)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   591
                        nodestobundle[node] = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   592
                            bundlerepo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   593
                            bundleroots,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   594
                            newbundlefile,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   595
                        )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   596
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   597
                scratchbundles.append(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   598
                    _generateoutputparts(head, *nodestobundle[head])
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   599
                )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   600
                newheads.extend(bundleroots)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   601
                scratchheads.append(head)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   602
    finally:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   603
        for bundlerepo, bundlefile in allbundlestocleanup:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   604
            bundlerepo.close()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   605
            try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   606
                os.unlink(bundlefile)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   607
            except (IOError, OSError):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   608
                # if we can't cleanup the file then just ignore the error,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   609
                # no need to fail
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   610
                pass
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   611
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   612
    pullfrombundlestore = bool(scratchbundles)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   613
    wrappedchangegrouppart = False
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   614
    wrappedlistkeys = False
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   615
    oldchangegrouppart = exchange.getbundle2partsmapping[b'changegroup']
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   616
    try:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   617
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   618
        def _changegrouppart(bundler, *args, **kwargs):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   619
            # Order is important here. First add non-scratch part
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   620
            # and only then add parts with scratch bundles because
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   621
            # non-scratch part contains parents of roots of scratch bundles.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   622
            result = oldchangegrouppart(bundler, *args, **kwargs)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   623
            for bundle in scratchbundles:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   624
                for part in bundle:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   625
                    bundler.addpart(part)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   626
            return result
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   627
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   628
        exchange.getbundle2partsmapping[b'changegroup'] = _changegrouppart
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   629
        wrappedchangegrouppart = True
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   630
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   631
        def _listkeys(orig, self, namespace):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   632
            origvalues = orig(self, namespace)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   633
            if namespace == b'phases' and pullfrombundlestore:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   634
                if origvalues.get(b'publishing') == b'True':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   635
                    # Make repo non-publishing to preserve draft phase
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   636
                    del origvalues[b'publishing']
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   637
                origvalues.update(newphases)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   638
            return origvalues
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   639
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   640
        extensions.wrapfunction(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   641
            localrepo.localrepository, b'listkeys', _listkeys
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   642
        )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   643
        wrappedlistkeys = True
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   644
        heads = list((set(newheads) | set(heads)) - set(scratchheads))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   645
        result = orig(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   646
            repo, source, heads=heads, bundlecaps=bundlecaps, **kwargs
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   647
        )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   648
    finally:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   649
        if wrappedchangegrouppart:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   650
            exchange.getbundle2partsmapping[b'changegroup'] = oldchangegrouppart
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   651
        if wrappedlistkeys:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   652
            extensions.unwrapfunction(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   653
                localrepo.localrepository, b'listkeys', _listkeys
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   654
            )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   655
    return result
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   656
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   657
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   658
def _lookupwrap(orig):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   659
    def _lookup(repo, proto, key):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   660
        localkey = encoding.tolocal(key)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   661
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   662
        if isinstance(localkey, str) and _scratchbranchmatcher(localkey):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   663
            scratchnode = repo.bundlestore.index.getnode(localkey)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   664
            if scratchnode:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   665
                return b"%d %s\n" % (1, scratchnode)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   666
            else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   667
                return b"%d %s\n" % (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   668
                    0,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   669
                    b'scratch branch %s not found' % localkey,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   670
                )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   671
        else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   672
            try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   673
                r = hex(repo.lookup(localkey))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   674
                return b"%d %s\n" % (1, r)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   675
            except Exception as inst:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   676
                if repo.bundlestore.index.getbundle(localkey):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   677
                    return b"%d %s\n" % (1, localkey)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   678
                else:
38083
5f2dc1b71cf1 py3: use utils.stringutil.forcebytestr to convert error to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38067
diff changeset
   679
                    r = stringutil.forcebytestr(inst)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   680
                    return b"%d %s\n" % (0, r)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   681
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   682
    return _lookup
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   683
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   684
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   685
def _pull(orig, ui, repo, source=b"default", **opts):
37577
e7eea8582afa py3: use pycompat.{strkwargs|byteskwargs} in infinitepush
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37239
diff changeset
   686
    opts = pycompat.byteskwargs(opts)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   687
    # Copy paste from `pull` command
46943
30ee1224b9a2 infinitepush: use `get_unique_pull_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46911
diff changeset
   688
    source, branches = urlutil.get_unique_pull_path(
30ee1224b9a2 infinitepush: use `get_unique_pull_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46911
diff changeset
   689
        b"infinite-push's pull",
30ee1224b9a2 infinitepush: use `get_unique_pull_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46911
diff changeset
   690
        repo,
30ee1224b9a2 infinitepush: use `get_unique_pull_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46911
diff changeset
   691
        ui,
30ee1224b9a2 infinitepush: use `get_unique_pull_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46911
diff changeset
   692
        source,
30ee1224b9a2 infinitepush: use `get_unique_pull_path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46911
diff changeset
   693
        default_branches=opts.get(b'branch'),
46908
4452cb788404 urlutil: extract `parseurl` from `hg` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46720
diff changeset
   694
    )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   695
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   696
    scratchbookmarks = {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   697
    unfi = repo.unfiltered()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   698
    unknownnodes = []
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   699
    for rev in opts.get(b'rev', []):
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   700
        if rev not in unfi:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   701
            unknownnodes.append(rev)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   702
    if opts.get(b'bookmark'):
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   703
        bookmarks = []
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   704
        revs = opts.get(b'rev') or []
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   705
        for bookmark in opts.get(b'bookmark'):
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   706
            if _scratchbranchmatcher(bookmark):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   707
                # rev is not known yet
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   708
                # it will be fetched with listkeyspatterns next
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   709
                scratchbookmarks[bookmark] = b'REVTOFETCH'
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   710
            else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   711
                bookmarks.append(bookmark)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   712
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   713
        if scratchbookmarks:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   714
            other = hg.peer(repo, opts, source)
46663
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   715
            try:
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   716
                fetchedbookmarks = other.listkeyspatterns(
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   717
                    b'bookmarks', patterns=scratchbookmarks
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   718
                )
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   719
                for bookmark in scratchbookmarks:
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   720
                    if bookmark not in fetchedbookmarks:
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   721
                        raise error.Abort(
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   722
                            b'remote bookmark %s not found!' % bookmark
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   723
                        )
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   724
                    scratchbookmarks[bookmark] = fetchedbookmarks[bookmark]
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   725
                    revs.append(fetchedbookmarks[bookmark])
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   726
            finally:
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   727
                other.close()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   728
        opts[b'bookmark'] = bookmarks
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   729
        opts[b'rev'] = revs
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   730
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   731
    if scratchbookmarks or unknownnodes:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   732
        # Set anyincoming to True
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   733
        extensions.wrapfunction(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   734
            discovery, b'findcommonincoming', _findcommonincoming
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   735
        )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   736
    try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   737
        # Remote scratch bookmarks will be deleted because remotenames doesn't
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   738
        # know about them. Let's save it before pull and restore after
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   739
        remotescratchbookmarks = _readscratchremotebookmarks(ui, repo, source)
37577
e7eea8582afa py3: use pycompat.{strkwargs|byteskwargs} in infinitepush
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37239
diff changeset
   740
        result = orig(ui, repo, source, **pycompat.strkwargs(opts))
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   741
        # TODO(stash): race condition is possible
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   742
        # if scratch bookmarks was updated right after orig.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   743
        # But that's unlikely and shouldn't be harmful.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   744
        if common.isremotebooksenabled(ui):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   745
            remotescratchbookmarks.update(scratchbookmarks)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   746
            _saveremotebookmarks(repo, remotescratchbookmarks, source)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   747
        else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   748
            _savelocalbookmarks(repo, scratchbookmarks)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   749
        return result
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   750
    finally:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   751
        if scratchbookmarks:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   752
            extensions.unwrapfunction(discovery, b'findcommonincoming')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   753
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   754
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   755
def _readscratchremotebookmarks(ui, repo, other):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   756
    if common.isremotebooksenabled(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   757
        remotenamesext = extensions.find(b'remotenames')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   758
        remotepath = remotenamesext.activepath(repo.ui, other)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   759
        result = {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   760
        # Let's refresh remotenames to make sure we have it up to date
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   761
        # Seems that `repo.names['remotebookmarks']` may return stale bookmarks
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   762
        # and it results in deleting scratch bookmarks. Our best guess how to
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   763
        # fix it is to use `clearnames()`
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   764
        repo._remotenames.clearnames()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   765
        for remotebookmark in repo.names[b'remotebookmarks'].listnames(repo):
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   766
            path, bookname = remotenamesext.splitremotename(remotebookmark)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   767
            if path == remotepath and _scratchbranchmatcher(bookname):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   768
                nodes = repo.names[b'remotebookmarks'].nodes(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   769
                    repo, remotebookmark
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   770
                )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   771
                if nodes:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   772
                    result[bookname] = hex(nodes[0])
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   773
        return result
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   774
    else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   775
        return {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   776
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   777
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   778
def _saveremotebookmarks(repo, newbookmarks, remote):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   779
    remotenamesext = extensions.find(b'remotenames')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   780
    remotepath = remotenamesext.activepath(repo.ui, remote)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   781
    branches = collections.defaultdict(list)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   782
    bookmarks = {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   783
    remotenames = remotenamesext.readremotenames(repo)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   784
    for hexnode, nametype, remote, rname in remotenames:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   785
        if remote != remotepath:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   786
            continue
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   787
        if nametype == b'bookmarks':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   788
            if rname in newbookmarks:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   789
                # It's possible if we have a normal bookmark that matches
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   790
                # scratch branch pattern. In this case just use the current
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   791
                # bookmark node
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   792
                del newbookmarks[rname]
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   793
            bookmarks[rname] = hexnode
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   794
        elif nametype == b'branches':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   795
            # saveremotenames expects 20 byte binary nodes for branches
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   796
            branches[rname].append(bin(hexnode))
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   797
43105
649d3ac37a12 py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43089
diff changeset
   798
    for bookmark, hexnode in pycompat.iteritems(newbookmarks):
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   799
        bookmarks[bookmark] = hexnode
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   800
    remotenamesext.saveremotenames(repo, remotepath, branches, bookmarks)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   801
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   802
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   803
def _savelocalbookmarks(repo, bookmarks):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   804
    if not bookmarks:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   805
        return
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   806
    with repo.wlock(), repo.lock(), repo.transaction(b'bookmark') as tr:
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   807
        changes = []
43105
649d3ac37a12 py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43089
diff changeset
   808
        for scratchbook, node in pycompat.iteritems(bookmarks):
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   809
            changectx = repo[node]
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   810
            changes.append((scratchbook, changectx.node()))
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   811
        repo._bookmarks.applychanges(repo, tr, changes)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   812
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   813
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   814
def _findcommonincoming(orig, *args, **kwargs):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   815
    common, inc, remoteheads = orig(*args, **kwargs)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   816
    return common, True, remoteheads
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   817
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   818
46911
6071bfab6292 infinitepush: use the new function to determine push destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46908
diff changeset
   819
def _push(orig, ui, repo, *dests, **opts):
40252
090e5f3900b7 py3: fix infinitepush extension tests
Mark Thomas <mbthomas@fb.com>
parents: 39826
diff changeset
   820
    opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   821
    bookmark = opts.get(b'bookmark')
37199
c5687ce3b411 infinitepush: drop the `--to` flag to push and use `-B` instead
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37198
diff changeset
   822
    # we only support pushing one infinitepush bookmark at once
c5687ce3b411 infinitepush: drop the `--to` flag to push and use `-B` instead
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37198
diff changeset
   823
    if len(bookmark) == 1:
c5687ce3b411 infinitepush: drop the `--to` flag to push and use `-B` instead
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37198
diff changeset
   824
        bookmark = bookmark[0]
c5687ce3b411 infinitepush: drop the `--to` flag to push and use `-B` instead
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37198
diff changeset
   825
    else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   826
        bookmark = b''
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   827
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   828
    oldphasemove = None
37198
78c2e9418278 infinitepush: drop the `--create` flag to push command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37197
diff changeset
   829
    overrides = {(experimental, configbookmark): bookmark}
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   830
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   831
    with ui.configoverride(overrides, b'infinitepush'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   832
        scratchpush = opts.get(b'bundle_store')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   833
        if _scratchbranchmatcher(bookmark):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   834
            scratchpush = True
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   835
            # bundle2 can be sent back after push (for example, bundle2
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   836
            # containing `pushkey` part to update bookmarks)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   837
            ui.setconfig(experimental, b'bundle2.pushback', True)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   838
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   839
        if scratchpush:
37199
c5687ce3b411 infinitepush: drop the `--to` flag to push and use `-B` instead
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37198
diff changeset
   840
            # this is an infinitepush, we don't want the bookmark to be applied
c5687ce3b411 infinitepush: drop the `--to` flag to push and use `-B` instead
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37198
diff changeset
   841
            # rather that should be stored in the bundlestore
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   842
            opts[b'bookmark'] = []
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   843
            ui.setconfig(experimental, configscratchpush, True)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   844
            oldphasemove = extensions.wrapfunction(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   845
                exchange, b'_localphasemove', _phasemove
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   846
            )
46911
6071bfab6292 infinitepush: use the new function to determine push destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46908
diff changeset
   847
6071bfab6292 infinitepush: use the new function to determine push destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46908
diff changeset
   848
        paths = list(urlutil.get_push_paths(repo, ui, dests))
6071bfab6292 infinitepush: use the new function to determine push destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46908
diff changeset
   849
        if len(paths) > 1:
6071bfab6292 infinitepush: use the new function to determine push destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46908
diff changeset
   850
            msg = _(b'cannot push to multiple path with infinitepush')
6071bfab6292 infinitepush: use the new function to determine push destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46908
diff changeset
   851
            raise error.Abort(msg)
6071bfab6292 infinitepush: use the new function to determine push destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46908
diff changeset
   852
6071bfab6292 infinitepush: use the new function to determine push destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46908
diff changeset
   853
        path = paths[0]
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   854
        destpath = path.pushloc or path.loc
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   855
        # Remote scratch bookmarks will be deleted because remotenames doesn't
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   856
        # know about them. Let's save it before push and restore after
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   857
        remotescratchbookmarks = _readscratchremotebookmarks(ui, repo, destpath)
46911
6071bfab6292 infinitepush: use the new function to determine push destination
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46908
diff changeset
   858
        result = orig(ui, repo, *dests, **pycompat.strkwargs(opts))
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   859
        if common.isremotebooksenabled(ui):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   860
            if bookmark and scratchpush:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   861
                other = hg.peer(repo, opts, destpath)
46663
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   862
                try:
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   863
                    fetchedbookmarks = other.listkeyspatterns(
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   864
                        b'bookmarks', patterns=[bookmark]
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   865
                    )
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   866
                    remotescratchbookmarks.update(fetchedbookmarks)
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   867
                finally:
a4c19a162615 sshpeer: enable+fix warning about sshpeers not being closed explicitly
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 45942
diff changeset
   868
                    other.close()
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   869
            _saveremotebookmarks(repo, remotescratchbookmarks, destpath)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   870
    if oldphasemove:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   871
        exchange._localphasemove = oldphasemove
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   872
    return result
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   873
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   874
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   875
def _deleteinfinitepushbookmarks(ui, repo, path, names):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   876
    """Prune remote names by removing the bookmarks we don't want anymore,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   877
    then writing the result back to disk
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   878
    """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   879
    remotenamesext = extensions.find(b'remotenames')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   880
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   881
    # remotename format is:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   882
    # (node, nametype ("branches" or "bookmarks"), remote, name)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   883
    nametype_idx = 1
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   884
    remote_idx = 2
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   885
    name_idx = 3
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   886
    remotenames = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   887
        remotename
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   888
        for remotename in remotenamesext.readremotenames(repo)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   889
        if remotename[remote_idx] == path
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   890
    ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   891
    remote_bm_names = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   892
        remotename[name_idx]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   893
        for remotename in remotenames
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   894
        if remotename[nametype_idx] == b"bookmarks"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   895
    ]
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   896
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   897
    for name in names:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   898
        if name not in remote_bm_names:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   899
            raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   900
                _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   901
                    b"infinitepush bookmark '{}' does not exist "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   902
                    b"in path '{}'"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   903
                ).format(name, path)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   904
            )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   905
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   906
    bookmarks = {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   907
    branches = collections.defaultdict(list)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   908
    for node, nametype, remote, name in remotenames:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   909
        if nametype == b"bookmarks" and name not in names:
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   910
            bookmarks[name] = node
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   911
        elif nametype == b"branches":
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   912
            # saveremotenames wants binary nodes for branches
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   913
            branches[name].append(bin(node))
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   914
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   915
    remotenamesext.saveremotenames(repo, path, branches, bookmarks)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   916
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   917
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   918
def _phasemove(orig, pushop, nodes, phase=phases.public):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   919
    """prevent commits from being marked public
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   920
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   921
    Since these are going to a scratch branch, they aren't really being
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   922
    published."""
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   923
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   924
    if phase != phases.public:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   925
        orig(pushop, nodes, phase)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   926
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   927
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   928
@exchange.b2partsgenerator(scratchbranchparttype)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   929
def partgen(pushop, bundler):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   930
    bookmark = pushop.ui.config(experimental, configbookmark)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   931
    scratchpush = pushop.ui.configbool(experimental, configscratchpush)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   932
    if b'changesets' in pushop.stepsdone or not scratchpush:
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   933
        return
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   934
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   935
    if scratchbranchparttype not in bundle2.bundle2caps(pushop.remote):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   936
        return
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   937
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   938
    pushop.stepsdone.add(b'changesets')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   939
    if not pushop.outgoing.missing:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   940
        pushop.ui.status(_(b'no changes found\n'))
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   941
        pushop.cgresult = 0
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   942
        return
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   943
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   944
    # This parameter tells the server that the following bundle is an
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   945
    # infinitepush. This let's it switch the part processing to our infinitepush
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   946
    # code path.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   947
    bundler.addparam(b"infinitepush", b"True")
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   948
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   949
    scratchparts = bundleparts.getscratchbranchparts(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   950
        pushop.repo, pushop.remote, pushop.outgoing, pushop.ui, bookmark
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   951
    )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   952
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   953
    for scratchpart in scratchparts:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   954
        bundler.addpart(scratchpart)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   955
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   956
    def handlereply(op):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   957
        # server either succeeds or aborts; no code to read
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   958
        pushop.cgresult = 1
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   959
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   960
    return handlereply
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   961
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   962
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   963
bundle2.capabilities[bundleparts.scratchbranchparttype] = ()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   964
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   965
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   966
def _getrevs(bundle, oldnode, force, bookmark):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   967
    b'extracts and validates the revs to be imported'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   968
    revs = [bundle[r] for r in bundle.revs(b'sort(bundle())')]
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   969
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   970
    # new bookmark
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   971
    if oldnode is None:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   972
        return revs
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   973
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   974
    # Fast forward update
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   975
    if oldnode in bundle and list(bundle.set(b'bundle() & %s::', oldnode)):
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   976
        return revs
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   977
37203
f083e7fd6313 infinitepush: delete the non-forward-move flag for hg push
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37202
diff changeset
   978
    return revs
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   979
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   980
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   981
@contextlib.contextmanager
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   982
def logservicecall(logger, service, **kwargs):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   983
    start = time.time()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   984
    logger(service, eventtype=b'start', **kwargs)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   985
    try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   986
        yield
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   987
        logger(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   988
            service,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   989
            eventtype=b'success',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   990
            elapsedms=(time.time() - start) * 1000,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   991
            **kwargs
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   992
        )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   993
    except Exception as e:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   994
        logger(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   995
            service,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   996
            eventtype=b'failure',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   997
            elapsedms=(time.time() - start) * 1000,
43363
2ded39ef5bf7 py3: fix exception message encoding in infinitepush
Emmanuel Leblond <emmanuel.leblond@gmail.com>
parents: 43111
diff changeset
   998
            errormsg=stringutil.forcebytestr(e),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   999
            **kwargs
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1000
        )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1001
        raise
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1002
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1003
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1004
def _getorcreateinfinitepushlogger(op):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1005
    logger = op.records[b'infinitepushlogger']
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1006
    if not logger:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1007
        ui = op.repo.ui
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1008
        try:
37204
0d6c12668691 inifnitepush: use utils.{stringutil|procutil}.* instead of util.*
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37203
diff changeset
  1009
            username = procutil.getuser()
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1010
        except Exception:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1011
            username = b'unknown'
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1012
        # Generate random request id to be able to find all logged entries
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1013
        # for the same request. Since requestid is pseudo-generated it may
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1014
        # not be unique, but we assume that (hostname, username, requestid)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1015
        # is unique.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1016
        random.seed()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1017
        requestid = random.randint(0, 2000000000)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1018
        hostname = socket.gethostname()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1019
        logger = functools.partial(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1020
            ui.log,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1021
            b'infinitepush',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1022
            user=username,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1023
            requestid=requestid,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1024
            hostname=hostname,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1025
            reponame=ui.config(b'infinitepush', b'reponame'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1026
        )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1027
        op.records.add(b'infinitepushlogger', logger)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1028
    else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1029
        logger = logger[0]
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1030
    return logger
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1031
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1032
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1033
def storetobundlestore(orig, repo, op, unbundler):
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1034
    """stores the incoming bundle coming from push command to the bundlestore
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1035
    instead of applying on the revlogs"""
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1036
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1037
    repo.ui.status(_(b"storing changesets on the bundlestore\n"))
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1038
    bundler = bundle2.bundle20(repo.ui)
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1039
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1040
    # processing each part and storing it in bundler
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1041
    with bundle2.partiterator(repo, op, unbundler) as parts:
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1042
        for part in parts:
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1043
            bundlepart = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1044
            if part.type == b'replycaps':
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1045
                # This configures the current operation to allow reply parts.
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1046
                bundle2._processpart(op, part)
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1047
            else:
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1048
                bundlepart = bundle2.bundlepart(part.type, data=part.read())
43105
649d3ac37a12 py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43089
diff changeset
  1049
                for key, value in pycompat.iteritems(part.params):
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1050
                    bundlepart.addparam(key, value)
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1051
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1052
                # Certain parts require a response
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1053
                if part.type in (b'pushkey', b'changegroup'):
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1054
                    if op.reply is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1055
                        rpart = op.reply.newpart(b'reply:%s' % part.type)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1056
                        rpart.addparam(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1057
                            b'in-reply-to', b'%d' % part.id, mandatory=False
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1058
                        )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1059
                        rpart.addparam(b'return', b'1', mandatory=False)
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1060
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1061
            op.records.add(
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1062
                part.type,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1063
                {
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1064
                    b'return': 1,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1065
                },
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1066
            )
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1067
            if bundlepart:
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1068
                bundler.addpart(bundlepart)
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1069
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1070
    # storing the bundle in the bundlestore
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1071
    buf = util.chunkbuffer(bundler.getchunks())
38164
aac4be30e250 py3: wrap tempfile.mkstemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents: 38088
diff changeset
  1072
    fd, bundlefile = pycompat.mkstemp()
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1073
    try:
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1074
        try:
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43363
diff changeset
  1075
            fp = os.fdopen(fd, 'wb')
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1076
            fp.write(buf.read())
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1077
        finally:
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1078
            fp.close()
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1079
        storebundle(op, {}, bundlefile)
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1080
    finally:
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1081
        try:
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1082
            os.unlink(bundlefile)
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1083
        except Exception:
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1084
            # we would rather see the original exception
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1085
            pass
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1086
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1087
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1088
def processparts(orig, repo, op, unbundler):
37205
e5cd0ef5c362 infinitepush: don't wrap bundle2.processparts while calling `hg unbundle`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37204
diff changeset
  1089
e5cd0ef5c362 infinitepush: don't wrap bundle2.processparts while calling `hg unbundle`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37204
diff changeset
  1090
    # make sure we don't wrap processparts in case of `hg unbundle`
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1091
    if op.source == b'unbundle':
37239
40ee0af04e3a infinitepush: use bundleoperation.source instead of hacking on tr
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37233
diff changeset
  1092
        return orig(repo, op, unbundler)
37205
e5cd0ef5c362 infinitepush: don't wrap bundle2.processparts while calling `hg unbundle`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37204
diff changeset
  1093
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1094
    # this server routes each push to bundle store
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1095
    if repo.ui.configbool(b'infinitepush', b'pushtobundlestore'):
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1096
        return storetobundlestore(orig, repo, op, unbundler)
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1097
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1098
    if unbundler.params.get(b'infinitepush') != b'True':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1099
        return orig(repo, op, unbundler)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1100
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1101
    handleallparts = repo.ui.configbool(b'infinitepush', b'storeallparts')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1102
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1103
    bundler = bundle2.bundle20(repo.ui)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1104
    cgparams = None
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1105
    with bundle2.partiterator(repo, op, unbundler) as parts:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1106
        for part in parts:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1107
            bundlepart = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1108
            if part.type == b'replycaps':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1109
                # This configures the current operation to allow reply parts.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1110
                bundle2._processpart(op, part)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1111
            elif part.type == bundleparts.scratchbranchparttype:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1112
                # Scratch branch parts need to be converted to normal
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1113
                # changegroup parts, and the extra parameters stored for later
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1114
                # when we upload to the store. Eventually those parameters will
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1115
                # be put on the actual bundle instead of this part, then we can
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1116
                # send a vanilla changegroup instead of the scratchbranch part.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1117
                cgversion = part.params.get(b'cgversion', b'01')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1118
                bundlepart = bundle2.bundlepart(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1119
                    b'changegroup', data=part.read()
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1120
                )
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1121
                bundlepart.addparam(b'version', cgversion)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1122
                cgparams = part.params
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1123
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1124
                # If we're not dumping all parts into the new bundle, we need to
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1125
                # alert the future pushkey and phase-heads handler to skip
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1126
                # the part.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1127
                if not handleallparts:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1128
                    op.records.add(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1129
                        scratchbranchparttype + b'_skippushkey', True
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1130
                    )
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1131
                    op.records.add(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1132
                        scratchbranchparttype + b'_skipphaseheads', True
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1133
                    )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1134
            else:
37197
7fa00a6f8180 infinitepush: drop logic related to treemanifest extension
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37196
diff changeset
  1135
                if handleallparts:
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1136
                    # Ideally we would not process any parts, and instead just
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1137
                    # forward them to the bundle for storage, but since this
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1138
                    # differs from previous behavior, we need to put it behind a
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1139
                    # config flag for incremental rollout.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1140
                    bundlepart = bundle2.bundlepart(part.type, data=part.read())
43105
649d3ac37a12 py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43089
diff changeset
  1141
                    for key, value in pycompat.iteritems(part.params):
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1142
                        bundlepart.addparam(key, value)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1143
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1144
                    # Certain parts require a response
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1145
                    if part.type == b'pushkey':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1146
                        if op.reply is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1147
                            rpart = op.reply.newpart(b'reply:pushkey')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1148
                            rpart.addparam(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1149
                                b'in-reply-to', str(part.id), mandatory=False
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1150
                            )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1151
                            rpart.addparam(b'return', b'1', mandatory=False)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1152
                else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1153
                    bundle2._processpart(op, part)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1154
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1155
            if handleallparts:
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1156
                op.records.add(
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1157
                    part.type,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1158
                    {
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1159
                        b'return': 1,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1160
                    },
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1161
                )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1162
            if bundlepart:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1163
                bundler.addpart(bundlepart)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1164
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1165
    # If commits were sent, store them
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1166
    if cgparams:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1167
        buf = util.chunkbuffer(bundler.getchunks())
38164
aac4be30e250 py3: wrap tempfile.mkstemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents: 38088
diff changeset
  1168
        fd, bundlefile = pycompat.mkstemp()
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1169
        try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1170
            try:
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43363
diff changeset
  1171
                fp = os.fdopen(fd, 'wb')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1172
                fp.write(buf.read())
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1173
            finally:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1174
                fp.close()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1175
            storebundle(op, cgparams, bundlefile)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1176
        finally:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1177
            try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1178
                os.unlink(bundlefile)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1179
            except Exception:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1180
                # we would rather see the original exception
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1181
                pass
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1182
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1183
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1184
def storebundle(op, params, bundlefile):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1185
    log = _getorcreateinfinitepushlogger(op)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1186
    parthandlerstart = time.time()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1187
    log(scratchbranchparttype, eventtype=b'start')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1188
    index = op.repo.bundlestore.index
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1189
    store = op.repo.bundlestore.store
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1190
    op.records.add(scratchbranchparttype + b'_skippushkey', True)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1191
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1192
    bundle = None
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1193
    try:  # guards bundle
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1194
        bundlepath = b"bundle:%s+%s" % (op.repo.root, bundlefile)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1195
        bundle = hg.repository(op.repo.ui, bundlepath)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1196
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1197
        bookmark = params.get(b'bookmark')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1198
        bookprevnode = params.get(b'bookprevnode', b'')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1199
        force = params.get(b'force')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1200
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1201
        if bookmark:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1202
            oldnode = index.getnode(bookmark)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1203
        else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1204
            oldnode = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1205
        bundleheads = bundle.revs(b'heads(bundle())')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1206
        if bookmark and len(bundleheads) > 1:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1207
            raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1208
                _(b'cannot push more than one head to a scratch branch')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1209
            )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1210
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1211
        revs = _getrevs(bundle, oldnode, force, bookmark)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1212
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1213
        # Notify the user of what is being pushed
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1214
        plural = b's' if len(revs) > 1 else b''
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1215
        op.repo.ui.warn(_(b"pushing %d commit%s:\n") % (len(revs), plural))
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1216
        maxoutput = 10
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1217
        for i in range(0, min(len(revs), maxoutput)):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1218
            firstline = bundle[revs[i]].description().split(b'\n')[0][:50]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1219
            op.repo.ui.warn(b"    %s  %s\n" % (revs[i], firstline))
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1220
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1221
        if len(revs) > maxoutput + 1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1222
            op.repo.ui.warn(b"    ...\n")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1223
            firstline = bundle[revs[-1]].description().split(b'\n')[0][:50]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1224
            op.repo.ui.warn(b"    %s  %s\n" % (revs[-1], firstline))
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1225
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1226
        nodesctx = [bundle[rev] for rev in revs]
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1227
        inindex = lambda rev: bool(index.getbundle(bundle[rev].hex()))
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1228
        if bundleheads:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1229
            newheadscount = sum(not inindex(rev) for rev in bundleheads)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1230
        else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1231
            newheadscount = 0
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1232
        # If there's a bookmark specified, there should be only one head,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1233
        # so we choose the last node, which will be that head.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1234
        # If a bug or malicious client allows there to be a bookmark
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1235
        # with multiple heads, we will place the bookmark on the last head.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1236
        bookmarknode = nodesctx[-1].hex() if nodesctx else None
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1237
        key = None
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1238
        if newheadscount:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1239
            with open(bundlefile, b'rb') as f:
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1240
                bundledata = f.read()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1241
                with logservicecall(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1242
                    log, b'bundlestore', bundlesize=len(bundledata)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1243
                ):
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1244
                    bundlesizelimit = 100 * 1024 * 1024  # 100 MB
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1245
                    if len(bundledata) > bundlesizelimit:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1246
                        error_msg = (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1247
                            b'bundle is too big: %d bytes. '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1248
                            + b'max allowed size is 100 MB'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1249
                        )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1250
                        raise error.Abort(error_msg % (len(bundledata),))
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1251
                    key = store.write(bundledata)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1252
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1253
        with logservicecall(log, b'index', newheadscount=newheadscount), index:
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1254
            if key:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1255
                index.addbundle(key, nodesctx)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1256
            if bookmark:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1257
                index.addbookmark(bookmark, bookmarknode)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1258
                _maybeaddpushbackpart(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1259
                    op, bookmark, bookmarknode, bookprevnode, params
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1260
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1261
        log(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1262
            scratchbranchparttype,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1263
            eventtype=b'success',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1264
            elapsedms=(time.time() - parthandlerstart) * 1000,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1265
        )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1266
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1267
    except Exception as e:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1268
        log(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1269
            scratchbranchparttype,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1270
            eventtype=b'failure',
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1271
            elapsedms=(time.time() - parthandlerstart) * 1000,
43363
2ded39ef5bf7 py3: fix exception message encoding in infinitepush
Emmanuel Leblond <emmanuel.leblond@gmail.com>
parents: 43111
diff changeset
  1272
            errormsg=stringutil.forcebytestr(e),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1273
        )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1274
        raise
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1275
    finally:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1276
        if bundle:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1277
            bundle.close()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1278
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1279
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1280
@bundle2.parthandler(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1281
    scratchbranchparttype,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1282
    (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1283
        b'bookmark',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1284
        b'bookprevnode',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1285
        b'force',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1286
        b'pushbackbookmarks',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1287
        b'cgversion',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1288
    ),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1289
)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1290
def bundle2scratchbranch(op, part):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1291
    '''unbundle a bundle2 part containing a changegroup to store'''
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1292
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1293
    bundler = bundle2.bundle20(op.repo.ui)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1294
    cgversion = part.params.get(b'cgversion', b'01')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1295
    cgpart = bundle2.bundlepart(b'changegroup', data=part.read())
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1296
    cgpart.addparam(b'version', cgversion)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1297
    bundler.addpart(cgpart)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1298
    buf = util.chunkbuffer(bundler.getchunks())
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1299
38164
aac4be30e250 py3: wrap tempfile.mkstemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents: 38088
diff changeset
  1300
    fd, bundlefile = pycompat.mkstemp()
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1301
    try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1302
        try:
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43363
diff changeset
  1303
            fp = os.fdopen(fd, 'wb')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1304
            fp.write(buf.read())
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1305
        finally:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1306
            fp.close()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1307
        storebundle(op, part.params, bundlefile)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1308
    finally:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1309
        try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1310
            os.unlink(bundlefile)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1311
        except OSError as e:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1312
            if e.errno != errno.ENOENT:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1313
                raise
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1314
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1315
    return 1
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1316
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1317
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1318
def _maybeaddpushbackpart(op, bookmark, newnode, oldnode, params):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1319
    if params.get(b'pushbackbookmarks'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1320
        if op.reply and b'pushback' in op.reply.capabilities:
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1321
            params = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1322
                b'namespace': b'bookmarks',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1323
                b'key': bookmark,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1324
                b'new': newnode,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1325
                b'old': oldnode,
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1326
            }
43105
649d3ac37a12 py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43089
diff changeset
  1327
            op.reply.newpart(
649d3ac37a12 py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43089
diff changeset
  1328
                b'pushkey', mandatoryparams=pycompat.iteritems(params)
649d3ac37a12 py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43089
diff changeset
  1329
            )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1330
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1331
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1332
def bundle2pushkey(orig, op, part):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1333
    """Wrapper of bundle2.handlepushkey()
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1334
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1335
    The only goal is to skip calling the original function if flag is set.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1336
    It's set if infinitepush push is happening.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1337
    """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1338
    if op.records[scratchbranchparttype + b'_skippushkey']:
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1339
        if op.reply is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1340
            rpart = op.reply.newpart(b'reply:pushkey')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1341
            rpart.addparam(b'in-reply-to', str(part.id), mandatory=False)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1342
            rpart.addparam(b'return', b'1', mandatory=False)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1343
        return 1
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1344
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1345
    return orig(op, part)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1346
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1347
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1348
def bundle2handlephases(orig, op, part):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1349
    """Wrapper of bundle2.handlephases()
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1350
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1351
    The only goal is to skip calling the original function if flag is set.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1352
    It's set if infinitepush push is happening.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1353
    """
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1354
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1355
    if op.records[scratchbranchparttype + b'_skipphaseheads']:
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1356
        return
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1357
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1358
    return orig(op, part)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1359
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1360
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1361
def _asyncsavemetadata(root, nodes):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1362
    """starts a separate process that fills metadata for the nodes
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1363
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1364
    This function creates a separate process and doesn't wait for it's
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1365
    completion. This was done to avoid slowing down pushes
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45144
diff changeset
  1366
    """
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1367
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1368
    maxnodes = 50
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1369
    if len(nodes) > maxnodes:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1370
        return
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1371
    nodesargs = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1372
    for node in nodes:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1373
        nodesargs.append(b'--node')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1374
        nodesargs.append(node)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1375
    with open(os.devnull, b'w+b') as devnull:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1376
        cmdline = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1377
            util.hgexecutable(),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1378
            b'debugfillinfinitepushmetadata',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1379
            b'-R',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1380
            root,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1381
        ] + nodesargs
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1382
        # Process will run in background. We don't care about the return code
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1383
        subprocess.Popen(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1384
            pycompat.rapply(procutil.tonativestr, cmdline),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1385
            close_fds=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1386
            shell=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1387
            stdin=devnull,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1388
            stdout=devnull,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1389
            stderr=devnull,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1390
        )