hgext/infinitepush/__init__.py
author Gregory Szorc <gregory.szorc@gmail.com>
Sun, 06 Oct 2019 16:55:18 -0400
changeset 43089 c59eb1560c44
parent 43085 eef9a2d67051
child 43105 649d3ac37a12
permissions -rw-r--r--
py3: manually import getattr where it is needed The march continues. Differential Revision: https://phab.mercurial-scm.org/D7009
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
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
     9
    [infinitepush]
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    10
    # 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
    11
    branchpattern = PATTERN
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    12
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    13
    # Server or client
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    14
    server = False
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    15
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    16
    # 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
    17
    indextype = disk
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    18
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    19
    # 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
    20
    # 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
    21
    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
    22
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    23
    # 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
    24
    # Filesystem path to the index store
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    25
    indexpath = PATH
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    26
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    27
    # 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
    28
    # Fails if not set
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    29
    storetype = disk
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    30
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    31
    # Server-side option.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    32
    # 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
    33
    # 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
    34
    put_binary = put
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
    # 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
    37
    # 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
    38
    put_args = {filename}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    39
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    40
    # Server-side option.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    41
    # 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
    42
    # 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
    43
    get_binary = get
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
    # 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
    46
    # 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
    47
    get_args = {filename} {handle}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    48
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    49
    # Server-side option
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    50
    logfile = FIlE
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    51
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    52
    # Server-side option
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    53
    loglevel = DEBUG
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    54
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    55
    # 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
    56
    # Sets mysql wait_timeout option.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    57
    waittimeout = 300
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    58
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    59
    # 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
    60
    # 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
    61
    locktimeout = 120
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    62
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    63
    # 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
    64
    # Name of the repository
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    65
    reponame = ''
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    66
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    67
    # 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
    68
    # 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
    69
    defaultremotepatterns = ['*']
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    70
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    71
    # 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
    72
    # bundle for storage. Defaults to False.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    73
    storeallparts = True
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    74
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
    75
    # 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
    76
    pushtobundlestore = True
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
    77
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    78
    [remotenames]
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    79
    # Client-side option
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    80
    # 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
    81
    # 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
    82
    bookmarks = True
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    83
"""
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    84
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    85
from __future__ import absolute_import
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    86
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    87
import collections
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    88
import contextlib
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    89
import errno
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    90
import functools
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    91
import logging
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    92
import os
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    93
import random
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    94
import re
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    95
import socket
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    96
import subprocess
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    97
import time
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    98
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
    99
from mercurial.node import (
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   100
    bin,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   101
    hex,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   102
)
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.i18n import _
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   105
43089
c59eb1560c44 py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43085
diff changeset
   106
from mercurial.pycompat import (
c59eb1560c44 py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43085
diff changeset
   107
    getattr,
c59eb1560c44 py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43085
diff changeset
   108
    open,
c59eb1560c44 py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43085
diff changeset
   109
)
43085
eef9a2d67051 py3: manually import pycompat.open into files that need it
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
   110
37204
0d6c12668691 inifnitepush: use utils.{stringutil|procutil}.* instead of util.*
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37203
diff changeset
   111
from mercurial.utils import (
0d6c12668691 inifnitepush: use utils.{stringutil|procutil}.* instead of util.*
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37203
diff changeset
   112
    procutil,
0d6c12668691 inifnitepush: use utils.{stringutil|procutil}.* instead of util.*
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37203
diff changeset
   113
    stringutil,
0d6c12668691 inifnitepush: use utils.{stringutil|procutil}.* instead of util.*
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37203
diff changeset
   114
)
0d6c12668691 inifnitepush: use utils.{stringutil|procutil}.* instead of util.*
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37203
diff changeset
   115
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   116
from mercurial import (
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   117
    bundle2,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   118
    changegroup,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   119
    commands,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   120
    discovery,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   121
    encoding,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   122
    error,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   123
    exchange,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   124
    extensions,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   125
    hg,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   126
    localrepo,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   127
    phases,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   128
    pushkey,
37577
e7eea8582afa py3: use pycompat.{strkwargs|byteskwargs} in infinitepush
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37239
diff changeset
   129
    pycompat,
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   130
    registrar,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   131
    util,
37612
5e71dea79aae wireproto: move value encoding functions to wireprototypes (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37579
diff changeset
   132
    wireprototypes,
37614
a81d02ea65db wireproto: move version 1 peer functionality to standalone module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   133
    wireprotov1peer,
37785
b4d85bc122bd wireproto: rename wireproto to wireprotov1server (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37615
diff changeset
   134
    wireprotov1server,
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   135
)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   136
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   137
from . import (
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   138
    bundleparts,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   139
    common,
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   140
)
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
# 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
   143
# 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
   144
# 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
   145
# leave the attribute unspecified.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   146
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
   147
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   148
configtable = {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   149
configitem = registrar.configitem(configtable)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   150
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   151
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   152
    b'infinitepush', b'server', default=False,
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   153
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   154
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   155
    b'infinitepush', b'storetype', default=b'',
37187
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(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   158
    b'infinitepush', b'indextype', default=b'',
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   159
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   160
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   161
    b'infinitepush', b'indexpath', default=b'',
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   162
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   163
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   164
    b'infinitepush', b'storeallparts', default=False,
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   165
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   166
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   167
    b'infinitepush', b'reponame', default=b'',
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   168
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   169
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   170
    b'scratchbranch', b'storepath', 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(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   173
    b'infinitepush', b'branchpattern', default=b'',
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   174
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   175
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   176
    b'infinitepush', b'pushtobundlestore', default=False,
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
   177
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   178
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   179
    b'experimental', b'server-bundlestore-bookmark', default=b'',
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   180
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   181
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   182
    b'experimental', b'infinitepush-scratchpush', default=False,
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   183
)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   184
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   185
experimental = b'experimental'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   186
configbookmark = b'server-bundlestore-bookmark'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   187
configscratchpush = b'infinitepush-scratchpush'
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   188
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   189
scratchbranchparttype = bundleparts.scratchbranchparttype
37188
de4c2f3af97f infinitepush: remove backupcommands.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37187
diff changeset
   190
revsetpredicate = registrar.revsetpredicate()
de4c2f3af97f infinitepush: remove backupcommands.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37187
diff changeset
   191
templatekeyword = registrar.templatekeyword()
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   192
_scratchbranchmatcher = lambda x: False
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   193
_maybehash = re.compile(r'^[a-f0-9]+$').search
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   194
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   195
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   196
def _buildexternalbundlestore(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   197
    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
   198
    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
   199
    if not put_binary:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   200
        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
   201
    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
   202
    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
   203
    if not get_binary:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   204
        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
   205
    from . import store
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   206
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   207
    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
   208
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   209
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   210
def _buildsqlindex(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   211
    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
   212
    if not sqlhost:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   213
        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
   214
    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
   215
    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
   216
    if not reponame:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   217
        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
   218
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   219
    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
   220
    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
   221
    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
   222
    from . import sqlindexapi
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
    return sqlindexapi.sqlindexapi(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   225
        reponame,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   226
        host,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   227
        port,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   228
        db,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   229
        user,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   230
        password,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   231
        logfile,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   232
        _getloglevel(ui),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   233
        waittimeout=waittimeout,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   234
        locktimeout=locktimeout,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   235
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   236
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   237
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   238
def _getloglevel(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   239
    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
   240
    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
   241
    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
   242
        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
   243
    return numeric_loglevel
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   244
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   245
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   246
def _tryhoist(ui, remotebookmark):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   247
    '''returns a bookmarks with hoisted part removed
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   248
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   249
    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
   250
    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
   251
    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
   252
    infinitepush.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   253
    '''
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   254
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   255
    if common.isremotebooksenabled(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   256
        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
   257
        if remotebookmark.startswith(hoist):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   258
            return remotebookmark[len(hoist) :]
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   259
    return remotebookmark
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   260
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   261
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   262
class bundlestore(object):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   263
    def __init__(self, repo):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   264
        self._repo = repo
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   265
        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
   266
        if storetype == b'disk':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   267
            from . import store
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   268
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   269
            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
   270
        elif storetype == b'external':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   271
            self.store = _buildexternalbundlestore(self._repo.ui)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   272
        else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   273
            raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   274
                _(b'unknown infinitepush store type specified %s') % storetype
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   275
            )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   276
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   277
        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
   278
        if indextype == b'disk':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   279
            from . import fileindexapi
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   280
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   281
            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
   282
        elif indextype == b'sql':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   283
            self.index = _buildsqlindex(self._repo.ui)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   284
        else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   285
            raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   286
                _(b'unknown infinitepush index type specified %s') % indextype
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   287
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   288
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   289
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   290
def _isserver(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   291
    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
   292
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   293
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   294
def reposetup(ui, repo):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   295
    if _isserver(ui) and repo.local():
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   296
        repo.bundlestore = bundlestore(repo)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   297
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   298
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   299
def extsetup(ui):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   300
    commonsetup(ui)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   301
    if _isserver(ui):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   302
        serverextsetup(ui)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   303
    else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   304
        clientextsetup(ui)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   305
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   306
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   307
def commonsetup(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   308
    wireprotov1server.commands[b'listkeyspatterns'] = (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   309
        wireprotolistkeyspatterns,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   310
        b'namespace patterns',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   311
    )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   312
    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
   313
    if scratchbranchpat:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   314
        global _scratchbranchmatcher
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   315
        kind, pat, _scratchbranchmatcher = stringutil.stringmatcher(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   316
            scratchbranchpat
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   317
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   318
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   319
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   320
def serverextsetup(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   321
    origpushkeyhandler = bundle2.parthandlermapping[b'pushkey']
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   322
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   323
    def newpushkeyhandler(*args, **kwargs):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   324
        bundle2pushkey(origpushkeyhandler, *args, **kwargs)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   325
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   326
    newpushkeyhandler.params = origpushkeyhandler.params
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   327
    bundle2.parthandlermapping[b'pushkey'] = newpushkeyhandler
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   328
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   329
    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
   330
    newphaseheadshandler = lambda *args, **kwargs: bundle2handlephases(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   331
        orighandlephasehandler, *args, **kwargs
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   332
    )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   333
    newphaseheadshandler.params = orighandlephasehandler.params
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   334
    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
   335
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   336
    extensions.wrapfunction(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   337
        localrepo.localrepository, b'listkeys', localrepolistkeys
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   338
    )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   339
    wireprotov1server.commands[b'lookup'] = (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   340
        _lookupwrap(wireprotov1server.commands[b'lookup'][0]),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   341
        b'key',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   342
    )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   343
    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
   344
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   345
    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
   346
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   347
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   348
def clientextsetup(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   349
    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
   350
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   351
    entry[1].append(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   352
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   353
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   354
            b'bundle-store',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   355
            None,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   356
            _(b'force push to go to bundle store (EXPERIMENTAL)'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   357
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   358
    )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   359
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   360
    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
   361
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   362
    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
   363
37614
a81d02ea65db wireproto: move version 1 peer functionality to standalone module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37612
diff changeset
   364
    wireprotov1peer.wirepeer.listkeyspatterns = listkeyspatterns
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   365
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   366
    partorder = exchange.b2partsgenorder
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   367
    index = partorder.index(b'changeset')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   368
    partorder.insert(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   369
        index, partorder.pop(partorder.index(scratchbranchparttype))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   370
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   371
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   372
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   373
def _checkheads(orig, pushop):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   374
    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
   375
        return
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   376
    return orig(pushop)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   377
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   378
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   379
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
   380
    patterns = wireprototypes.decodelist(patterns)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   381
    d = repo.listkeys(encoding.tolocal(namespace), patterns).iteritems()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   382
    return pushkey.encodekeys(d)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   383
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   384
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   385
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
   386
    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
   387
        index = self.bundlestore.index
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   388
        results = {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   389
        bookmarks = orig(self, namespace)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   390
        for pattern in patterns:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   391
            results.update(index.getbookmarks(pattern))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   392
            if pattern.endswith(b'*'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   393
                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
   394
            kind, pat, matcher = stringutil.stringmatcher(pattern)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   395
            for bookmark, node in bookmarks.iteritems():
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   396
                if matcher(bookmark):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   397
                    results[bookmark] = node
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   398
        return results
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   399
    else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   400
        return orig(self, namespace)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   401
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   402
37615
f3dc8239e3a9 peer: scatter module to the wind (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37614
diff changeset
   403
@wireprotov1peer.batchable
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   404
def listkeyspatterns(self, namespace, patterns):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   405
    if not self.capable(b'pushkey'):
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   406
        yield {}, None
37615
f3dc8239e3a9 peer: scatter module to the wind (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37614
diff changeset
   407
    f = wireprotov1peer.future()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   408
    self.ui.debug(b'preparing listkeys for "%s"\n' % namespace)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   409
    yield {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   410
        b'namespace': encoding.fromlocal(namespace),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   411
        b'patterns': wireprototypes.encodelist(patterns),
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   412
    }, f
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   413
    d = f.value
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   414
    self.ui.debug(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   415
        b'received listkey for "%s": %i bytes\n' % (namespace, len(d))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   416
    )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   417
    yield pushkey.decodekeys(d)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   418
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   419
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   420
def _readbundlerevs(bundlerepo):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   421
    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
   422
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   423
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   424
def _includefilelogstobundle(bundlecaps, bundlerepo, bundlerevs, ui):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   425
    '''Tells remotefilelog to include all changed files to the changegroup
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   426
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   427
    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
   428
    But we need to include it if we are fetching from bundlestore.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   429
    '''
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   430
    changedfiles = set()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   431
    cl = bundlerepo.changelog
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   432
    for r in bundlerevs:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   433
        # [3] means changed files
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   434
        changedfiles.update(cl.read(r)[3])
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   435
    if not changedfiles:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   436
        return bundlecaps
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   437
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   438
    changedfiles = b'\0'.join(changedfiles)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   439
    newcaps = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   440
    appended = False
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   441
    for cap in bundlecaps or []:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   442
        if cap.startswith(b'excludepattern='):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   443
            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
   444
            appended = True
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   445
        else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   446
            newcaps.append(cap)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   447
    if not appended:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   448
        # 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
   449
        newcaps.append(b'excludepattern=' + changedfiles)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   450
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   451
    return newcaps
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   452
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   453
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   454
def _rebundle(bundlerepo, bundleroots, unknownhead):
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
    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
   457
    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
   458
    This function will filter out all revision that user is not requested.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   459
    '''
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   460
    parts = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   461
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   462
    version = b'02'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   463
    outgoing = discovery.outgoing(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   464
        bundlerepo, commonheads=bundleroots, missingheads=[unknownhead]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   465
    )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   466
    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
   467
    cgstream = util.chunkbuffer(cgstream).read()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   468
    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
   469
    cgpart.addparam(b'version', version)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   470
    parts.append(cgpart)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   471
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   472
    return parts
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   473
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   474
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   475
def _getbundleroots(oldrepo, bundlerepo, bundlerevs):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   476
    cl = bundlerepo.changelog
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   477
    bundleroots = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   478
    for rev in bundlerevs:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   479
        node = cl.node(rev)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   480
        parents = cl.parents(node)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   481
        for parent in parents:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   482
            # 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
   483
            # 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
   484
            if parent in oldrepo:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   485
                bundleroots.append(parent)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   486
    return bundleroots
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   487
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   488
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   489
def _needsrebundling(head, bundlerepo):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   490
    bundleheads = list(bundlerepo.revs(b'heads(bundle())'))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   491
    return not (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   492
        len(bundleheads) == 1 and bundlerepo[bundleheads[0]].node() == head
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   493
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   494
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   495
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   496
def _generateoutputparts(head, bundlerepo, bundleroots, bundlefile):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   497
    '''generates bundle that will be send to the user
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   498
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   499
    returns tuple with raw bundle string and bundle type
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
    parts = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   502
    if not _needsrebundling(head, bundlerepo):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   503
        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
   504
            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
   505
            if isinstance(unbundler, changegroup.cg1unpacker):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   506
                part = bundle2.bundlepart(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   507
                    b'changegroup', data=unbundler._stream.read()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   508
                )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   509
                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
   510
                parts.append(part)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   511
            elif isinstance(unbundler, bundle2.unbundle20):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   512
                haschangegroup = False
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   513
                for part in unbundler.iterparts():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   514
                    if part.type == b'changegroup':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   515
                        haschangegroup = True
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   516
                    newpart = bundle2.bundlepart(part.type, data=part.read())
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   517
                    for key, value in part.params.iteritems():
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   518
                        newpart.addparam(key, value)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   519
                    parts.append(newpart)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   520
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   521
                if not haschangegroup:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   522
                    raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   523
                        b'unexpected bundle without changegroup part, '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   524
                        + b'head: %s' % hex(head),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   525
                        hint=b'report to administrator',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   526
                    )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   527
            else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   528
                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
   529
    else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   530
        parts = _rebundle(bundlerepo, bundleroots, head)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   531
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   532
    return parts
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   533
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   534
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   535
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
   536
    heads = heads or []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   537
    # 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
   538
    newphases = {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   539
    scratchbundles = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   540
    newheads = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   541
    scratchheads = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   542
    nodestobundle = {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   543
    allbundlestocleanup = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   544
    try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   545
        for head in heads:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   546
            if head not in repo.changelog.nodemap:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   547
                if head not in nodestobundle:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   548
                    newbundlefile = common.downloadbundle(repo, head)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   549
                    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
   550
                    bundlerepo = hg.repository(repo.ui, bundlepath)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   551
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   552
                    allbundlestocleanup.append((bundlerepo, newbundlefile))
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   553
                    bundlerevs = set(_readbundlerevs(bundlerepo))
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   554
                    bundlecaps = _includefilelogstobundle(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   555
                        bundlecaps, bundlerepo, bundlerevs, repo.ui
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   556
                    )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   557
                    cl = bundlerepo.changelog
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   558
                    bundleroots = _getbundleroots(repo, bundlerepo, bundlerevs)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   559
                    for rev in bundlerevs:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   560
                        node = cl.node(rev)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   561
                        newphases[hex(node)] = str(phases.draft)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   562
                        nodestobundle[node] = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   563
                            bundlerepo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   564
                            bundleroots,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   565
                            newbundlefile,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   566
                        )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   567
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   568
                scratchbundles.append(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   569
                    _generateoutputparts(head, *nodestobundle[head])
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   570
                )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   571
                newheads.extend(bundleroots)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   572
                scratchheads.append(head)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   573
    finally:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   574
        for bundlerepo, bundlefile in allbundlestocleanup:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   575
            bundlerepo.close()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   576
            try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   577
                os.unlink(bundlefile)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   578
            except (IOError, OSError):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   579
                # 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
   580
                # no need to fail
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   581
                pass
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   582
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   583
    pullfrombundlestore = bool(scratchbundles)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   584
    wrappedchangegrouppart = False
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   585
    wrappedlistkeys = False
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   586
    oldchangegrouppart = exchange.getbundle2partsmapping[b'changegroup']
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   587
    try:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   588
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   589
        def _changegrouppart(bundler, *args, **kwargs):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   590
            # 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
   591
            # 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
   592
            # 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
   593
            result = oldchangegrouppart(bundler, *args, **kwargs)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   594
            for bundle in scratchbundles:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   595
                for part in bundle:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   596
                    bundler.addpart(part)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   597
            return result
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   598
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   599
        exchange.getbundle2partsmapping[b'changegroup'] = _changegrouppart
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   600
        wrappedchangegrouppart = True
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   601
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   602
        def _listkeys(orig, self, namespace):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   603
            origvalues = orig(self, namespace)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   604
            if namespace == b'phases' and pullfrombundlestore:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   605
                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
   606
                    # 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
   607
                    del origvalues[b'publishing']
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   608
                origvalues.update(newphases)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   609
            return origvalues
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   610
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   611
        extensions.wrapfunction(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   612
            localrepo.localrepository, b'listkeys', _listkeys
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   613
        )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   614
        wrappedlistkeys = True
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   615
        heads = list((set(newheads) | set(heads)) - set(scratchheads))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   616
        result = orig(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   617
            repo, source, heads=heads, bundlecaps=bundlecaps, **kwargs
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   618
        )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   619
    finally:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   620
        if wrappedchangegrouppart:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   621
            exchange.getbundle2partsmapping[b'changegroup'] = oldchangegrouppart
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   622
        if wrappedlistkeys:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   623
            extensions.unwrapfunction(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   624
                localrepo.localrepository, b'listkeys', _listkeys
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   625
            )
37187
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
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   628
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   629
def _lookupwrap(orig):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   630
    def _lookup(repo, proto, key):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   631
        localkey = encoding.tolocal(key)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   632
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   633
        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
   634
            scratchnode = repo.bundlestore.index.getnode(localkey)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   635
            if scratchnode:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   636
                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
   637
            else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   638
                return b"%d %s\n" % (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   639
                    0,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   640
                    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
   641
                )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   642
        else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   643
            try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   644
                r = hex(repo.lookup(localkey))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   645
                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
   646
            except Exception as inst:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   647
                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
   648
                    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
   649
                else:
38083
5f2dc1b71cf1 py3: use utils.stringutil.forcebytestr to convert error to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38067
diff changeset
   650
                    r = stringutil.forcebytestr(inst)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   651
                    return b"%d %s\n" % (0, r)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   652
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   653
    return _lookup
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   654
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   655
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   656
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
   657
    opts = pycompat.byteskwargs(opts)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   658
    # Copy paste from `pull` command
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   659
    source, branches = hg.parseurl(ui.expandpath(source), opts.get(b'branch'))
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   660
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   661
    scratchbookmarks = {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   662
    unfi = repo.unfiltered()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   663
    unknownnodes = []
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   664
    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
   665
        if rev not in unfi:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   666
            unknownnodes.append(rev)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   667
    if opts.get(b'bookmark'):
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   668
        bookmarks = []
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   669
        revs = opts.get(b'rev') or []
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   670
        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
   671
            if _scratchbranchmatcher(bookmark):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   672
                # rev is not known yet
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   673
                # 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
   674
                scratchbookmarks[bookmark] = b'REVTOFETCH'
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   675
            else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   676
                bookmarks.append(bookmark)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   677
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   678
        if scratchbookmarks:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   679
            other = hg.peer(repo, opts, source)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   680
            fetchedbookmarks = other.listkeyspatterns(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   681
                b'bookmarks', patterns=scratchbookmarks
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   682
            )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   683
            for bookmark in scratchbookmarks:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   684
                if bookmark not in fetchedbookmarks:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   685
                    raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   686
                        b'remote bookmark %s not found!' % bookmark
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   687
                    )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   688
                scratchbookmarks[bookmark] = fetchedbookmarks[bookmark]
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   689
                revs.append(fetchedbookmarks[bookmark])
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   690
        opts[b'bookmark'] = bookmarks
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   691
        opts[b'rev'] = revs
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   692
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   693
    if scratchbookmarks or unknownnodes:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   694
        # Set anyincoming to True
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   695
        extensions.wrapfunction(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   696
            discovery, b'findcommonincoming', _findcommonincoming
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   697
        )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   698
    try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   699
        # 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
   700
        # 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
   701
        remotescratchbookmarks = _readscratchremotebookmarks(ui, repo, source)
37577
e7eea8582afa py3: use pycompat.{strkwargs|byteskwargs} in infinitepush
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37239
diff changeset
   702
        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
   703
        # TODO(stash): race condition is possible
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   704
        # 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
   705
        # 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
   706
        if common.isremotebooksenabled(ui):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   707
            remotescratchbookmarks.update(scratchbookmarks)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   708
            _saveremotebookmarks(repo, remotescratchbookmarks, source)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   709
        else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   710
            _savelocalbookmarks(repo, scratchbookmarks)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   711
        return result
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   712
    finally:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   713
        if scratchbookmarks:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   714
            extensions.unwrapfunction(discovery, b'findcommonincoming')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   715
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   716
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   717
def _readscratchremotebookmarks(ui, repo, other):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   718
    if common.isremotebooksenabled(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   719
        remotenamesext = extensions.find(b'remotenames')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   720
        remotepath = remotenamesext.activepath(repo.ui, other)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   721
        result = {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   722
        # 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
   723
        # 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
   724
        # 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
   725
        # fix it is to use `clearnames()`
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   726
        repo._remotenames.clearnames()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   727
        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
   728
            path, bookname = remotenamesext.splitremotename(remotebookmark)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   729
            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
   730
                nodes = repo.names[b'remotebookmarks'].nodes(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   731
                    repo, remotebookmark
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   732
                )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   733
                if nodes:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   734
                    result[bookname] = hex(nodes[0])
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   735
        return result
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   736
    else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   737
        return {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   738
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   739
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   740
def _saveremotebookmarks(repo, newbookmarks, remote):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   741
    remotenamesext = extensions.find(b'remotenames')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   742
    remotepath = remotenamesext.activepath(repo.ui, remote)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   743
    branches = collections.defaultdict(list)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   744
    bookmarks = {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   745
    remotenames = remotenamesext.readremotenames(repo)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   746
    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
   747
        if remote != remotepath:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   748
            continue
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   749
        if nametype == b'bookmarks':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   750
            if rname in newbookmarks:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   751
                # 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
   752
                # 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
   753
                # bookmark node
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   754
                del newbookmarks[rname]
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   755
            bookmarks[rname] = hexnode
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   756
        elif nametype == b'branches':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   757
            # 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
   758
            branches[rname].append(bin(hexnode))
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   759
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   760
    for bookmark, hexnode in newbookmarks.iteritems():
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   761
        bookmarks[bookmark] = hexnode
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   762
    remotenamesext.saveremotenames(repo, remotepath, branches, bookmarks)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   763
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   764
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   765
def _savelocalbookmarks(repo, bookmarks):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   766
    if not bookmarks:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   767
        return
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   768
    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
   769
        changes = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   770
        for scratchbook, node in bookmarks.iteritems():
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   771
            changectx = repo[node]
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   772
            changes.append((scratchbook, changectx.node()))
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   773
        repo._bookmarks.applychanges(repo, tr, changes)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   774
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   775
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   776
def _findcommonincoming(orig, *args, **kwargs):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   777
    common, inc, remoteheads = orig(*args, **kwargs)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   778
    return common, True, remoteheads
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   779
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   780
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   781
def _push(orig, ui, repo, dest=None, *args, **opts):
40252
090e5f3900b7 py3: fix infinitepush extension tests
Mark Thomas <mbthomas@fb.com>
parents: 39826
diff changeset
   782
    opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   783
    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
   784
    # 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
   785
    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
   786
        bookmark = bookmark[0]
c5687ce3b411 infinitepush: drop the `--to` flag to push and use `-B` instead
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37198
diff changeset
   787
    else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   788
        bookmark = b''
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   789
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   790
    oldphasemove = None
37198
78c2e9418278 infinitepush: drop the `--create` flag to push command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37197
diff changeset
   791
    overrides = {(experimental, configbookmark): bookmark}
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   792
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   793
    with ui.configoverride(overrides, b'infinitepush'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   794
        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
   795
        if _scratchbranchmatcher(bookmark):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   796
            scratchpush = True
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   797
            # 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
   798
            # 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
   799
            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
   800
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   801
        if scratchpush:
37199
c5687ce3b411 infinitepush: drop the `--to` flag to push and use `-B` instead
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37198
diff changeset
   802
            # 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
   803
            # 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
   804
            opts[b'bookmark'] = []
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   805
            ui.setconfig(experimental, configscratchpush, True)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   806
            oldphasemove = extensions.wrapfunction(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   807
                exchange, b'_localphasemove', _phasemove
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   808
            )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   809
        # Copy-paste from `push` command
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   810
        path = ui.paths.getpath(dest, default=(b'default-push', b'default'))
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   811
        if not path:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   812
            raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   813
                _(b'default repository not configured!'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   814
                hint=_(b"see 'hg help config.paths'"),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   815
            )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   816
        destpath = path.pushloc or path.loc
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   817
        # 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
   818
        # 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
   819
        remotescratchbookmarks = _readscratchremotebookmarks(ui, repo, destpath)
40252
090e5f3900b7 py3: fix infinitepush extension tests
Mark Thomas <mbthomas@fb.com>
parents: 39826
diff changeset
   820
        result = orig(ui, repo, dest, *args, **pycompat.strkwargs(opts))
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   821
        if common.isremotebooksenabled(ui):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   822
            if bookmark and scratchpush:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   823
                other = hg.peer(repo, opts, destpath)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   824
                fetchedbookmarks = other.listkeyspatterns(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   825
                    b'bookmarks', patterns=[bookmark]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   826
                )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   827
                remotescratchbookmarks.update(fetchedbookmarks)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   828
            _saveremotebookmarks(repo, remotescratchbookmarks, destpath)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   829
    if oldphasemove:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   830
        exchange._localphasemove = oldphasemove
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   831
    return result
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   832
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   833
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   834
def _deleteinfinitepushbookmarks(ui, repo, path, names):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   835
    """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
   836
    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
   837
    """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   838
    remotenamesext = extensions.find(b'remotenames')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   839
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   840
    # remotename format is:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   841
    # (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
   842
    nametype_idx = 1
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   843
    remote_idx = 2
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   844
    name_idx = 3
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   845
    remotenames = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   846
        remotename
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   847
        for remotename in remotenamesext.readremotenames(repo)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   848
        if remotename[remote_idx] == path
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   849
    ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   850
    remote_bm_names = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   851
        remotename[name_idx]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   852
        for remotename in remotenames
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   853
        if remotename[nametype_idx] == b"bookmarks"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   854
    ]
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   855
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   856
    for name in names:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   857
        if name not in remote_bm_names:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   858
            raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   859
                _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   860
                    b"infinitepush bookmark '{}' does not exist "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   861
                    b"in path '{}'"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   862
                ).format(name, path)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   863
            )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   864
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   865
    bookmarks = {}
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   866
    branches = collections.defaultdict(list)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   867
    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
   868
        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
   869
            bookmarks[name] = node
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   870
        elif nametype == b"branches":
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   871
            # saveremotenames wants binary nodes for branches
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   872
            branches[name].append(bin(node))
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   873
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   874
    remotenamesext.saveremotenames(repo, path, branches, bookmarks)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   875
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   876
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   877
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
   878
    """prevent commits from being marked public
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   879
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   880
    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
   881
    published."""
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   882
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   883
    if phase != phases.public:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   884
        orig(pushop, nodes, phase)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   885
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   886
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   887
@exchange.b2partsgenerator(scratchbranchparttype)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   888
def partgen(pushop, bundler):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   889
    bookmark = pushop.ui.config(experimental, configbookmark)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   890
    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
   891
    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
   892
        return
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   893
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   894
    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
   895
        return
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   896
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   897
    pushop.stepsdone.add(b'changesets')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   898
    if not pushop.outgoing.missing:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   899
        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
   900
        pushop.cgresult = 0
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   901
        return
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   902
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   903
    # 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
   904
    # 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
   905
    # code path.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   906
    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
   907
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   908
    scratchparts = bundleparts.getscratchbranchparts(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   909
        pushop.repo, pushop.remote, pushop.outgoing, pushop.ui, bookmark
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   910
    )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   911
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   912
    for scratchpart in scratchparts:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   913
        bundler.addpart(scratchpart)
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
    def handlereply(op):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   916
        # 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
   917
        pushop.cgresult = 1
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   918
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   919
    return handlereply
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   920
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   921
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   922
bundle2.capabilities[bundleparts.scratchbranchparttype] = ()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   923
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   924
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   925
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
   926
    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
   927
    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
   928
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   929
    # new bookmark
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   930
    if oldnode is None:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   931
        return revs
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   932
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   933
    # Fast forward update
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   934
    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
   935
        return revs
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   936
37203
f083e7fd6313 infinitepush: delete the non-forward-move flag for hg push
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37202
diff changeset
   937
    return revs
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   938
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   939
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   940
@contextlib.contextmanager
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   941
def logservicecall(logger, service, **kwargs):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   942
    start = time.time()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   943
    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
   944
    try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   945
        yield
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   946
        logger(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   947
            service,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   948
            eventtype=b'success',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   949
            elapsedms=(time.time() - start) * 1000,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   950
            **kwargs
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
    except Exception as e:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   953
        logger(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   954
            service,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   955
            eventtype=b'failure',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   956
            elapsedms=(time.time() - start) * 1000,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   957
            errormsg=str(e),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   958
            **kwargs
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   959
        )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   960
        raise
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
def _getorcreateinfinitepushlogger(op):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   964
    logger = op.records[b'infinitepushlogger']
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   965
    if not logger:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   966
        ui = op.repo.ui
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   967
        try:
37204
0d6c12668691 inifnitepush: use utils.{stringutil|procutil}.* instead of util.*
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37203
diff changeset
   968
            username = procutil.getuser()
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   969
        except Exception:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   970
            username = b'unknown'
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   971
        # 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
   972
        # 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
   973
        # 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
   974
        # is unique.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   975
        random.seed()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   976
        requestid = random.randint(0, 2000000000)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   977
        hostname = socket.gethostname()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   978
        logger = functools.partial(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   979
            ui.log,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   980
            b'infinitepush',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   981
            user=username,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   982
            requestid=requestid,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   983
            hostname=hostname,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   984
            reponame=ui.config(b'infinitepush', b'reponame'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   985
        )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   986
        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
   987
    else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   988
        logger = logger[0]
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   989
    return logger
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
   990
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
   991
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
   992
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
   993
    """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
   994
    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
   995
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   996
    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
   997
    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
   998
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
   999
    # 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
  1000
    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
  1001
        for part in parts:
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1002
            bundlepart = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1003
            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
  1004
                # 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
  1005
                bundle2._processpart(op, part)
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1006
            else:
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1007
                bundlepart = bundle2.bundlepart(part.type, data=part.read())
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1008
                for key, value in part.params.iteritems():
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1009
                    bundlepart.addparam(key, value)
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1010
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1011
                # Certain parts require a response
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1012
                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
  1013
                    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
  1014
                        rpart = op.reply.newpart(b'reply:%s' % part.type)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1015
                        rpart.addparam(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1016
                            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
  1017
                        )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1018
                        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
  1019
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1020
            op.records.add(part.type, {b'return': 1,})
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1021
            if bundlepart:
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1022
                bundler.addpart(bundlepart)
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1023
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1024
    # 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
  1025
    buf = util.chunkbuffer(bundler.getchunks())
