annotate hgext/infinitepush/__init__.py @ 43076:2372284d9457

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