38164
aac4be30e250 py3: wrap tempfile.mkstemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents: 38088
diff changeset
  1026
    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
  1027
    try:
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1028
        try:
37578
56df2ca5c032 py3: prevent transformer from adding b'' by adding r'' prefix
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37577
diff changeset
  1029
            fp = os.fdopen(fd, r'wb')
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1030
            fp.write(buf.read())
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1031
        finally:
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1032
            fp.close()
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1033
        storebundle(op, {}, bundlefile)
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1034
    finally:
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1035
        try:
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1036
            os.unlink(bundlefile)
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1037
        except Exception:
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1038
            # 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
  1039
            pass
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1040
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1041
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1042
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
  1043
e5cd0ef5c362 infinitepush: don't wrap bundle2.processparts while calling `hg unbundle`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37204
diff changeset
  1044
    # 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
  1045
    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
  1046
        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
  1047
37206
571f25dae740 infinitepush: introduce server option to route every push to bundlestore
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37205
diff changeset
  1048
    # 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
  1049
    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
  1050
        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
  1051
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1052
    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
  1053
        return orig(repo, op, unbundler)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1054
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1055
    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
  1056
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1057
    bundler = bundle2.bundle20(repo.ui)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1058
    cgparams = None
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1059
    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
  1060
        for part in parts:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1061
            bundlepart = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1062
            if part.type == b'replycaps':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1063
                # 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
  1064
                bundle2._processpart(op, part)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1065
            elif part.type == bundleparts.scratchbranchparttype:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1066
                # 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
  1067
                # 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
  1068
                # 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
  1069
                # 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
  1070
                # 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
  1071
                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
  1072
                bundlepart = bundle2.bundlepart(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1073
                    b'changegroup', data=part.read()
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1074
                )
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1075
                bundlepart.addparam(b'version', cgversion)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1076
                cgparams = part.params
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1077
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1078
                # 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
  1079
                # 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
  1080
                # the part.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1081
                if not handleallparts:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1082
                    op.records.add(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1083
                        scratchbranchparttype + b'_skippushkey', True
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1084
                    )
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1085
                    op.records.add(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1086
                        scratchbranchparttype + b'_skipphaseheads', True
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
            else:
37197
7fa00a6f8180 infinitepush: drop logic related to treemanifest extension
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37196
diff changeset
  1089
                if handleallparts:
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1090
                    # 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
  1091
                    # 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
  1092
                    # 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
  1093
                    # config flag for incremental rollout.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1094
                    bundlepart = bundle2.bundlepart(part.type, data=part.read())
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1095
                    for key, value in part.params.iteritems():
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1096
                        bundlepart.addparam(key, value)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1097
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1098
                    # Certain parts require a response
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1099
                    if part.type == b'pushkey':
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1100
                        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
  1101
                            rpart = op.reply.newpart(b'reply:pushkey')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1102
                            rpart.addparam(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1103
                                b'in-reply-to', str(part.id), mandatory=False
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1104
                            )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1105
                            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
  1106
                else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1107
                    bundle2._processpart(op, part)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1108
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1109
            if handleallparts:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1110
                op.records.add(part.type, {b'return': 1,})
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1111
            if bundlepart:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1112
                bundler.addpart(bundlepart)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1113
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1114
    # If commits were sent, store them
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1115
    if cgparams:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1116
        buf = util.chunkbuffer(bundler.getchunks())
38164
aac4be30e250 py3: wrap tempfile.mkstemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents: 38088
diff changeset
  1117
        fd, bundlefile = pycompat.mkstemp()
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1118
        try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1119
            try:
37578
56df2ca5c032 py3: prevent transformer from adding b'' by adding r'' prefix
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37577
diff changeset
  1120
                fp = os.fdopen(fd, r'wb')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1121
                fp.write(buf.read())
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1122
            finally:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1123
                fp.close()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1124
            storebundle(op, cgparams, bundlefile)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1125
        finally:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1126
            try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1127
                os.unlink(bundlefile)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1128
            except Exception:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1129
                # 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
  1130
                pass
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1131
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1132
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1133
def storebundle(op, params, bundlefile):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1134
    log = _getorcreateinfinitepushlogger(op)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1135
    parthandlerstart = time.time()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1136
    log(scratchbranchparttype, eventtype=b'start')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1137
    index = op.repo.bundlestore.index
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1138
    store = op.repo.bundlestore.store
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1139
    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
  1140
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1141
    bundle = None
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1142
    try:  # guards bundle
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1143
        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
  1144
        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
  1145
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1146
        bookmark = params.get(b'bookmark')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1147
        bookprevnode = params.get(b'bookprevnode', b'')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1148
        force = params.get(b'force')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1149
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1150
        if bookmark:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1151
            oldnode = index.getnode(bookmark)
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
            oldnode = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1154
        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
  1155
        if bookmark and len(bundleheads) > 1:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1156
            raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1157
                _(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
  1158
            )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1159
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1160
        revs = _getrevs(bundle, oldnode, force, bookmark)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1161
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1162
        # 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
  1163
        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
  1164
        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
  1165
        maxoutput = 10
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1166
        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
  1167
            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
  1168
            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
  1169
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1170
        if len(revs) > maxoutput + 1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1171
            op.repo.ui.warn(b"    ...\n")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1172
            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
  1173
            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
  1174
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1175
        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
  1176
        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
  1177
        if bundleheads:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1178
            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
  1179
        else:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1180
            newheadscount = 0
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1181
        # 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
  1182
        # 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
  1183
        # 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
  1184
        # 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
  1185
        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
  1186
        key = None
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1187
        if newheadscount:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1188
            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
  1189
                bundledata = f.read()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1190
                with logservicecall(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1191
                    log, b'bundlestore', bundlesize=len(bundledata)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1192
                ):
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1193
                    bundlesizelimit = 100 * 1024 * 1024  # 100 MB
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1194
                    if len(bundledata) > bundlesizelimit:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1195
                        error_msg = (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1196
                            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
  1197
                            + b'max allowed size is 100 MB'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1198
                        )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1199
                        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
  1200
                    key = store.write(bundledata)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1201
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1202
        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
  1203
            if key:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1204
                index.addbundle(key, nodesctx)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1205
            if bookmark:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1206
                index.addbookmark(bookmark, bookmarknode)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1207
                _maybeaddpushbackpart(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1208
                    op, bookmark, bookmarknode, bookprevnode, params
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1209
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1210
        log(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1211
            scratchbranchparttype,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1212
            eventtype=b'success',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1213
            elapsedms=(time.time() - parthandlerstart) * 1000,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1214
        )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1215
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1216
    except Exception as e:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1217
        log(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1218
            scratchbranchparttype,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1219
            eventtype=b'failure',
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1220
            elapsedms=(time.time() - parthandlerstart) * 1000,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1221
            errormsg=str(e),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1222
        )
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1223
        raise
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1224
    finally:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1225
        if bundle:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1226
            bundle.close()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1227
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1228
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1229
@bundle2.parthandler(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1230
    scratchbranchparttype,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1231
    (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1232
        b'bookmark',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1233
        b'bookprevnode',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1234
        b'force',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1235
        b'pushbackbookmarks',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1236
        b'cgversion',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1237
    ),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1238
)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1239
def bundle2scratchbranch(op, part):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1240
    '''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
  1241
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1242
    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
  1243
    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
  1244
    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
  1245
    cgpart.addparam(b'version', cgversion)
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1246
    bundler.addpart(cgpart)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1247
    buf = util.chunkbuffer(bundler.getchunks())
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1248
38164
aac4be30e250 py3: wrap tempfile.mkstemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents: 38088
diff changeset
  1249
    fd, bundlefile = pycompat.mkstemp()
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1250
    try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1251
        try:
37578
56df2ca5c032 py3: prevent transformer from adding b'' by adding r'' prefix
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37577
diff changeset
  1252
            fp = os.fdopen(fd, r'wb')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1253
            fp.write(buf.read())
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1254
        finally:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1255
            fp.close()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1256
        storebundle(op, part.params, bundlefile)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1257
    finally:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1258
        try:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1259
            os.unlink(bundlefile)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1260
        except OSError as e:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1261
            if e.errno != errno.ENOENT:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1262
                raise
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1263
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1264
    return 1
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1265
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1266
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1267
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
  1268
    if params.get(b'pushbackbookmarks'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1269
        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
  1270
            params = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1271
                b'namespace': b'bookmarks',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1272
                b'key': bookmark,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1273
                b'new': newnode,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1274
                b'old': oldnode,
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1275
            }
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1276
            op.reply.newpart(b'pushkey', mandatoryparams=params.iteritems())
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1277
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1278
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1279
def bundle2pushkey(orig, op, part):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1280
    '''Wrapper of bundle2.handlepushkey()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1281
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1282
    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
  1283
    It's set if infinitepush push is happening.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1284
    '''
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1285
    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
  1286
        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
  1287
            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
  1288
            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
  1289
            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
  1290
        return 1
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1291
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1292
    return orig(op, part)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1293
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1294
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1295
def bundle2handlephases(orig, op, part):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1296
    '''Wrapper of bundle2.handlephases()
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1297
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1298
    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
  1299
    It's set if infinitepush push is happening.
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1300
    '''
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1301
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1302
    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
  1303
        return
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1304
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1305
    return orig(op, part)
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1306
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1307
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1308
def _asyncsavemetadata(root, nodes):
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1309
    '''starts a separate process that fills metadata for the nodes
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1310
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1311
    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
  1312
    completion. This was done to avoid slowing down pushes
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1313
    '''
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
    maxnodes = 50
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1316
    if len(nodes) > maxnodes:
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1317
        return
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1318
    nodesargs = []
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1319
    for node in nodes:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1320
        nodesargs.append(b'--node')
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1321
        nodesargs.append(node)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1322
    with open(os.devnull, b'w+b') as devnull:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1323
        cmdline = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1324
            util.hgexecutable(),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1325
            b'debugfillinfinitepushmetadata',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1326
            b'-R',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1327
            root,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1328
        ] + nodesargs
37187
03ff17a4bf53 infinitepush: move the extension to core from fb-hgext
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
  1329
        # 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
  1330
        subprocess.Popen(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1331
            pycompat.rapply(procutil.tonativestr, cmdline),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1332
            close_fds=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1333
            shell=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1334
            stdin=devnull,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1335
            stdout=devnull,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1336
            stderr=devnull,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
  1337
        )