annotate hgext/phabricator.py @ 51788:278af66e6595

typing: induce pytype to use the standard `attr` instead of the vendored copy What was previously happening with the vendored copy was that pytype would stub out all(?) classes that were decorated with `@attr.s` as `Any`. After this, we get a ton of classes defined, and numerous fields and methods now have proper types.
author Matt Harbison <matt_harbison@yahoo.com>
date Tue, 23 Jul 2024 19:20:22 -0400
parents 587153c96fe3
children f4733654f144
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
1 # phabricator.py - simple Phabricator integration
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
2 #
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
3 # Copyright 2017 Facebook, Inc.
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
4 #
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
39671
87539f615b87 phabricator: mark extension as experimental for now
Augie Fackler <raf@durin42.com>
parents: 39670
diff changeset
7 """simple Phabricator integration (EXPERIMENTAL)
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
8
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
9 This extension provides a ``phabsend`` command which sends a stack of
33993
07ffff841863 phabsend: make --amend the default
Jun Wu <quark@fb.com>
parents: 33992
diff changeset
10 changesets to Phabricator, and a ``phabread`` command which prints a stack of
07ffff841863 phabsend: make --amend the default
Jun Wu <quark@fb.com>
parents: 33992
diff changeset
11 revisions in a format suitable for :hg:`import`, and a ``phabupdate`` command
07ffff841863 phabsend: make --amend the default
Jun Wu <quark@fb.com>
parents: 33992
diff changeset
12 to update statuses in batch.
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
13
43857
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
14 A "phabstatus" view for :hg:`show` is also provided; it displays status
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
15 information of Phabricator differentials associated with unfinished
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
16 changesets.
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
17
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
18 By default, Phabricator requires ``Test Plan`` which might prevent some
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
19 changeset from being sent. The requirement could be disabled by changing
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
20 ``differential.require-test-plan-field`` config server side.
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
21
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
22 Config::
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
23
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
24 [phabricator]
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
25 # Phabricator URL
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
26 url = https://phab.example.com/
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
27
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
28 # Repo callsign. If a repo has a URL https://$HOST/diffusion/FOO, then its
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
29 # callsign is "FOO".
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
30 callsign = FOO
33202
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33201
diff changeset
31
34081
8b659b7388c0 phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents: 34080
diff changeset
32 # curl command to use. If not set (default), use builtin HTTP library to
8b659b7388c0 phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents: 34080
diff changeset
33 # communicate. If set, use the specified curl command. This could be useful
8b659b7388c0 phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents: 34080
diff changeset
34 # if you need to specify advanced options that is not easily supported by
8b659b7388c0 phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents: 34080
diff changeset
35 # the internal library.
8b659b7388c0 phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents: 34080
diff changeset
36 curlcmd = curl --connect-timeout 2 --retry 3 --silent
36795
4397909f82d3 phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents: 36543
diff changeset
37
45984
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
38 # retry failed command N time (default 0). Useful when using the extension
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
39 # over flakly connection.
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
40 #
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
41 # We wait `retry.interval` between each retry, in seconds.
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
42 # (default 1 second).
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
43 retry = 3
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
44 retry.interval = 10
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
45
45985
4d70444c3ea9 phabricator: use the `http.timeout` config for conduit call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45984
diff changeset
46 # the retry option can combine well with the http.timeout one.
4d70444c3ea9 phabricator: use the `http.timeout` config for conduit call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45984
diff changeset
47 #
4d70444c3ea9 phabricator: use the `http.timeout` config for conduit call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45984
diff changeset
48 # For example to give up on http request after 20 seconds:
4d70444c3ea9 phabricator: use the `http.timeout` config for conduit call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45984
diff changeset
49 [http]
4d70444c3ea9 phabricator: use the `http.timeout` config for conduit call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45984
diff changeset
50 timeout=20
4d70444c3ea9 phabricator: use the `http.timeout` config for conduit call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45984
diff changeset
51
38039
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 38020
diff changeset
52 [auth]
38040
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 38039
diff changeset
53 example.schemes = https
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 38039
diff changeset
54 example.prefix = phab.example.com
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 38039
diff changeset
55
36795
4397909f82d3 phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents: 36543
diff changeset
56 # API token. Get it from https://$HOST/conduit/login/
38039
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 38020
diff changeset
57 example.phabtoken = cli-xxxxxxxxxxxxxxxxxxxxxxxxxxxx
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
58 """
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
59
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
60
43187
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
61 import base64
41083
9d35ae3d9999 phabricator: ensure that the return of urlopener.open() is closed
Matt Harbison <matt_harbison@yahoo.com>
parents: 41081
diff changeset
62 import contextlib
43188
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
63 import hashlib
48964
5aafc3c5bdec py3: use io.BytesIO directly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48128
diff changeset
64 import io
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
65 import itertools
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
66 import json
43189
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
67 import mimetypes
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
68 import operator
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
69 import re
45984
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
70 import time
51788
278af66e6595 typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents: 51785
diff changeset
71 import typing
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
72
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46907
diff changeset
73 from mercurial.node import bin, short
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
74 from mercurial.i18n import _
43183
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
75 from mercurial.thirdparty import attr
51788
278af66e6595 typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents: 51785
diff changeset
76
278af66e6595 typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents: 51785
diff changeset
77 # Force pytype to use the non-vendored package
278af66e6595 typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents: 51785
diff changeset
78 if typing.TYPE_CHECKING:
278af66e6595 typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents: 51785
diff changeset
79 # noinspection PyPackageRequirements
278af66e6595 typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents: 51785
diff changeset
80 import attr
278af66e6595 typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents: 51785
diff changeset
81
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
82 from mercurial import (
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
83 cmdutil,
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
84 context,
44615
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44614
diff changeset
85 copies,
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
86 encoding,
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
87 error,
42975
24bf7a3d3c30 phabricator: use exthelper to register commands, config, and templates
Matt Harbison <matt_harbison@yahoo.com>
parents: 42955
diff changeset
88 exthelper,
43857
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
89 graphmod,
38040
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 38039
diff changeset
90 httpconnection as httpconnectionmod,
44127
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
91 localrepo,
43857
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
92 logcmdutil,
43186
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
93 match,
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
94 mdiff,
33761
e6d8ee3c9ec3 obsutil: rename allprecursors into allpredecessors
Boris Feld <boris.feld@octobus.net>
parents: 33718
diff changeset
95 obsutil,
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
96 parser,
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
97 patch,
41163
0101a35deae2 phabricator: warn if unable to amend, instead of aborting after posting
Matt Harbison <matt_harbison@yahoo.com>
parents: 41083
diff changeset
98 phases,
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
99 pycompat,
45437
1a5d3e555c70 phabricator: update the hashes in commit messages as they get submitted
Matt Harbison <matt_harbison@yahoo.com>
parents: 45272
diff changeset
100 rewriteutil,
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
101 scmutil,
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
102 smartset,
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
103 tags,
42226
289d82a070e9 phabricator: use templatefilters.json in writediffproperties
Ian Moody <moz-ian@perix.co.uk>
parents: 41976
diff changeset
104 templatefilters,
39670
4057e38bba76 phabricator: fix templating bug by using hybriddict
Augie Fackler <raf@durin42.com>
parents: 39668
diff changeset
105 templateutil,
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
106 url as urlmod,
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
107 util,
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
108 )
37123
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36826
diff changeset
109 from mercurial.utils import (
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36826
diff changeset
110 procutil,
37800
6cf5f5b4eb57 phabricator: specify some metadata compatibly with arc
Tom Prince <mozilla@hocat.ca>
parents: 37123
diff changeset
111 stringutil,
46907
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46041
diff changeset
112 urlutil,
37123
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36826
diff changeset
113 )
43857
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
114 from . import show
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
115
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
116
39751
c0c703861b60 phabricator: add testedwith boilerplate
Yuya Nishihara <yuya@tcha.org>
parents: 39671
diff changeset
117 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
c0c703861b60 phabricator: add testedwith boilerplate
Yuya Nishihara <yuya@tcha.org>
parents: 39671
diff changeset
118 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
c0c703861b60 phabricator: add testedwith boilerplate
Yuya Nishihara <yuya@tcha.org>
parents: 39671
diff changeset
119 # be specifying the version(s) of Mercurial they are tested with, or
c0c703861b60 phabricator: add testedwith boilerplate
Yuya Nishihara <yuya@tcha.org>
parents: 39671
diff changeset
120 # leave the attribute unspecified.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
121 testedwith = b'ships-with-hg-core'
39751
c0c703861b60 phabricator: add testedwith boilerplate
Yuya Nishihara <yuya@tcha.org>
parents: 39671
diff changeset
122
42975
24bf7a3d3c30 phabricator: use exthelper to register commands, config, and templates
Matt Harbison <matt_harbison@yahoo.com>
parents: 42955
diff changeset
123 eh = exthelper.exthelper()
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
124
42975
24bf7a3d3c30 phabricator: use exthelper to register commands, config, and templates
Matt Harbison <matt_harbison@yahoo.com>
parents: 42955
diff changeset
125 cmdtable = eh.cmdtable
24bf7a3d3c30 phabricator: use exthelper to register commands, config, and templates
Matt Harbison <matt_harbison@yahoo.com>
parents: 42955
diff changeset
126 command = eh.command
24bf7a3d3c30 phabricator: use exthelper to register commands, config, and templates
Matt Harbison <matt_harbison@yahoo.com>
parents: 42955
diff changeset
127 configtable = eh.configtable
24bf7a3d3c30 phabricator: use exthelper to register commands, config, and templates
Matt Harbison <matt_harbison@yahoo.com>
parents: 42955
diff changeset
128 templatekeyword = eh.templatekeyword
44127
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
129 uisetup = eh.finaluisetup
38075
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 38040
diff changeset
130
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 38040
diff changeset
131 # developer config: phabricator.batchsize
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
132 eh.configitem(
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
133 b'phabricator',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
134 b'batchsize',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
135 default=12,
38075
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 38040
diff changeset
136 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
137 eh.configitem(
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
138 b'phabricator',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
139 b'callsign',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
140 default=None,
38075
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 38040
diff changeset
141 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
142 eh.configitem(
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
143 b'phabricator',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
144 b'curlcmd',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
145 default=None,
38075
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 38040
diff changeset
146 )
44715
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
147 # developer config: phabricator.debug
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
148 eh.configitem(
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
149 b'phabricator',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
150 b'debug',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
151 default=False,
44715
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
152 )
38075
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 38040
diff changeset
153 # developer config: phabricator.repophid
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
154 eh.configitem(
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
155 b'phabricator',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
156 b'repophid',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
157 default=None,
38075
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 38040
diff changeset
158 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
159 eh.configitem(
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
160 b'phabricator',
45984
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
161 b'retry',
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
162 default=0,
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
163 )
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
164 eh.configitem(
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
165 b'phabricator',
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
166 b'retry.interval',
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
167 default=1,
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
168 )
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
169 eh.configitem(
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
170 b'phabricator',
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
171 b'url',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
172 default=None,
38075
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 38040
diff changeset
173 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
174 eh.configitem(
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
175 b'phabsend',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
176 b'confirm',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
177 default=False,
38075
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 38040
diff changeset
178 )
44561
9bae1d1a0f4c phabricator: add a config knob to import in the secret phase
Matt Harbison <matt_harbison@yahoo.com>
parents: 44560
diff changeset
179 eh.configitem(
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
180 b'phabimport',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
181 b'secret',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
182 default=False,
44561
9bae1d1a0f4c phabricator: add a config knob to import in the secret phase
Matt Harbison <matt_harbison@yahoo.com>
parents: 44560
diff changeset
183 )
44562
f10055b099b3 phabricator: add a config knob to create obsolete markers when importing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44561
diff changeset
184 eh.configitem(
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
185 b'phabimport',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
186 b'obsolete',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
187 default=False,
44562
f10055b099b3 phabricator: add a config knob to create obsolete markers when importing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44561
diff changeset
188 )
38075
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 38040
diff changeset
189
34080
941c33cfde81 phabricator: standardize colors
Jun Wu <quark@fb.com>
parents: 33996
diff changeset
190 colortable = {
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
191 b'phabricator.action.created': b'green',
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
192 b'phabricator.action.skipped': b'magenta',
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
193 b'phabricator.action.updated': b'magenta',
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
194 b'phabricator.drev': b'bold',
43869
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43868
diff changeset
195 b'phabricator.status.abandoned': b'magenta dim',
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43868
diff changeset
196 b'phabricator.status.accepted': b'green bold',
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43868
diff changeset
197 b'phabricator.status.closed': b'green',
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43868
diff changeset
198 b'phabricator.status.needsreview': b'yellow',
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43868
diff changeset
199 b'phabricator.status.needsrevision': b'red',
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43868
diff changeset
200 b'phabricator.status.changesplanned': b'red',
34080
941c33cfde81 phabricator: standardize colors
Jun Wu <quark@fb.com>
parents: 33996
diff changeset
201 }
941c33cfde81 phabricator: standardize colors
Jun Wu <quark@fb.com>
parents: 33996
diff changeset
202
39666
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38983
diff changeset
203 _VCR_FLAGS = [
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
204 (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
205 b'',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
206 b'test-vcr',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
207 b'',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
208 _(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
209 b'Path to a vcr file. If nonexistent, will record a new vcr transcript'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
210 b', otherwise will mock all http requests using the specified vcr file.'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
211 b' (ADVANCED)'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
212 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
213 ),
39666
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38983
diff changeset
214 ]
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38983
diff changeset
215
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
216
44127
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
217 @eh.wrapfunction(localrepo, "loadhgrc")
45513
c7fe0dfb5312 phabricator: fix loadhgrc() override broken by D8656
Martin von Zweigbergk <martinvonz@google.com>
parents: 45496
diff changeset
218 def _loadhgrc(orig, ui, wdirvfs, hgvfs, requirements, *args, **opts):
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
219 """Load ``.arcconfig`` content into a ui instance on repository open."""
44127
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
220 result = False
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
221 arcconfig = {}
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
222
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
223 try:
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
224 # json.loads only accepts bytes from 3.6+
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
225 rawparams = encoding.unifromlocal(wdirvfs.read(b".arcconfig"))
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
226 # json.loads only returns unicode strings
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
227 arcconfig = pycompat.rapply(
49025
06de08b36c82 py3: use str instead of pycompat.unicode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 49004
diff changeset
228 lambda x: encoding.unitolocal(x) if isinstance(x, str) else x,
44127
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
229 pycompat.json_loads(rawparams),
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
230 )
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
231
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
232 result = True
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
233 except ValueError:
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
234 ui.warn(_(b"invalid JSON in %s\n") % wdirvfs.join(b".arcconfig"))
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
235 except IOError:
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
236 pass
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
237
44128
ff396501e841 phabricator: use .arcconfig for `phabricator.url` if not set locally
Matt Harbison <matt_harbison@yahoo.com>
parents: 44127
diff changeset
238 cfg = util.sortdict()
ff396501e841 phabricator: use .arcconfig for `phabricator.url` if not set locally
Matt Harbison <matt_harbison@yahoo.com>
parents: 44127
diff changeset
239
44127
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
240 if b"repository.callsign" in arcconfig:
44128
ff396501e841 phabricator: use .arcconfig for `phabricator.url` if not set locally
Matt Harbison <matt_harbison@yahoo.com>
parents: 44127
diff changeset
241 cfg[(b"phabricator", b"callsign")] = arcconfig[b"repository.callsign"]
ff396501e841 phabricator: use .arcconfig for `phabricator.url` if not set locally
Matt Harbison <matt_harbison@yahoo.com>
parents: 44127
diff changeset
242
ff396501e841 phabricator: use .arcconfig for `phabricator.url` if not set locally
Matt Harbison <matt_harbison@yahoo.com>
parents: 44127
diff changeset
243 if b"phabricator.uri" in arcconfig:
ff396501e841 phabricator: use .arcconfig for `phabricator.url` if not set locally
Matt Harbison <matt_harbison@yahoo.com>
parents: 44127
diff changeset
244 cfg[(b"phabricator", b"url")] = arcconfig[b"phabricator.uri"]
ff396501e841 phabricator: use .arcconfig for `phabricator.url` if not set locally
Matt Harbison <matt_harbison@yahoo.com>
parents: 44127
diff changeset
245
ff396501e841 phabricator: use .arcconfig for `phabricator.url` if not set locally
Matt Harbison <matt_harbison@yahoo.com>
parents: 44127
diff changeset
246 if cfg:
ff396501e841 phabricator: use .arcconfig for `phabricator.url` if not set locally
Matt Harbison <matt_harbison@yahoo.com>
parents: 44127
diff changeset
247 ui.applyconfig(cfg, source=wdirvfs.join(b".arcconfig"))
44127
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
248
45496
b71858b42963 localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45437
diff changeset
249 return (
45513
c7fe0dfb5312 phabricator: fix loadhgrc() override broken by D8656
Martin von Zweigbergk <martinvonz@google.com>
parents: 45496
diff changeset
250 orig(ui, wdirvfs, hgvfs, requirements, *args, **opts) or result
45496
b71858b42963 localrepo: load the share source .hg/hgrc also in share-safe mode (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45437
diff changeset
251 ) # Load .hg/hgrc
44127
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
252
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
253
42451
16312ea45a8b phabricator: make `hg debugcallconduit` work outside a hg repo
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42450
diff changeset
254 def vcrcommand(name, flags, spec, helpcategory=None, optionalrepo=False):
39666
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38983
diff changeset
255 fullflags = flags + _VCR_FLAGS
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
256
42295
af13e2088f77 phabricator: add custom vcr matcher to match request bodies
Ian Moody <moz-ian@perix.co.uk>
parents: 42286
diff changeset
257 def hgmatcher(r1, r2):
af13e2088f77 phabricator: add custom vcr matcher to match request bodies
Ian Moody <moz-ian@perix.co.uk>
parents: 42286
diff changeset
258 if r1.uri != r2.uri or r1.method != r2.method:
af13e2088f77 phabricator: add custom vcr matcher to match request bodies
Ian Moody <moz-ian@perix.co.uk>
parents: 42286
diff changeset
259 return False
43264
a4da1c3b82ab phabricator: update hgmatcher to cope with the new data format
Ian Moody <moz-ian@perix.co.uk>
parents: 43263
diff changeset
260 r1params = util.urlreq.parseqs(r1.body)
a4da1c3b82ab phabricator: update hgmatcher to cope with the new data format
Ian Moody <moz-ian@perix.co.uk>
parents: 43263
diff changeset
261 r2params = util.urlreq.parseqs(r2.body)
a4da1c3b82ab phabricator: update hgmatcher to cope with the new data format
Ian Moody <moz-ian@perix.co.uk>
parents: 43263
diff changeset
262 for key in r1params:
a4da1c3b82ab phabricator: update hgmatcher to cope with the new data format
Ian Moody <moz-ian@perix.co.uk>
parents: 43263
diff changeset
263 if key not in r2params:
a4da1c3b82ab phabricator: update hgmatcher to cope with the new data format
Ian Moody <moz-ian@perix.co.uk>
parents: 43263
diff changeset
264 return False
a4da1c3b82ab phabricator: update hgmatcher to cope with the new data format
Ian Moody <moz-ian@perix.co.uk>
parents: 43263
diff changeset
265 value = r1params[key][0]
a4da1c3b82ab phabricator: update hgmatcher to cope with the new data format
Ian Moody <moz-ian@perix.co.uk>
parents: 43263
diff changeset
266 # we want to compare json payloads without worrying about ordering
a4da1c3b82ab phabricator: update hgmatcher to cope with the new data format
Ian Moody <moz-ian@perix.co.uk>
parents: 43263
diff changeset
267 if value.startswith(b'{') and value.endswith(b'}'):
43380
579672b347d2 py3: define and use json.loads polyfill
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43350
diff changeset
268 r1json = pycompat.json_loads(value)
579672b347d2 py3: define and use json.loads polyfill
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43350
diff changeset
269 r2json = pycompat.json_loads(r2params[key][0])
43264
a4da1c3b82ab phabricator: update hgmatcher to cope with the new data format
Ian Moody <moz-ian@perix.co.uk>
parents: 43263
diff changeset
270 if r1json != r2json:
a4da1c3b82ab phabricator: update hgmatcher to cope with the new data format
Ian Moody <moz-ian@perix.co.uk>
parents: 43263
diff changeset
271 return False
a4da1c3b82ab phabricator: update hgmatcher to cope with the new data format
Ian Moody <moz-ian@perix.co.uk>
parents: 43263
diff changeset
272 elif r2params[key][0] != value:
a4da1c3b82ab phabricator: update hgmatcher to cope with the new data format
Ian Moody <moz-ian@perix.co.uk>
parents: 43263
diff changeset
273 return False
a4da1c3b82ab phabricator: update hgmatcher to cope with the new data format
Ian Moody <moz-ian@perix.co.uk>
parents: 43263
diff changeset
274 return True
42295
af13e2088f77 phabricator: add custom vcr matcher to match request bodies
Ian Moody <moz-ian@perix.co.uk>
parents: 42286
diff changeset
275
42459
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42451
diff changeset
276 def sanitiserequest(request):
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42451
diff changeset
277 request.body = re.sub(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
278 br'cli-[a-z0-9]+', br'cli-hahayouwish', request.body
42459
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42451
diff changeset
279 )
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42451
diff changeset
280 return request
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42451
diff changeset
281
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42451
diff changeset
282 def sanitiseresponse(response):
43554
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43552
diff changeset
283 if 'set-cookie' in response['headers']:
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43552
diff changeset
284 del response['headers']['set-cookie']
42459
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42451
diff changeset
285 return response
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42451
diff changeset
286
39666
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38983
diff changeset
287 def decorate(fn):
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38983
diff changeset
288 def inner(*args, **kwargs):
45272
b1f2659c1c34 phabricator: unconditionally pop `test_vcr` to fix debugcallconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 45152
diff changeset
289 vcr = kwargs.pop('test_vcr')
b1f2659c1c34 phabricator: unconditionally pop `test_vcr` to fix debugcallconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 45152
diff changeset
290 if vcr:
b1f2659c1c34 phabricator: unconditionally pop `test_vcr` to fix debugcallconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 45152
diff changeset
291 cassette = pycompat.fsdecode(vcr)
39666
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38983
diff changeset
292 import hgdemandimport
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
293
39666
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38983
diff changeset
294 with hgdemandimport.deactivated():
49931
de9ffb82ef4d typing: suppress a bunch of potential import-error cases in extensions
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
295 # pytype: disable=import-error
39666
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38983
diff changeset
296 import vcr as vcrmod
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38983
diff changeset
297 import vcr.stubs as stubs
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
298
49931
de9ffb82ef4d typing: suppress a bunch of potential import-error cases in extensions
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
299 # pytype: enable=import-error
de9ffb82ef4d typing: suppress a bunch of potential import-error cases in extensions
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
300
40378
b015f30a91fb phabricator: do more of the VCR work in demandimport.deactivated()
Augie Fackler <augie@google.com>
parents: 40151
diff changeset
301 vcr = vcrmod.VCR(
43554
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43552
diff changeset
302 serializer='json',
42459
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42451
diff changeset
303 before_record_request=sanitiserequest,
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42451
diff changeset
304 before_record_response=sanitiseresponse,
40378
b015f30a91fb phabricator: do more of the VCR work in demandimport.deactivated()
Augie Fackler <augie@google.com>
parents: 40151
diff changeset
305 custom_patches=[
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
306 (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
307 urlmod,
43554
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43552
diff changeset
308 'httpconnection',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
309 stubs.VCRHTTPConnection,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
310 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
311 (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
312 urlmod,
43554
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43552
diff changeset
313 'httpsconnection',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
314 stubs.VCRHTTPSConnection,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
315 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
316 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
317 )
43554
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43552
diff changeset
318 vcr.register_matcher('hgmatcher', hgmatcher)
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43552
diff changeset
319 with vcr.use_cassette(cassette, match_on=['hgmatcher']):
40378
b015f30a91fb phabricator: do more of the VCR work in demandimport.deactivated()
Augie Fackler <augie@google.com>
parents: 40151
diff changeset
320 return fn(*args, **kwargs)
39666
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38983
diff changeset
321 return fn(*args, **kwargs)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
322
44456
09f3e003fc2a phabricator: avoid a stacktrace when command arguments are missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
323 cmd = util.checksignature(inner, depth=2)
09f3e003fc2a phabricator: avoid a stacktrace when command arguments are missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
324 cmd.__name__ = fn.__name__
09f3e003fc2a phabricator: avoid a stacktrace when command arguments are missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
325 cmd.__doc__ = fn.__doc__
09f3e003fc2a phabricator: avoid a stacktrace when command arguments are missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
326
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
327 return command(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
328 name,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
329 fullflags,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
330 spec,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
331 helpcategory=helpcategory,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
332 optionalrepo=optionalrepo,
44456
09f3e003fc2a phabricator: avoid a stacktrace when command arguments are missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
333 )(cmd)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
334
39666
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38983
diff changeset
335 return decorate
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38983
diff changeset
336
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
337
44715
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
338 def _debug(ui, *msg, **opts):
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
339 """write debug output for Phabricator if ``phabricator.debug`` is set
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
340
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
341 Specifically, this avoids dumping Conduit and HTTP auth chatter that is
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
342 printed with the --debug argument.
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
343 """
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
344 if ui.configbool(b"phabricator", b"debug"):
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
345 flag = ui.debugflag
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
346 try:
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
347 ui.debugflag = True
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
348 ui.write(*msg, **opts)
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
349 finally:
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
350 ui.debugflag = flag
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
351
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
352
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
353 def urlencodenested(params):
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
354 """like urlencode, but works with nested parameters.
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
355
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
356 For example, if params is {'a': ['b', 'c'], 'd': {'e': 'f'}}, it will be
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
357 flattened to {'a[0]': 'b', 'a[1]': 'c', 'd[e]': 'f'} and then passed to
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
358 urlencode. Note: the encoding is consistent with PHP's http_build_query.
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
359 """
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
360 flatparams = util.sortdict()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
361
49945
92743e6d1a0c typing: disable a bogus attribute-error warning in phabricator
Matt Harbison <matt_harbison@yahoo.com>
parents: 49931
diff changeset
362 def process(prefix: bytes, obj):
40473
d7d3164e6a31 phabricator: properly encode boolean types in the request body
Matt Harbison <matt_harbison@yahoo.com>
parents: 40435
diff changeset
363 if isinstance(obj, bool):
d7d3164e6a31 phabricator: properly encode boolean types in the request body
Matt Harbison <matt_harbison@yahoo.com>
parents: 40435
diff changeset
364 obj = {True: b'true', False: b'false'}[obj] # Python -> PHP form
41905
47125193bad0 py3: convert indexes into bytes when enumerating lists in urlencodenested
Ian Moody <moz-ian@perix.co.uk>
parents: 41904
diff changeset
365 lister = lambda l: [(b'%d' % k, v) for k, v in enumerate(l)]
49945
92743e6d1a0c typing: disable a bogus attribute-error warning in phabricator
Matt Harbison <matt_harbison@yahoo.com>
parents: 49931
diff changeset
366 # .items() will only be called for a dict type
92743e6d1a0c typing: disable a bogus attribute-error warning in phabricator
Matt Harbison <matt_harbison@yahoo.com>
parents: 49931
diff changeset
367 # pytype: disable=attribute-error
41905
47125193bad0 py3: convert indexes into bytes when enumerating lists in urlencodenested
Ian Moody <moz-ian@perix.co.uk>
parents: 41904
diff changeset
368 items = {list: lister, dict: lambda x: x.items()}.get(type(obj))
49945
92743e6d1a0c typing: disable a bogus attribute-error warning in phabricator
Matt Harbison <matt_harbison@yahoo.com>
parents: 49931
diff changeset
369 # pytype: enable=attribute-error
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
370 if items is None:
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
371 flatparams[prefix] = obj
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
372 else:
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
373 for k, v in items(obj):
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
374 if prefix:
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
375 process(b'%s[%s]' % (prefix, k), v)
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
376 else:
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
377 process(k, v)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
378
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
379 process(b'', params)
46907
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46041
diff changeset
380 return urlutil.urlreq.urlencode(flatparams)
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
381
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
382
42449
500b64c5d991 phabricator: pass ui into readurltoken instead of passing repo
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42447
diff changeset
383 def readurltoken(ui):
38039
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 38020
diff changeset
384 """return conduit url, token and make sure they exist
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 38020
diff changeset
385
38040
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 38039
diff changeset
386 Currently read from [auth] config section. In the future, it might
38039
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 38020
diff changeset
387 make sense to read from .arcconfig and .arcrc as well.
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 38020
diff changeset
388 """
42449
500b64c5d991 phabricator: pass ui into readurltoken instead of passing repo
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42447
diff changeset
389 url = ui.config(b'phabricator', b'url')
38039
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 38020
diff changeset
390 if not url:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
391 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
392 _(b'config %s.%s is required') % (b'phabricator', b'url')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
393 )
38039
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 38020
diff changeset
394
46907
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46041
diff changeset
395 res = httpconnectionmod.readauthforuri(ui, url, urlutil.url(url).user)
38040
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 38039
diff changeset
396 token = None
38039
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 38020
diff changeset
397
38040
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 38039
diff changeset
398 if res:
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 38039
diff changeset
399 group, auth = res
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 38039
diff changeset
400
42449
500b64c5d991 phabricator: pass ui into readurltoken instead of passing repo
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42447
diff changeset
401 ui.debug(b"using auth.%s.* for authentication\n" % group)
38040
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 38039
diff changeset
402
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
403 token = auth.get(b'phabtoken')
38039
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 38020
diff changeset
404
36795
4397909f82d3 phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents: 36543
diff changeset
405 if not token:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
406 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
407 _(b'Can\'t find conduit token associated to %s') % (url,)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
408 )
36795
4397909f82d3 phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents: 36543
diff changeset
409
4397909f82d3 phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents: 36543
diff changeset
410 return url, token
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
411
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
412
42450
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42449
diff changeset
413 def callconduit(ui, name, params):
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
414 """call Conduit API, params is a dict. return json.loads result, or None"""
42450
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42449
diff changeset
415 host, token = readurltoken(ui)
47027
067f2c53fb24 phabricator: adapt to the new `urlutil.url()` API
Matt Harbison <matt_harbison@yahoo.com>
parents: 46907
diff changeset
416 url, authinfo = urlutil.url(b'/'.join([host, b'api', name])).authinfo()
42450
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42449
diff changeset
417 ui.debug(b'Conduit Call: %s %s\n' % (url, pycompat.byterepr(params)))
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
418 params = params.copy()
43261
f5aa4a53acd1 phabricator: change conduit data format to match arcanist
Ian Moody <moz-ian@perix.co.uk>
parents: 43259
diff changeset
419 params[b'__conduit__'] = {
f5aa4a53acd1 phabricator: change conduit data format to match arcanist
Ian Moody <moz-ian@perix.co.uk>
parents: 43259
diff changeset
420 b'token': token,
f5aa4a53acd1 phabricator: change conduit data format to match arcanist
Ian Moody <moz-ian@perix.co.uk>
parents: 43259
diff changeset
421 }
f5aa4a53acd1 phabricator: change conduit data format to match arcanist
Ian Moody <moz-ian@perix.co.uk>
parents: 43259
diff changeset
422 rawdata = {
f5aa4a53acd1 phabricator: change conduit data format to match arcanist
Ian Moody <moz-ian@perix.co.uk>
parents: 43259
diff changeset
423 b'params': templatefilters.json(params),
f5aa4a53acd1 phabricator: change conduit data format to match arcanist
Ian Moody <moz-ian@perix.co.uk>
parents: 43259
diff changeset
424 b'output': b'json',
f5aa4a53acd1 phabricator: change conduit data format to match arcanist
Ian Moody <moz-ian@perix.co.uk>
parents: 43259
diff changeset
425 b'__conduit__': 1,
f5aa4a53acd1 phabricator: change conduit data format to match arcanist
Ian Moody <moz-ian@perix.co.uk>
parents: 43259
diff changeset
426 }
f5aa4a53acd1 phabricator: change conduit data format to match arcanist
Ian Moody <moz-ian@perix.co.uk>
parents: 43259
diff changeset
427 data = urlencodenested(rawdata)
42450
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42449
diff changeset
428 curlcmd = ui.config(b'phabricator', b'curlcmd')
34081
8b659b7388c0 phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents: 34080
diff changeset
429 if curlcmd:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
430 sin, sout = procutil.popen2(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
431 b'%s -d @- %s' % (curlcmd, procutil.shellquote(url))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
432 )
34081
8b659b7388c0 phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents: 34080
diff changeset
433 sin.write(data)
8b659b7388c0 phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents: 34080
diff changeset
434 sin.close()
8b659b7388c0 phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents: 34080
diff changeset
435 body = sout.read()
8b659b7388c0 phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents: 34080
diff changeset
436 else:
42450
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42449
diff changeset
437 urlopener = urlmod.opener(ui, authinfo)
41906
a98dabdb5a7b py3: convert URL to str before passing it to request
Ian Moody <moz-ian@perix.co.uk>
parents: 41905
diff changeset
438 request = util.urlreq.request(pycompat.strurl(url), data=data)
45984
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
439 max_try = ui.configint(b'phabricator', b'retry') + 1
45985
4d70444c3ea9 phabricator: use the `http.timeout` config for conduit call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45984
diff changeset
440 timeout = ui.configwith(float, b'http', b'timeout')
45984
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
441 for try_count in range(max_try):
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
442 try:
45985
4d70444c3ea9 phabricator: use the `http.timeout` config for conduit call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45984
diff changeset
443 with contextlib.closing(
4d70444c3ea9 phabricator: use the `http.timeout` config for conduit call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45984
diff changeset
444 urlopener.open(request, timeout=timeout)
4d70444c3ea9 phabricator: use the `http.timeout` config for conduit call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45984
diff changeset
445 ) as rsp:
45984
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
446 body = rsp.read()
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
447 break
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
448 except util.urlerr.urlerror as err:
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
449 if try_count == max_try - 1:
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
450 raise
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
451 ui.debug(
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
452 b'Conduit Request failed (try %d/%d): %r\n'
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
453 % (try_count + 1, max_try, err)
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
454 )
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
455 # failing request might come from overloaded server
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
456 retry_interval = ui.configint(b'phabricator', b'retry.interval')
57183111a463 phabricator: introduce a `phabricator.retry` option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45957
diff changeset
457 time.sleep(retry_interval)
42450
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42449
diff changeset
458 ui.debug(b'Conduit Response: %s\n' % body)
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
459 parsed = pycompat.rapply(
49025
06de08b36c82 py3: use str instead of pycompat.unicode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 49004
diff changeset
460 lambda x: encoding.unitolocal(x) if isinstance(x, str) else x,
43047
0f90c2d2d7e8 py3: fix phabricator's use of json.loads() for py3.5
Ian Moody <moz-ian@perix.co.uk>
parents: 42975
diff changeset
461 # json.loads only accepts bytes from py3.6+
43380
579672b347d2 py3: define and use json.loads polyfill
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43350
diff changeset
462 pycompat.json_loads(encoding.unifromlocal(body)),
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
463 )
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
464 if parsed.get(b'error_code'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
465 msg = _(b'Conduit Error (%s): %s') % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
466 parsed[b'error_code'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
467 parsed[b'error_info'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
468 )
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
469 raise error.Abort(msg)
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
470 return parsed[b'result']
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
471
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
472
42451
16312ea45a8b phabricator: make `hg debugcallconduit` work outside a hg repo
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42450
diff changeset
473 @vcrcommand(b'debugcallconduit', [], _(b'METHOD'), optionalrepo=True)
33200
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
474 def debugcallconduit(ui, repo, name):
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
475 """call Conduit API
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
476
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
477 Call parameters are read from stdin as a JSON blob. Result will be written
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
478 to stdout as a JSON blob.
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
479 """
41976
99e00e5c4746 py3: convert to/from bytes/unicode for json.(dump|load)s in debugcallconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41975
diff changeset
480 # json.loads only accepts bytes from 3.6+
99e00e5c4746 py3: convert to/from bytes/unicode for json.(dump|load)s in debugcallconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41975
diff changeset
481 rawparams = encoding.unifromlocal(ui.fin.read())
99e00e5c4746 py3: convert to/from bytes/unicode for json.(dump|load)s in debugcallconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41975
diff changeset
482 # json.loads only returns unicode strings
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
483 params = pycompat.rapply(
49025
06de08b36c82 py3: use str instead of pycompat.unicode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 49004
diff changeset
484 lambda x: encoding.unitolocal(x) if isinstance(x, str) else x,
43380
579672b347d2 py3: define and use json.loads polyfill
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43350
diff changeset
485 pycompat.json_loads(rawparams),
41976
99e00e5c4746 py3: convert to/from bytes/unicode for json.(dump|load)s in debugcallconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41975
diff changeset
486 )
99e00e5c4746 py3: convert to/from bytes/unicode for json.(dump|load)s in debugcallconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41975
diff changeset
487 # json.dumps only accepts unicode strings
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
488 result = pycompat.rapply(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
489 lambda x: encoding.unifromlocal(x) if isinstance(x, bytes) else x,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
490 callconduit(ui, name, params),
41976
99e00e5c4746 py3: convert to/from bytes/unicode for json.(dump|load)s in debugcallconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41975
diff changeset
491 )
99e00e5c4746 py3: convert to/from bytes/unicode for json.(dump|load)s in debugcallconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41975
diff changeset
492 s = json.dumps(result, sort_keys=True, indent=2, separators=(u',', u': '))
99e00e5c4746 py3: convert to/from bytes/unicode for json.(dump|load)s in debugcallconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41975
diff changeset
493 ui.write(b'%s\n' % encoding.unitolocal(s))
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
494
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
495
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
496 def getrepophid(repo):
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
497 """given callsign, return repository PHID or None"""
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
498 # developer config: phabricator.repophid
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
499 repophid = repo.ui.config(b'phabricator', b'repophid')
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
500 if repophid:
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
501 return repophid
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
502 callsign = repo.ui.config(b'phabricator', b'callsign')
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
503 if not callsign:
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
504 return None
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
505 query = callconduit(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
506 repo.ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
507 b'diffusion.repository.search',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
508 {b'constraints': {b'callsigns': [callsign]}},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
509 )
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
510 if len(query[b'data']) == 0:
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
511 return None
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
512 repophid = query[b'data'][0][b'phid']
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
513 repo.ui.setconfig(b'phabricator', b'repophid', repophid)
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
514 return repophid
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
515
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
516
41546
bd3f03d8cc9f global: use raw strings for regular expressions with escapes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41387
diff changeset
517 _differentialrevisiontagre = re.compile(br'\AD([1-9][0-9]*)\Z')
33263
ed61189763ef phabricator: check associated Differential Revision from commit message
Jun Wu <quark@fb.com>
parents: 33202
diff changeset
518 _differentialrevisiondescre = re.compile(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
519 br'^Differential Revision:\s*(?P<url>(?:.*)D(?P<id>[1-9][0-9]*))$', re.M
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
520 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
521
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
522
33442
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
523 def getoldnodedrevmap(repo, nodelist):
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
524 """find previous nodes that has been sent to Phabricator
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
525
33717
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
526 return {node: (oldnode, Differential diff, Differential Revision ID)}
33442
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
527 for node in nodelist with known previous sent versions, or associated
33717
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
528 Differential Revision IDs. ``oldnode`` and ``Differential diff`` could
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
529 be ``None``.
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
530
33717
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
531 Examines commit messages like "Differential Revision:" to get the
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
532 association information.
33263
ed61189763ef phabricator: check associated Differential Revision from commit message
Jun Wu <quark@fb.com>
parents: 33202
diff changeset
533
33717
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
534 If such commit message line is not found, examines all precursors and their
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
535 tags. Tags with format like "D1234" are considered a match and the node
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
536 with that tag, and the number after "D" (ex. 1234) will be returned.
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
537
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
538 The ``old node``, if not None, is guaranteed to be the last diff of
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
539 corresponding Differential Revision, and exist in the repo.
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
540 """
33442
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
541 unfi = repo.unfiltered()
43597
4cb3f5bb29ec index: use `index.has_node` in `phabricator.getoldnodedrevmap`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
542 has_node = unfi.changelog.index.has_node
33263
ed61189763ef phabricator: check associated Differential Revision from commit message
Jun Wu <quark@fb.com>
parents: 33202
diff changeset
543
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
544 result = {} # {node: (oldnode?, lastdiff?, drev)}
44715
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
545 # ordered for test stability when printing new -> old mapping below
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
546 toconfirm = util.sortdict() # {node: (force, {precnode}, drev)}
33442
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
547 for node in nodelist:
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
548 ctx = unfi[node]
33443
e48082e0a8d5 phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
549 # For tags like "D123", put them into "toconfirm" to verify later
33761
e6d8ee3c9ec3 obsutil: rename allprecursors into allpredecessors
Boris Feld <boris.feld@octobus.net>
parents: 33718
diff changeset
550 precnodes = list(obsutil.allpredecessors(unfi.obsstore, [node]))
33443
e48082e0a8d5 phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
551 for n in precnodes:
43597
4cb3f5bb29ec index: use `index.has_node` in `phabricator.getoldnodedrevmap`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
552 if has_node(n):
33442
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
553 for tag in unfi.nodetags(n):
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
554 m = _differentialrevisiontagre.match(tag)
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
555 if m:
33717
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
556 toconfirm[node] = (0, set(precnodes), int(m.group(1)))
43847
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43597
diff changeset
557 break
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43597
diff changeset
558 else:
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43597
diff changeset
559 continue # move to next predecessor
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43597
diff changeset
560 break # found a tag, stop
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43597
diff changeset
561 else:
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43597
diff changeset
562 # Check commit message
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43597
diff changeset
563 m = _differentialrevisiondescre.search(ctx.description())
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43597
diff changeset
564 if m:
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43597
diff changeset
565 toconfirm[node] = (1, set(precnodes), int(m.group('id')))
33263
ed61189763ef phabricator: check associated Differential Revision from commit message
Jun Wu <quark@fb.com>
parents: 33202
diff changeset
566
33443
e48082e0a8d5 phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
567 # Double check if tags are genuine by collecting all old nodes from
e48082e0a8d5 phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
568 # Phabricator, and expect precursors overlap with it.
e48082e0a8d5 phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
569 if toconfirm:
33717
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
570 drevs = [drev for force, precs, drev in toconfirm.values()]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
571 alldiffs = callconduit(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
572 unfi.ui, b'differential.querydiffs', {b'revisionIDs': drevs}
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
573 )
44650
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
574
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
575 def getnodes(d, precset):
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
576 # Ignore other nodes that were combined into the Differential
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
577 # that aren't predecessors of the current local node.
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
578 return [n for n in getlocalcommits(d) if n in precset]
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
579
33717
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
580 for newnode, (force, precset, drev) in toconfirm.items():
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
581 diffs = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
582 d for d in alldiffs.values() if int(d[b'revisionID']) == drev
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
583 ]
33717
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
584
44650
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
585 # local predecessors known by Phabricator
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
586 phprecset = {n for d in diffs for n in getnodes(d, precset)}
33717
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
587
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
588 # Ignore if precursors (Phabricator and local repo) do not overlap,
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
589 # and force is not set (when commit message says nothing)
44650
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
590 if not force and not phprecset:
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
591 tagname = b'D%d' % drev
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
592 tags.tag(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
593 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
594 tagname,
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46907
diff changeset
595 repo.nullid,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
596 message=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
597 user=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
598 date=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
599 local=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
600 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
601 unfi.ui.warn(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
602 _(
43399
742065def6ca py3: use %d to format an int
Ian Moody <moz-ian@perix.co.uk>
parents: 43380
diff changeset
603 b'D%d: local tag removed - does not match '
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
604 b'Differential history\n'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
605 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
606 % drev
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
607 )
33717
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
608 continue
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
609
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
610 # Find the last node using Phabricator metadata, and make sure it
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
611 # exists in the repo
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
612 oldnode = lastdiff = None
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
613 if diffs:
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
614 lastdiff = max(diffs, key=lambda d: int(d[b'id']))
44650
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
615 oldnodes = getnodes(lastdiff, precset)
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
616
44715
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
617 _debug(
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
618 unfi.ui,
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
619 b"%s mapped to old nodes %s\n"
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
620 % (
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
621 short(newnode),
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
622 stringutil.pprint([short(n) for n in sorted(oldnodes)]),
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
623 ),
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
624 )
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
625
44650
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
626 # If this commit was the result of `hg fold` after submission,
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
627 # and now resubmitted with --fold, the easiest thing to do is
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
628 # to leave the node clear. This only results in creating a new
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
629 # diff for the _same_ Differential Revision if this commit is
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
630 # the first or last in the selected range. If we picked a node
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
631 # from the list instead, it would have to be the lowest if at
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
632 # the beginning of the --fold range, or the highest at the end.
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
633 # Otherwise, one or more of the nodes wouldn't be considered in
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
634 # the diff, and the Differential wouldn't be properly updated.
44650
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
635 # If this commit is the result of `hg split` in the same
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
636 # scenario, there is a single oldnode here (and multiple
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
637 # newnodes mapped to it). That makes it the same as the normal
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
638 # case, as the edges of the newnode range cleanly maps to one
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
639 # oldnode each.
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
640 if len(oldnodes) == 1:
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
641 oldnode = oldnodes[0]
43597
4cb3f5bb29ec index: use `index.has_node` in `phabricator.getoldnodedrevmap`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
642 if oldnode and not has_node(oldnode):
33717
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
643 oldnode = None
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
644
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
645 result[newnode] = (oldnode, lastdiff, drev)
33443
e48082e0a8d5 phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
646
33442
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
647 return result
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
648
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
649
43857
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
650 def getdrevmap(repo, revs):
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
651 """Return a dict mapping each rev in `revs` to their Differential Revision
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
652 ID or None.
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
653 """
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
654 result = {}
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
655 for rev in revs:
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
656 result[rev] = None
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
657 ctx = repo[rev]
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
658 # Check commit message
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
659 m = _differentialrevisiondescre.search(ctx.description())
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
660 if m:
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
661 result[rev] = int(m.group('id'))
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
662 continue
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
663 # Check tags
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
664 for tag in repo.nodetags(ctx.node()):
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
665 m = _differentialrevisiontagre.match(tag)
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
666 if m:
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
667 result[rev] = int(m.group(1))
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
668 break
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
669
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
670 return result
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
671
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
672
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
673 def getdiff(basectx, ctx, diffopts):
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
674 """plain-text diff without header (user, commit message, etc)"""
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
675 output = util.stringio()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
676 for chunk, _label in patch.diffui(
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
677 ctx.repo(), basectx.p1().node(), ctx.node(), None, opts=diffopts
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
678 ):
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
679 output.write(chunk)
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
680 return output.getvalue()
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
681
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
682
49037
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 49025
diff changeset
683 class DiffChangeType:
43182
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
684 ADD = 1
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
685 CHANGE = 2
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
686 DELETE = 3
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
687 MOVE_AWAY = 4
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
688 COPY_AWAY = 5
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
689 MOVE_HERE = 6
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
690 COPY_HERE = 7
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
691 MULTICOPY = 8
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
692
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
693
49037
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 49025
diff changeset
694 class DiffFileType:
43182
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
695 TEXT = 1
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
696 IMAGE = 2
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
697 BINARY = 3
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
698
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
699
43183
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
700 @attr.s
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
701 class phabhunk(dict):
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
702 """Represents a Differential hunk, which is owned by a Differential change"""
43183
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
703
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
704 oldOffset = attr.ib(default=0) # camelcase-required
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
705 oldLength = attr.ib(default=0) # camelcase-required
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
706 newOffset = attr.ib(default=0) # camelcase-required
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
707 newLength = attr.ib(default=0) # camelcase-required
51785
587153c96fe3 phabricator: correct the default value of `phabhunk.corpus`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51131
diff changeset
708 corpus = attr.ib(default=b'')
43183
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
709 # These get added to the phabchange's equivalents
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
710 addLines = attr.ib(default=0) # camelcase-required
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
711 delLines = attr.ib(default=0) # camelcase-required
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
712
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
713
43184
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
714 @attr.s
49037
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 49025
diff changeset
715 class phabchange:
43184
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
716 """Represents a Differential change, owns Differential hunks and owned by a
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
717 Differential diff. Each one represents one file in a diff.
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
718 """
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
719
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
720 currentPath = attr.ib(default=None) # camelcase-required
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
721 oldPath = attr.ib(default=None) # camelcase-required
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
722 awayPaths = attr.ib(default=attr.Factory(list)) # camelcase-required
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
723 metadata = attr.ib(default=attr.Factory(dict))
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
724 oldProperties = attr.ib(default=attr.Factory(dict)) # camelcase-required
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
725 newProperties = attr.ib(default=attr.Factory(dict)) # camelcase-required
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
726 type = attr.ib(default=DiffChangeType.CHANGE)
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
727 fileType = attr.ib(default=DiffFileType.TEXT) # camelcase-required
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
728 commitHash = attr.ib(default=None) # camelcase-required
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
729 addLines = attr.ib(default=0) # camelcase-required
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
730 delLines = attr.ib(default=0) # camelcase-required
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
731 hunks = attr.ib(default=attr.Factory(list))
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
732
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
733 def copynewmetadatatoold(self):
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
734 for key in list(self.metadata.keys()):
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
735 newkey = key.replace(b'new:', b'old:')
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
736 self.metadata[newkey] = self.metadata[key]
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
737
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
738 def addoldmode(self, value):
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
739 self.oldProperties[b'unix:filemode'] = value
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
740
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
741 def addnewmode(self, value):
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
742 self.newProperties[b'unix:filemode'] = value
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
743
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
744 def addhunk(self, hunk):
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
745 if not isinstance(hunk, phabhunk):
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
746 raise error.Abort(b'phabchange.addhunk only takes phabhunks')
43259
162b81e65e60 phabricator: convert phabhunk and phabchange keys to bytes when finalising
Ian Moody <moz-ian@perix.co.uk>
parents: 43258
diff changeset
747 self.hunks.append(pycompat.byteskwargs(attr.asdict(hunk)))
43184
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
748 # It's useful to include these stats since the Phab web UI shows them,
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
749 # and uses them to estimate how large a change a Revision is. Also used
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
750 # in email subjects for the [+++--] bit.
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
751 self.addLines += hunk.addLines
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
752 self.delLines += hunk.delLines
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
753
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
754
43185
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
755 @attr.s
49037
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 49025
diff changeset
756 class phabdiff:
43185
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
757 """Represents a Differential diff, owns Differential changes. Corresponds
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
758 to a commit.
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
759 """
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
760
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
761 # Doesn't seem to be any reason to send this (output of uname -n)
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
762 sourceMachine = attr.ib(default=b'') # camelcase-required
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
763 sourcePath = attr.ib(default=b'/') # camelcase-required
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
764 sourceControlBaseRevision = attr.ib(default=b'0' * 40) # camelcase-required
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
765 sourceControlPath = attr.ib(default=b'/') # camelcase-required
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
766 sourceControlSystem = attr.ib(default=b'hg') # camelcase-required
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
767 branch = attr.ib(default=b'default')
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
768 bookmark = attr.ib(default=None)
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
769 creationMethod = attr.ib(default=b'phabsend') # camelcase-required
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
770 lintStatus = attr.ib(default=b'none') # camelcase-required
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
771 unitStatus = attr.ib(default=b'none') # camelcase-required
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
772 changes = attr.ib(default=attr.Factory(dict))
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
773 repositoryPHID = attr.ib(default=None) # camelcase-required
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
774
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
775 def addchange(self, change):
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
776 if not isinstance(change, phabchange):
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
777 raise error.Abort(b'phabdiff.addchange only takes phabchanges')
43259
162b81e65e60 phabricator: convert phabhunk and phabchange keys to bytes when finalising
Ian Moody <moz-ian@perix.co.uk>
parents: 43258
diff changeset
778 self.changes[change.currentPath] = pycompat.byteskwargs(
162b81e65e60 phabricator: convert phabhunk and phabchange keys to bytes when finalising
Ian Moody <moz-ian@perix.co.uk>
parents: 43258
diff changeset
779 attr.asdict(change)
162b81e65e60 phabricator: convert phabhunk and phabchange keys to bytes when finalising
Ian Moody <moz-ian@perix.co.uk>
parents: 43258
diff changeset
780 )
43185
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
781
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
782
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
783 def maketext(pchange, basectx, ctx, fname):
43186
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
784 """populate the phabchange for a text file"""
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
785 repo = ctx.repo()
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
786 fmatcher = match.exact([fname])
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
787 diffopts = mdiff.diffopts(git=True, context=32767)
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
788 _pfctx, _fctx, header, fhunks = next(
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
789 patch.diffhunks(repo, basectx.p1(), ctx, fmatcher, opts=diffopts)
43186
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
790 )
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
791
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
792 for fhunk in fhunks:
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
793 (oldOffset, oldLength, newOffset, newLength), lines = fhunk
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
794 corpus = b''.join(lines[1:])
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
795 shunk = list(header)
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
796 shunk.extend(lines)
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
797 _mf, _mt, addLines, delLines, _hb = patch.diffstatsum(
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
798 patch.diffstatdata(util.iterlines(shunk))
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
799 )
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
800 pchange.addhunk(
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
801 phabhunk(
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
802 oldOffset,
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
803 oldLength,
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
804 newOffset,
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
805 newLength,
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
806 corpus,
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
807 addLines,
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
808 delLines,
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
809 )
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
810 )
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
811
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
812
43187
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
813 def uploadchunks(fctx, fphid):
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
814 """upload large binary files as separate chunks.
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
815 Phab requests chunking over 8MiB, and splits into 4MiB chunks
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
816 """
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
817 ui = fctx.repo().ui
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
818 chunks = callconduit(ui, b'file.querychunks', {b'filePHID': fphid})
43552
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
819 with ui.makeprogress(
43187
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
820 _(b'uploading file chunks'), unit=_(b'chunks'), total=len(chunks)
43552
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
821 ) as progress:
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
822 for chunk in chunks:
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
823 progress.increment()
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
824 if chunk[b'complete']:
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
825 continue
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
826 bstart = int(chunk[b'byteStart'])
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
827 bend = int(chunk[b'byteEnd'])
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
828 callconduit(
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
829 ui,
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
830 b'file.uploadchunk',
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
831 {
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
832 b'filePHID': fphid,
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
833 b'byteStart': bstart,
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
834 b'data': base64.b64encode(fctx.data()[bstart:bend]),
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
835 b'dataEncoding': b'base64',
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
836 },
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
837 )
43187
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
838
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
839
43188
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
840 def uploadfile(fctx):
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
841 """upload binary files to Phabricator"""
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
842 repo = fctx.repo()
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
843 ui = repo.ui
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
844 fname = fctx.path()
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
845 size = fctx.size()
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
846 fhash = pycompat.bytestr(hashlib.sha256(fctx.data()).hexdigest())
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
847
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
848 # an allocate call is required first to see if an upload is even required
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
849 # (Phab might already have it) and to determine if chunking is needed
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
850 allocateparams = {
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
851 b'name': fname,
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
852 b'contentLength': size,
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
853 b'contentHash': fhash,
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
854 }
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
855 filealloc = callconduit(ui, b'file.allocate', allocateparams)
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
856 fphid = filealloc[b'filePHID']
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
857
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
858 if filealloc[b'upload']:
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
859 ui.write(_(b'uploading %s\n') % bytes(fctx))
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
860 if not fphid:
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
861 uploadparams = {
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
862 b'name': fname,
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
863 b'data_base64': base64.b64encode(fctx.data()),
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
864 }
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
865 fphid = callconduit(ui, b'file.upload', uploadparams)
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
866 else:
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
867 uploadchunks(fctx, fphid)
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
868 else:
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
869 ui.debug(b'server already has %s\n' % bytes(fctx))
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
870
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
871 if not fphid:
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
872 raise error.Abort(b'Upload of %s failed.' % bytes(fctx))
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
873
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
874 return fphid
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
875
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
876
44449
98f7b9cf7bfc phabricator: pass old `fctx` to `addoldbinary()` instead of inferring it
Matt Harbison <matt_harbison@yahoo.com>
parents: 44448
diff changeset
877 def addoldbinary(pchange, oldfctx, fctx):
43189
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
878 """add the metadata for the previous version of a binary file to the
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
879 phabchange for the new version
44449
98f7b9cf7bfc phabricator: pass old `fctx` to `addoldbinary()` instead of inferring it
Matt Harbison <matt_harbison@yahoo.com>
parents: 44448
diff changeset
880
98f7b9cf7bfc phabricator: pass old `fctx` to `addoldbinary()` instead of inferring it
Matt Harbison <matt_harbison@yahoo.com>
parents: 44448
diff changeset
881 ``oldfctx`` is the previous version of the file; ``fctx`` is the new
98f7b9cf7bfc phabricator: pass old `fctx` to `addoldbinary()` instead of inferring it
Matt Harbison <matt_harbison@yahoo.com>
parents: 44448
diff changeset
882 version of the file, or None if the file is being removed.
43189
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
883 """
44449
98f7b9cf7bfc phabricator: pass old `fctx` to `addoldbinary()` instead of inferring it
Matt Harbison <matt_harbison@yahoo.com>
parents: 44448
diff changeset
884 if not fctx or fctx.cmp(oldfctx):
43189
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
885 # Files differ, add the old one
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
886 pchange.metadata[b'old:file:size'] = oldfctx.size()
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
887 mimeguess, _enc = mimetypes.guess_type(
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
888 encoding.unifromlocal(oldfctx.path())
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
889 )
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
890 if mimeguess:
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
891 pchange.metadata[b'old:file:mime-type'] = pycompat.bytestr(
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
892 mimeguess
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
893 )
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
894 fphid = uploadfile(oldfctx)
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
895 pchange.metadata[b'old:binary-phid'] = fphid
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
896 else:
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
897 # If it's left as IMAGE/BINARY web UI might try to display it
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
898 pchange.fileType = DiffFileType.TEXT
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
899 pchange.copynewmetadatatoold()
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
900
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
901
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
902 def makebinary(pchange, fctx):
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
903 """populate the phabchange for a binary file"""
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
904 pchange.fileType = DiffFileType.BINARY
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
905 fphid = uploadfile(fctx)
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
906 pchange.metadata[b'new:binary-phid'] = fphid
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
907 pchange.metadata[b'new:file:size'] = fctx.size()
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
908 mimeguess, _enc = mimetypes.guess_type(encoding.unifromlocal(fctx.path()))
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
909 if mimeguess:
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
910 mimeguess = pycompat.bytestr(mimeguess)
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
911 pchange.metadata[b'new:file:mime-type'] = mimeguess
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
912 if mimeguess.startswith(b'image/'):
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
913 pchange.fileType = DiffFileType.IMAGE
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
914
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
915
43190
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
916 # Copied from mercurial/patch.py
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
917 gitmode = {b'l': b'120000', b'x': b'100755', b'': b'100644'}
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
918
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
919
43263
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
920 def notutf8(fctx):
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
921 """detect non-UTF-8 text files since Phabricator requires them to be marked
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
922 as binary
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
923 """
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
924 try:
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
925 fctx.data().decode('utf-8')
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
926 return False
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
927 except UnicodeDecodeError:
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
928 fctx.repo().ui.write(
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
929 _(b'file %s detected as non-UTF-8, marked as binary\n')
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
930 % fctx.path()
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
931 )
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
932 return True
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
933
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
934
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
935 def addremoved(pdiff, basectx, ctx, removed):
43190
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
936 """add removed files to the phabdiff. Shouldn't include moves"""
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
937 for fname in removed:
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
938 pchange = phabchange(
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
939 currentPath=fname, oldPath=fname, type=DiffChangeType.DELETE
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
940 )
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
941 oldfctx = basectx.p1()[fname]
44613
7b9aaec17126 phabricator: eliminate a couple of duplicate filectx lookups
Matt Harbison <matt_harbison@yahoo.com>
parents: 44593
diff changeset
942 pchange.addoldmode(gitmode[oldfctx.flags()])
44450
aa9979bb6853 phabricator: rename a variable to clarify that it is the parent filecontext
Matt Harbison <matt_harbison@yahoo.com>
parents: 44449
diff changeset
943 if not (oldfctx.isbinary() or notutf8(oldfctx)):
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
944 maketext(pchange, basectx, ctx, fname)
43190
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
945
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
946 pdiff.addchange(pchange)
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
947
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
948
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
949 def addmodified(pdiff, basectx, ctx, modified):
43190
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
950 """add modified files to the phabdiff"""
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
951 for fname in modified:
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
952 fctx = ctx[fname]
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
953 oldfctx = basectx.p1()[fname]
43190
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
954 pchange = phabchange(currentPath=fname, oldPath=fname)
44613
7b9aaec17126 phabricator: eliminate a couple of duplicate filectx lookups
Matt Harbison <matt_harbison@yahoo.com>
parents: 44593
diff changeset
955 filemode = gitmode[fctx.flags()]
7b9aaec17126 phabricator: eliminate a couple of duplicate filectx lookups
Matt Harbison <matt_harbison@yahoo.com>
parents: 44593
diff changeset
956 originalmode = gitmode[oldfctx.flags()]
43190
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
957 if filemode != originalmode:
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
958 pchange.addoldmode(originalmode)
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
959 pchange.addnewmode(filemode)
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
960
44452
4ce2330f2d0b phabricator: also check parent fctx for binary where it is checked for UTF-8
Matt Harbison <matt_harbison@yahoo.com>
parents: 44451
diff changeset
961 if (
4ce2330f2d0b phabricator: also check parent fctx for binary where it is checked for UTF-8
Matt Harbison <matt_harbison@yahoo.com>
parents: 44451
diff changeset
962 fctx.isbinary()
4ce2330f2d0b phabricator: also check parent fctx for binary where it is checked for UTF-8
Matt Harbison <matt_harbison@yahoo.com>
parents: 44451
diff changeset
963 or notutf8(fctx)
4ce2330f2d0b phabricator: also check parent fctx for binary where it is checked for UTF-8
Matt Harbison <matt_harbison@yahoo.com>
parents: 44451
diff changeset
964 or oldfctx.isbinary()
4ce2330f2d0b phabricator: also check parent fctx for binary where it is checked for UTF-8
Matt Harbison <matt_harbison@yahoo.com>
parents: 44451
diff changeset
965 or notutf8(oldfctx)
4ce2330f2d0b phabricator: also check parent fctx for binary where it is checked for UTF-8
Matt Harbison <matt_harbison@yahoo.com>
parents: 44451
diff changeset
966 ):
43190
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
967 makebinary(pchange, fctx)
44613
7b9aaec17126 phabricator: eliminate a couple of duplicate filectx lookups
Matt Harbison <matt_harbison@yahoo.com>
parents: 44593
diff changeset
968 addoldbinary(pchange, oldfctx, fctx)
43190
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
969 else:
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
970 maketext(pchange, basectx, ctx, fname)
43190
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
971
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
972 pdiff.addchange(pchange)
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
973
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
974
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
975 def addadded(pdiff, basectx, ctx, added, removed):
43258
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
976 """add file adds to the phabdiff, both new files and copies/moves"""
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
977 # Keep track of files that've been recorded as moved/copied, so if there are
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
978 # additional copies we can mark them (moves get removed from removed)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
979 copiedchanges = {}
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
980 movedchanges = {}
44615
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44614
diff changeset
981
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44614
diff changeset
982 copy = {}
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44614
diff changeset
983 if basectx != ctx:
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44614
diff changeset
984 copy = copies.pathcopies(basectx.p1(), ctx)
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44614
diff changeset
985
43258
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
986 for fname in added:
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
987 fctx = ctx[fname]
44451
66a05dbb8b4c phabricator: don't infer the old `fctx` in `notutf8()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44450
diff changeset
988 oldfctx = None
43258
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
989 pchange = phabchange(currentPath=fname)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
990
44613
7b9aaec17126 phabricator: eliminate a couple of duplicate filectx lookups
Matt Harbison <matt_harbison@yahoo.com>
parents: 44593
diff changeset
991 filemode = gitmode[fctx.flags()]
44615
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44614
diff changeset
992
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44614
diff changeset
993 if copy:
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44614
diff changeset
994 originalfname = copy.get(fname, fname)
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44614
diff changeset
995 else:
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44614
diff changeset
996 originalfname = fname
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44614
diff changeset
997 if fctx.renamed():
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44614
diff changeset
998 originalfname = fctx.renamed()[0]
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44614
diff changeset
999
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44614
diff changeset
1000 renamed = fname != originalfname
43258
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1001
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1002 if renamed:
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
1003 oldfctx = basectx.p1()[originalfname]
44451
66a05dbb8b4c phabricator: don't infer the old `fctx` in `notutf8()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44450
diff changeset
1004 originalmode = gitmode[oldfctx.flags()]
43258
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1005 pchange.oldPath = originalfname
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1006
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1007 if originalfname in removed:
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1008 origpchange = phabchange(
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1009 currentPath=originalfname,
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1010 oldPath=originalfname,
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1011 type=DiffChangeType.MOVE_AWAY,
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1012 awayPaths=[fname],
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1013 )
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1014 movedchanges[originalfname] = origpchange
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1015 removed.remove(originalfname)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1016 pchange.type = DiffChangeType.MOVE_HERE
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1017 elif originalfname in movedchanges:
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1018 movedchanges[originalfname].type = DiffChangeType.MULTICOPY
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1019 movedchanges[originalfname].awayPaths.append(fname)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1020 pchange.type = DiffChangeType.COPY_HERE
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1021 else: # pure copy
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1022 if originalfname not in copiedchanges:
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1023 origpchange = phabchange(
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1024 currentPath=originalfname, type=DiffChangeType.COPY_AWAY
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1025 )
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1026 copiedchanges[originalfname] = origpchange
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1027 else:
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1028 origpchange = copiedchanges[originalfname]
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1029 origpchange.awayPaths.append(fname)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1030 pchange.type = DiffChangeType.COPY_HERE
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1031
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1032 if filemode != originalmode:
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1033 pchange.addoldmode(originalmode)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1034 pchange.addnewmode(filemode)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1035 else: # Brand-new file
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1036 pchange.addnewmode(gitmode[fctx.flags()])
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1037 pchange.type = DiffChangeType.ADD
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1038
44452
4ce2330f2d0b phabricator: also check parent fctx for binary where it is checked for UTF-8
Matt Harbison <matt_harbison@yahoo.com>
parents: 44451
diff changeset
1039 if (
4ce2330f2d0b phabricator: also check parent fctx for binary where it is checked for UTF-8
Matt Harbison <matt_harbison@yahoo.com>
parents: 44451
diff changeset
1040 fctx.isbinary()
4ce2330f2d0b phabricator: also check parent fctx for binary where it is checked for UTF-8
Matt Harbison <matt_harbison@yahoo.com>
parents: 44451
diff changeset
1041 or notutf8(fctx)
4ce2330f2d0b phabricator: also check parent fctx for binary where it is checked for UTF-8
Matt Harbison <matt_harbison@yahoo.com>
parents: 44451
diff changeset
1042 or (oldfctx and (oldfctx.isbinary() or notutf8(oldfctx)))
4ce2330f2d0b phabricator: also check parent fctx for binary where it is checked for UTF-8
Matt Harbison <matt_harbison@yahoo.com>
parents: 44451
diff changeset
1043 ):
43258
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1044 makebinary(pchange, fctx)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1045 if renamed:
44451
66a05dbb8b4c phabricator: don't infer the old `fctx` in `notutf8()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44450
diff changeset
1046 addoldbinary(pchange, oldfctx, fctx)
43258
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1047 else:
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
1048 maketext(pchange, basectx, ctx, fname)
43258
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1049
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1050 pdiff.addchange(pchange)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1051
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1052 for _path, copiedchange in copiedchanges.items():
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1053 pdiff.addchange(copiedchange)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1054 for _path, movedchange in movedchanges.items():
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1055 pdiff.addchange(movedchange)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1056
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
1057
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
1058 def creatediff(basectx, ctx):
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1059 """create a Differential Diff"""
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1060 repo = ctx.repo()
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1061 repophid = getrepophid(repo)
43262
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1062 # Create a "Differential Diff" via "differential.creatediff" API
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1063 pdiff = phabdiff(
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
1064 sourceControlBaseRevision=b'%s' % basectx.p1().hex(),
43262
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1065 branch=b'%s' % ctx.branch(),
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1066 )
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
1067 modified, added, removed, _d, _u, _i, _c = basectx.p1().status(ctx)
43262
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1068 # addadded will remove moved files from removed, so addremoved won't get
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1069 # them
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
1070 addadded(pdiff, basectx, ctx, added, removed)
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
1071 addmodified(pdiff, basectx, ctx, modified)
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
1072 addremoved(pdiff, basectx, ctx, removed)
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1073 if repophid:
43262
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1074 pdiff.repositoryPHID = repophid
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1075 diff = callconduit(
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1076 repo.ui,
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1077 b'differential.creatediff',
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1078 pycompat.byteskwargs(attr.asdict(pdiff)),
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1079 )
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1080 if not diff:
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
1081 if basectx != ctx:
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
1082 msg = _(b'cannot create diff for %s::%s') % (basectx, ctx)
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
1083 else:
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
1084 msg = _(b'cannot create diff for %s') % ctx
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
1085 raise error.Abort(msg)
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1086 return diff
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1087
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1088
44647
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1089 def writediffproperties(ctxs, diff):
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1090 """write metadata to diff so patches could be applied losslessly
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1091
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1092 ``ctxs`` is the list of commits that created the diff, in ascending order.
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1093 The list is generally a single commit, but may be several when using
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1094 ``phabsend --fold``.
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1095 """
43262
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1096 # creatediff returns with a diffid but query returns with an id
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1097 diffid = diff.get(b'diffid', diff.get(b'id'))
44647
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1098 basectx = ctxs[0]
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1099 tipctx = ctxs[-1]
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1100
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1101 params = {
43262
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1102 b'diff_id': diffid,
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1103 b'name': b'hg:meta',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1104 b'data': templatefilters.json(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1105 {
44647
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1106 b'user': tipctx.user(),
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1107 b'date': b'%d %d' % tipctx.date(),
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1108 b'branch': tipctx.branch(),
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1109 b'node': tipctx.hex(),
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1110 b'parent': basectx.p1().hex(),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1111 }
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1112 ),
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1113 }
44647
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1114 callconduit(basectx.repo().ui, b'differential.setdiffproperty', params)
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1115
44647
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1116 commits = {}
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1117 for ctx in ctxs:
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1118 commits[ctx.hex()] = {
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1119 b'author': stringutil.person(ctx.user()),
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1120 b'authorEmail': stringutil.email(ctx.user()),
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1121 b'time': int(ctx.date()[0]),
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1122 b'commit': ctx.hex(),
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1123 b'parents': [ctx.p1().hex()],
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1124 b'branch': ctx.branch(),
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1125 }
37800
6cf5f5b4eb57 phabricator: specify some metadata compatibly with arc
Tom Prince <mozilla@hocat.ca>
parents: 37123
diff changeset
1126 params = {
43262
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1127 b'diff_id': diffid,
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1128 b'name': b'local:commits',
44647
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1129 b'data': templatefilters.json(commits),
37800
6cf5f5b4eb57 phabricator: specify some metadata compatibly with arc
Tom Prince <mozilla@hocat.ca>
parents: 37123
diff changeset
1130 }
44647
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44615
diff changeset
1131 callconduit(basectx.repo().ui, b'differential.setdiffproperty', params)
37800
6cf5f5b4eb57 phabricator: specify some metadata compatibly with arc
Tom Prince <mozilla@hocat.ca>
parents: 37123
diff changeset
1132
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1133
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1134 def createdifferentialrevision(
44649
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1135 ctxs,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1136 revid=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1137 parentrevphid=None,
44649
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1138 oldbasenode=None,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1139 oldnode=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1140 olddiff=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1141 actions=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1142 comment=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1143 ):
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1144 """create or update a Differential Revision
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1145
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1146 If revid is None, create a new Differential Revision, otherwise update
42465
c19d259fd6ad phabricator: use parents.set to always set dependencies
Ian Moody <moz-ian@perix.co.uk>
parents: 42460
diff changeset
1147 revid. If parentrevphid is not None, set it as a dependency.
33265
95f658b558a3 phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents: 33264
diff changeset
1148
44649
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1149 If there is a single commit for the new Differential Revision, ``ctxs`` will
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1150 be a list of that single context. Otherwise, it is a list that covers the
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1151 range of changes for the differential, where ``ctxs[0]`` is the first change
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1152 to include and ``ctxs[-1]`` is the last.
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1153
33265
95f658b558a3 phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents: 33264
diff changeset
1154 If oldnode is not None, check if the patch content (without commit message
44649
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1155 and metadata) has changed before creating another diff. For a Revision with
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1156 a single commit, ``oldbasenode`` and ``oldnode`` have the same value. For a
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1157 Revision covering multiple commits, ``oldbasenode`` corresponds to
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1158 ``ctxs[0]`` the previous time this Revision was posted, and ``oldnode``
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1159 corresponds to ``ctxs[-1]``.
33498
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1160
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1161 If actions is not None, they will be appended to the transaction.
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1162 """
44649
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1163 ctx = ctxs[-1]
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1164 basectx = ctxs[0]
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1165
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1166 repo = ctx.repo()
33265
95f658b558a3 phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents: 33264
diff changeset
1167 if oldnode:
33994
27ff2a87d8c0 phabsend: detect patch change with larger context
Jun Wu <quark@fb.com>
parents: 33993
diff changeset
1168 diffopts = mdiff.diffopts(git=True, context=32767)
44649
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1169 unfi = repo.unfiltered()
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1170 oldctx = unfi[oldnode]
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1171 oldbasectx = unfi[oldbasenode]
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
1172 neednewdiff = getdiff(basectx, ctx, diffopts) != getdiff(
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
1173 oldbasectx, oldctx, diffopts
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
1174 )
33265
95f658b558a3 phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents: 33264
diff changeset
1175 else:
95f658b558a3 phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents: 33264
diff changeset
1176 neednewdiff = True
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1177
33265
95f658b558a3 phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents: 33264
diff changeset
1178 transactions = []
95f658b558a3 phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents: 33264
diff changeset
1179 if neednewdiff:
44614
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44613
diff changeset
1180 diff = creatediff(basectx, ctx)
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1181 transactions.append({b'type': b'update', b'value': diff[b'phid']})
42447
29528c4235a1 phabricator: add commenting to phabsend for new/updated Diffs
Ian Moody <moz-ian@perix.co.uk>
parents: 42295
diff changeset
1182 if comment:
29528c4235a1 phabricator: add commenting to phabsend for new/updated Diffs
Ian Moody <moz-ian@perix.co.uk>
parents: 42295
diff changeset
1183 transactions.append({b'type': b'comment', b'value': comment})
33718
f100354cce52 phabricator: update diff property even if we choose not to create a new diff
Jun Wu <quark@fb.com>
parents: 33717
diff changeset
1184 else:
f100354cce52 phabricator: update diff property even if we choose not to create a new diff
Jun Wu <quark@fb.com>
parents: 33717
diff changeset
1185 # Even if we don't need to upload a new diff because the patch content
f100354cce52 phabricator: update diff property even if we choose not to create a new diff
Jun Wu <quark@fb.com>
parents: 33717
diff changeset
1186 # does not change. We might still need to update its metadata so
f100354cce52 phabricator: update diff property even if we choose not to create a new diff
Jun Wu <quark@fb.com>
parents: 33717
diff changeset
1187 # pushers could know the correct node metadata.
f100354cce52 phabricator: update diff property even if we choose not to create a new diff
Jun Wu <quark@fb.com>
parents: 33717
diff changeset
1188 assert olddiff
f100354cce52 phabricator: update diff property even if we choose not to create a new diff
Jun Wu <quark@fb.com>
parents: 33717
diff changeset
1189 diff = olddiff
44649
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1190 writediffproperties(ctxs, diff)
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1191
42465
c19d259fd6ad phabricator: use parents.set to always set dependencies
Ian Moody <moz-ian@perix.co.uk>
parents: 42460
diff changeset
1192 # Set the parent Revision every time, so commit re-ordering is picked-up
c19d259fd6ad phabricator: use parents.set to always set dependencies
Ian Moody <moz-ian@perix.co.uk>
parents: 42460
diff changeset
1193 if parentrevphid:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1194 transactions.append(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1195 {b'type': b'parents.set', b'value': [parentrevphid]}
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1196 )
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1197
33498
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1198 if actions:
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1199 transactions += actions
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1200
44648
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1201 # When folding multiple local commits into a single review, arcanist will
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1202 # take the summary line of the first commit as the title, and then
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1203 # concatenate the rest of the remaining messages (including each of their
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1204 # first lines) to the rest of the first commit message (each separated by
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1205 # an empty line), and use that as the summary field. Do the same here.
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1206 # For commits with only a one line message, there is no summary field, as
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1207 # this gets assigned to the title.
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1208 fields = util.sortdict() # sorted for stable wire protocol in tests
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1209
44649
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1210 for i, _ctx in enumerate(ctxs):
44648
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1211 # Parse commit message and update related fields.
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1212 desc = _ctx.description()
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1213 info = callconduit(
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1214 repo.ui, b'differential.parsecommitmessage', {b'corpus': desc}
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1215 )
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1216
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1217 for k in [b'title', b'summary', b'testPlan']:
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1218 v = info[b'fields'].get(k)
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1219 if not v:
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1220 continue
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1221
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1222 if i == 0:
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1223 # Title, summary and test plan (if present) are taken verbatim
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1224 # for the first commit.
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1225 fields[k] = v.rstrip()
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1226 continue
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1227 elif k == b'title':
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1228 # Add subsequent titles (i.e. the first line of the commit
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1229 # message) back to the summary.
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1230 k = b'summary'
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1231
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1232 # Append any current field to the existing composite field
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1233 fields[k] = b'\n\n'.join(filter(None, [fields.get(k), v.rstrip()]))
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1234
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1235 for k, v in fields.items():
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1236 transactions.append({b'type': k, b'value': v})
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1237
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1238 params = {b'transactions': transactions}
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1239 if revid is not None:
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1240 # Update an existing Differential Revision
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1241 params[b'objectIdentifier'] = revid
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1242
42450
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42449
diff changeset
1243 revision = callconduit(repo.ui, b'differential.revision.edit', params)
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1244 if not revision:
44649
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1245 if len(ctxs) == 1:
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1246 msg = _(b'cannot create revision for %s') % ctx
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1247 else:
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1248 msg = _(b'cannot create revision for %s::%s') % (basectx, ctx)
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1249 raise error.Abort(msg)
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1250
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1251 return revision, diff
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1252
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1253
44445
ddcb51390891 phabricator: pass ui instead of repo to `userphids()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44444
diff changeset
1254 def userphids(ui, names):
33498
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1255 """convert user names to PHIDs"""
41716
570e62f1dcf2 phabricator: make user searches case-insensitive
Julien Cristau <jcristau@mozilla.com>
parents: 41546
diff changeset
1256 names = [name.lower() for name in names]
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1257 query = {b'constraints': {b'usernames': names}}
44445
ddcb51390891 phabricator: pass ui instead of repo to `userphids()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44444
diff changeset
1258 result = callconduit(ui, b'user.search', query)
33498
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1259 # username not found is not an error of the API. So check if we have missed
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1260 # some names here.
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1261 data = result[b'data']
44470
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 44456
diff changeset
1262 resolved = {entry[b'fields'][b'username'].lower() for entry in data}
33498
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1263 unresolved = set(names) - resolved
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1264 if unresolved:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1265 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1266 _(b'unknown username: %s') % b' '.join(sorted(unresolved))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1267 )
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1268 return [entry[b'phid'] for entry in data]
33498
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1269
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1270
44652
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1271 def _print_phabsend_action(ui, ctx, newrevid, action):
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1272 """print the ``action`` that occurred when posting ``ctx`` for review
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1273
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1274 This is a utility function for the sending phase of ``phabsend``, which
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1275 makes it easier to show a status for all local commits with `--fold``.
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1276 """
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1277 actiondesc = ui.label(
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1278 {
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1279 b'created': _(b'created'),
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1280 b'skipped': _(b'skipped'),
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1281 b'updated': _(b'updated'),
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1282 }[action],
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1283 b'phabricator.action.%s' % action,
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1284 )
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1285 drevdesc = ui.label(b'D%d' % newrevid, b'phabricator.drev')
45795
294aab57a5f3 phabsend: use default one-line summary
Martin von Zweigbergk <martinvonz@google.com>
parents: 45513
diff changeset
1286 summary = cmdutil.format_changeset_summary(ui, ctx, b'phabsend')
294aab57a5f3 phabsend: use default one-line summary
Martin von Zweigbergk <martinvonz@google.com>
parents: 45513
diff changeset
1287 ui.write(_(b'%s - %s - %s\n') % (drevdesc, actiondesc, summary))
44652
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1288
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1289
44651
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1290 def _amend_diff_properties(unfi, drevid, newnodes, diff):
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1291 """update the local commit list for the ``diff`` associated with ``drevid``
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1292
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1293 This is a utility function for the amend phase of ``phabsend``, which
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1294 converts failures to warning messages.
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1295 """
44715
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
1296 _debug(
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
1297 unfi.ui,
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
1298 b"new commits: %s\n" % stringutil.pprint([short(n) for n in newnodes]),
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
1299 )
38f7b2f02f6d phabricator: add debug logging to show previous node values in `phabsend`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44652
diff changeset
1300
44651
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1301 try:
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1302 writediffproperties([unfi[newnode] for newnode in newnodes], diff)
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1303 except util.urlerr.urlerror:
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1304 # If it fails just warn and keep going, otherwise the DREV
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1305 # associations will be lost
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1306 unfi.ui.warnnoi18n(b'Failed to update metadata for D%d\n' % drevid)
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1307
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1308
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1309 @vcrcommand(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1310 b'phabsend',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1311 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1312 (b'r', b'rev', [], _(b'revisions to send'), _(b'REV')),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1313 (b'', b'amend', True, _(b'update commit messages')),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1314 (b'', b'reviewer', [], _(b'specify reviewers')),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1315 (b'', b'blocker', [], _(b'specify blocking reviewers')),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1316 (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1317 b'm',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1318 b'comment',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1319 b'',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1320 _(b'add a comment to Revisions with new/updated Diffs'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1321 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1322 (b'', b'confirm', None, _(b'ask for confirmation before sending')),
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1323 (b'', b'fold', False, _(b'combine the revisions into one review')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1324 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1325 _(b'REV [OPTIONS]'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1326 helpcategory=command.CATEGORY_IMPORT_EXPORT,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1327 )
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1328 def phabsend(ui, repo, *revs, **opts):
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1329 """upload changesets to Phabricator
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1330
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1331 If there are multiple revisions specified, they will be send as a stack
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1332 with a linear dependencies relationship using the order specified by the
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1333 revset.
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1334
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1335 For the first time uploading changesets, local tags will be created to
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1336 maintain the association. After the first time, phabsend will check
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1337 obsstore and tags information so it can figure out whether to update an
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1338 existing Differential Revision, or create a new one.
33716
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1339
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1340 If --amend is set, update commit messages so they have the
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1341 ``Differential Revision`` URL, remove related tags. This is similar to what
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1342 arcanist will do, and is more desired in author-push workflows. Otherwise,
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1343 use local tags to record the ``Differential Revision`` association.
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1344
33716
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1345 The --confirm option lets you confirm changesets before sending them. You
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1346 can also add following to your configuration file to make it default
33992
45a8cd74de4e phabsend: polish the docstring a bit
Jun Wu <quark@fb.com>
parents: 33855
diff changeset
1347 behaviour::
33716
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1348
33992
45a8cd74de4e phabsend: polish the docstring a bit
Jun Wu <quark@fb.com>
parents: 33855
diff changeset
1349 [phabsend]
45a8cd74de4e phabsend: polish the docstring a bit
Jun Wu <quark@fb.com>
parents: 33855
diff changeset
1350 confirm = true
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1351
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1352 By default, a separate review will be created for each commit that is
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1353 selected, and will have the same parent/child relationship in Phabricator.
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1354 If ``--fold`` is set, multiple commits are rolled up into a single review
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1355 as if diffed from the parent of the first revision to the last. The commit
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1356 messages are concatenated in the summary field on Phabricator.
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1357
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1358 phabsend will check obsstore and the above association to decide whether to
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1359 update an existing Differential Revision, or create a new one.
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1360 """
41975
51ba9fbcca52 py3: use pycompat.byteskwargs on opts in phabricator.py
Ian Moody <moz-ian@perix.co.uk>
parents: 41955
diff changeset
1361 opts = pycompat.byteskwargs(opts)
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1362 revs = list(revs) + opts.get(b'rev', [])
48128
5ced12cfa41b errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents: 47084
diff changeset
1363 revs = logcmdutil.revrange(repo, revs)
44076
a7c4bcf7018a phabricator: post revisions in ascending topological order (issue6241)
Matt Harbison <matt_harbison@yahoo.com>
parents: 43869
diff changeset
1364 revs.sort() # ascending order to preserve topological parent/child in phab
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1365
33266
5b2391b46906 phabricator: abort if phabsend gets empty revs
Jun Wu <quark@fb.com>
parents: 33265
diff changeset
1366 if not revs:
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1367 raise error.Abort(_(b'phabsend requires at least one changeset'))
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1368 if opts.get(b'amend'):
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1369 cmdutil.checkunfinished(repo)
33266
5b2391b46906 phabricator: abort if phabsend gets empty revs
Jun Wu <quark@fb.com>
parents: 33265
diff changeset
1370
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1371 ctxs = [repo[rev] for rev in revs]
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1372
44719
c482e2fe444c phabricator: prevent posting obsolete commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44718
diff changeset
1373 if any(c for c in ctxs if c.obsolete()):
c482e2fe444c phabricator: prevent posting obsolete commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44718
diff changeset
1374 raise error.Abort(_(b"obsolete commits cannot be posted for review"))
c482e2fe444c phabricator: prevent posting obsolete commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44718
diff changeset
1375
44758
c1c922391314 phabricator: ensure that `phabsend` is given a contiguous, linear commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44720
diff changeset
1376 # Ensure the local commits are an unbroken range. The semantics of the
c1c922391314 phabricator: ensure that `phabsend` is given a contiguous, linear commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44720
diff changeset
1377 # --fold option implies this, and the auto restacking of orphans requires
c1c922391314 phabricator: ensure that `phabsend` is given a contiguous, linear commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44720
diff changeset
1378 # it. Otherwise A+C in A->B->C will cause B to be orphaned, and C' to
c1c922391314 phabricator: ensure that `phabsend` is given a contiguous, linear commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44720
diff changeset
1379 # get A' as a parent.
45152
b3b0cd8b9366 phabricator: clarify the multiple heads/roots error message for phabsend
Matt Harbison <matt_harbison@yahoo.com>
parents: 45140
diff changeset
1380 def _fail_nonlinear_revs(revs, revtype):
b3b0cd8b9366 phabricator: clarify the multiple heads/roots error message for phabsend
Matt Harbison <matt_harbison@yahoo.com>
parents: 45140
diff changeset
1381 badnodes = [repo[r].node() for r in revs]
44758
c1c922391314 phabricator: ensure that `phabsend` is given a contiguous, linear commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44720
diff changeset
1382 raise error.Abort(
c1c922391314 phabricator: ensure that `phabsend` is given a contiguous, linear commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44720
diff changeset
1383 _(b"cannot phabsend multiple %s revisions: %s")
c1c922391314 phabricator: ensure that `phabsend` is given a contiguous, linear commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44720
diff changeset
1384 % (revtype, scmutil.nodesummaries(repo, badnodes)),
c1c922391314 phabricator: ensure that `phabsend` is given a contiguous, linear commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44720
diff changeset
1385 hint=_(b"the revisions must form a linear chain"),
c1c922391314 phabricator: ensure that `phabsend` is given a contiguous, linear commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44720
diff changeset
1386 )
c1c922391314 phabricator: ensure that `phabsend` is given a contiguous, linear commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44720
diff changeset
1387
c1c922391314 phabricator: ensure that `phabsend` is given a contiguous, linear commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44720
diff changeset
1388 heads = repo.revs(b'heads(%ld)', revs)
c1c922391314 phabricator: ensure that `phabsend` is given a contiguous, linear commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44720
diff changeset
1389 if len(heads) > 1:
45152
b3b0cd8b9366 phabricator: clarify the multiple heads/roots error message for phabsend
Matt Harbison <matt_harbison@yahoo.com>
parents: 45140
diff changeset
1390 _fail_nonlinear_revs(heads, b"head")
44758
c1c922391314 phabricator: ensure that `phabsend` is given a contiguous, linear commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44720
diff changeset
1391
c1c922391314 phabricator: ensure that `phabsend` is given a contiguous, linear commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44720
diff changeset
1392 roots = repo.revs(b'roots(%ld)', revs)
c1c922391314 phabricator: ensure that `phabsend` is given a contiguous, linear commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44720
diff changeset
1393 if len(roots) > 1:
45152
b3b0cd8b9366 phabricator: clarify the multiple heads/roots error message for phabsend
Matt Harbison <matt_harbison@yahoo.com>
parents: 45140
diff changeset
1394 _fail_nonlinear_revs(roots, b"root")
44758
c1c922391314 phabricator: ensure that `phabsend` is given a contiguous, linear commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44720
diff changeset
1395
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1396 fold = opts.get(b'fold')
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1397 if fold:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1398 if len(revs) == 1:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1399 # TODO: just switch to --no-fold instead?
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1400 raise error.Abort(_(b"cannot fold a single revision"))
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1401
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1402 # There's no clear way to manage multiple commits with a Dxxx tag, so
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1403 # require the amend option. (We could append "_nnn", but then it
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1404 # becomes jumbled if earlier commits are added to an update.) It should
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1405 # lock the repo and ensure that the range is editable, but that would
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1406 # make the code pretty convoluted. The default behavior of `arc` is to
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1407 # create a new review anyway.
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1408 if not opts.get(b"amend"):
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1409 raise error.Abort(_(b"cannot fold with --no-amend"))
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1410
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1411 # It might be possible to bucketize the revisions by the DREV value, and
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1412 # iterate over those groups when posting, and then again when amending.
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1413 # But for simplicity, require all selected revisions to be for the same
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1414 # DREV (if present). Adding local revisions to an existing DREV is
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1415 # acceptable.
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1416 drevmatchers = [
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1417 _differentialrevisiondescre.search(ctx.description())
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1418 for ctx in ctxs
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1419 ]
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1420 if len({m.group('url') for m in drevmatchers if m}) > 1:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1421 raise error.Abort(
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1422 _(b"cannot fold revisions with different DREV values")
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1423 )
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1424
33996
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33995
diff changeset
1425 # {newnode: (oldnode, olddiff, olddrev}
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33995
diff changeset
1426 oldmap = getoldnodedrevmap(repo, [repo[r].node() for r in revs])
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33995
diff changeset
1427
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1428 confirm = ui.configbool(b'phabsend', b'confirm')
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1429 confirm |= bool(opts.get(b'confirm'))
33716
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1430 if confirm:
33996
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33995
diff changeset
1431 confirmed = _confirmbeforesend(repo, revs, oldmap)
33716
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1432 if not confirmed:
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1433 raise error.Abort(_(b'phabsend cancelled'))
33716
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1434
33498
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1435 actions = []
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1436 reviewers = opts.get(b'reviewer', [])
42460
f33d3ee110da phabricator: add --blocker argument to phabsend to specify blocking reviewers
Ian Moody <moz-ian@perix.co.uk>
parents: 42459
diff changeset
1437 blockers = opts.get(b'blocker', [])
f33d3ee110da phabricator: add --blocker argument to phabsend to specify blocking reviewers
Ian Moody <moz-ian@perix.co.uk>
parents: 42459
diff changeset
1438 phids = []
33498
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1439 if reviewers:
44445
ddcb51390891 phabricator: pass ui instead of repo to `userphids()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44444
diff changeset
1440 phids.extend(userphids(repo.ui, reviewers))
42460
f33d3ee110da phabricator: add --blocker argument to phabsend to specify blocking reviewers
Ian Moody <moz-ian@perix.co.uk>
parents: 42459
diff changeset
1441 if blockers:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1442 phids.extend(
44445
ddcb51390891 phabricator: pass ui instead of repo to `userphids()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44444
diff changeset
1443 map(
ddcb51390891 phabricator: pass ui instead of repo to `userphids()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44444
diff changeset
1444 lambda phid: b'blocking(%s)' % phid,
ddcb51390891 phabricator: pass ui instead of repo to `userphids()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44444
diff changeset
1445 userphids(repo.ui, blockers),
ddcb51390891 phabricator: pass ui instead of repo to `userphids()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44444
diff changeset
1446 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1447 )
42460
f33d3ee110da phabricator: add --blocker argument to phabsend to specify blocking reviewers
Ian Moody <moz-ian@perix.co.uk>
parents: 42459
diff changeset
1448 if phids:
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1449 actions.append({b'type': b'reviewers.add', b'value': phids})
33498
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1450
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1451 drevids = [] # [int]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1452 diffmap = {} # {newnode: diff}
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1453
42465
c19d259fd6ad phabricator: use parents.set to always set dependencies
Ian Moody <moz-ian@perix.co.uk>
parents: 42460
diff changeset
1454 # Send patches one by one so we know their Differential Revision PHIDs and
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1455 # can provide dependency relationship
42465
c19d259fd6ad phabricator: use parents.set to always set dependencies
Ian Moody <moz-ian@perix.co.uk>
parents: 42460
diff changeset
1456 lastrevphid = None
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1457 for ctx in ctxs:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1458 if fold:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1459 ui.debug(b'sending rev %d::%d\n' % (ctx.rev(), ctxs[-1].rev()))
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1460 else:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1461 ui.debug(b'sending rev %d\n' % ctx.rev())
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1462
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1463 # Get Differential Revision ID
33717
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33716
diff changeset
1464 oldnode, olddiff, revid = oldmap.get(ctx.node(), (None, None, None))
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1465 oldbasenode, oldbasediff, oldbaserevid = oldnode, olddiff, revid
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1466
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1467 if fold:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1468 oldbasenode, oldbasediff, oldbaserevid = oldmap.get(
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1469 ctxs[-1].node(), (None, None, None)
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1470 )
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1471
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1472 if oldnode != ctx.node() or opts.get(b'amend'):
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1473 # Create or update Differential Revision
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1474 revision, diff = createdifferentialrevision(
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1475 ctxs if fold else [ctx],
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1476 revid,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1477 lastrevphid,
44649
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44648
diff changeset
1478 oldbasenode,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1479 oldnode,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1480 olddiff,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1481 actions,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1482 opts.get(b'comment'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1483 )
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1484
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1485 if fold:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1486 for ctx in ctxs:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1487 diffmap[ctx.node()] = diff
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1488 else:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1489 diffmap[ctx.node()] = diff
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1490
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1491 newrevid = int(revision[b'object'][b'id'])
42465
c19d259fd6ad phabricator: use parents.set to always set dependencies
Ian Moody <moz-ian@perix.co.uk>
parents: 42460
diff changeset
1492 newrevphid = revision[b'object'][b'phid']
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1493 if revid:
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1494 action = b'updated'
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1495 else:
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1496 action = b'created'
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1497
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1498 # Create a local tag to note the association, if commit message
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1499 # does not have it already
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1500 if not fold:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1501 m = _differentialrevisiondescre.search(ctx.description())
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1502 if not m or int(m.group('id')) != newrevid:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1503 tagname = b'D%d' % newrevid
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1504 tags.tag(
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1505 repo,
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1506 tagname,
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1507 ctx.node(),
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1508 message=None,
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1509 user=None,
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1510 date=None,
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1511 local=True,
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1512 )
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1513 else:
42465
c19d259fd6ad phabricator: use parents.set to always set dependencies
Ian Moody <moz-ian@perix.co.uk>
parents: 42460
diff changeset
1514 # Nothing changed. But still set "newrevphid" so the next revision
c19d259fd6ad phabricator: use parents.set to always set dependencies
Ian Moody <moz-ian@perix.co.uk>
parents: 42460
diff changeset
1515 # could depend on this one and "newrevid" for the summary line.
44444
df8053082364 phabricator: pass ui instead of repo to `querydrev()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44443
diff changeset
1516 newrevphid = querydrev(repo.ui, b'%d' % revid)[0][b'phid']
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1517 newrevid = revid
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1518 action = b'skipped'
33201
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
1519
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1520 drevids.append(newrevid)
42465
c19d259fd6ad phabricator: use parents.set to always set dependencies
Ian Moody <moz-ian@perix.co.uk>
parents: 42460
diff changeset
1521 lastrevphid = newrevphid
33202
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33201
diff changeset
1522
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1523 if fold:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1524 for c in ctxs:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1525 if oldmap.get(c.node(), (None, None, None))[2]:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1526 action = b'updated'
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1527 else:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1528 action = b'created'
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1529 _print_phabsend_action(ui, c, newrevid, action)
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1530 break
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1531
44652
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1532 _print_phabsend_action(ui, ctx, newrevid, action)
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44651
diff changeset
1533
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1534 # Update commit messages and remove tags
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1535 if opts.get(b'amend'):
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1536 unfi = repo.unfiltered()
42450
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42449
diff changeset
1537 drevs = callconduit(ui, b'differential.query', {b'ids': drevids})
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1538 with repo.wlock(), repo.lock(), repo.transaction(b'phabsend'):
44720
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1539 # Eagerly evaluate commits to restabilize before creating new
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1540 # commits. The selected revisions are excluded because they are
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1541 # automatically restacked as part of the submission process.
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1542 restack = [
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1543 c
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1544 for c in repo.set(
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1545 b"(%ld::) - (%ld) - unstable() - obsolete() - public()",
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1546 revs,
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1547 revs,
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1548 )
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1549 ]
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1550 wnode = unfi[b'.'].node()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1551 mapping = {} # {oldnode: [newnode]}
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1552 newnodes = []
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1553
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1554 drevid = drevids[0]
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1555
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1556 for i, rev in enumerate(revs):
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1557 old = unfi[rev]
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1558 if not fold:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1559 drevid = drevids[i]
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1560 drev = [d for d in drevs if int(d[b'id']) == drevid][0]
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1561
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1562 newdesc = get_amended_desc(drev, old, fold)
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1563 # Make sure commit message contain "Differential Revision"
44718
0680b8a1992a phabricator: avoid creating unstable children within the review stack
Matt Harbison <matt_harbison@yahoo.com>
parents: 44717
diff changeset
1564 if (
0680b8a1992a phabricator: avoid creating unstable children within the review stack
Matt Harbison <matt_harbison@yahoo.com>
parents: 44717
diff changeset
1565 old.description() != newdesc
0680b8a1992a phabricator: avoid creating unstable children within the review stack
Matt Harbison <matt_harbison@yahoo.com>
parents: 44717
diff changeset
1566 or old.p1().node() in mapping
0680b8a1992a phabricator: avoid creating unstable children within the review stack
Matt Harbison <matt_harbison@yahoo.com>
parents: 44717
diff changeset
1567 or old.p2().node() in mapping
0680b8a1992a phabricator: avoid creating unstable children within the review stack
Matt Harbison <matt_harbison@yahoo.com>
parents: 44717
diff changeset
1568 ):
41163
0101a35deae2 phabricator: warn if unable to amend, instead of aborting after posting
Matt Harbison <matt_harbison@yahoo.com>
parents: 41083
diff changeset
1569 if old.phase() == phases.public:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1570 ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1571 _(b"warning: not updating public commit %s\n")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1572 % scmutil.formatchangeid(old)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1573 )
41163
0101a35deae2 phabricator: warn if unable to amend, instead of aborting after posting
Matt Harbison <matt_harbison@yahoo.com>
parents: 41083
diff changeset
1574 continue
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1575 parents = [
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1576 mapping.get(old.p1().node(), (old.p1(),))[0],
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1577 mapping.get(old.p2().node(), (old.p2(),))[0],
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1578 ]
45437
1a5d3e555c70 phabricator: update the hashes in commit messages as they get submitted
Matt Harbison <matt_harbison@yahoo.com>
parents: 45272
diff changeset
1579 newdesc = rewriteutil.update_hash_refs(
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
1580 repo,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
1581 newdesc,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
1582 mapping,
45437
1a5d3e555c70 phabricator: update the hashes in commit messages as they get submitted
Matt Harbison <matt_harbison@yahoo.com>
parents: 45272
diff changeset
1583 )
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1584 new = context.metadataonlyctx(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1585 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1586 old,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1587 parents=parents,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1588 text=newdesc,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1589 user=old.user(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1590 date=old.date(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1591 extra=old.extra(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1592 )
38342
bb7e3c6ef592 phabricator: preserve the phase when amending in the Differential fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 38075
diff changeset
1593
38429
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 38398
diff changeset
1594 newnode = new.commit()
38342
bb7e3c6ef592 phabricator: preserve the phase when amending in the Differential fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 38075
diff changeset
1595
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1596 mapping[old.node()] = [newnode]
44651
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1597
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1598 if fold:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1599 # Defer updating the (single) Diff until all nodes are
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1600 # collected. No tags were created, so none need to be
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1601 # removed.
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1602 newnodes.append(newnode)
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1603 continue
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1604
44651
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1605 _amend_diff_properties(
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1606 unfi, drevid, [newnode], diffmap[old.node()]
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44650
diff changeset
1607 )
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1608
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1609 # Remove local tags since it's no longer necessary
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1610 tagname = b'D%d' % drevid
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1611 if tagname in repo.tags():
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1612 tags.tag(
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1613 repo,
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1614 tagname,
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46907
diff changeset
1615 repo.nullid,
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1616 message=None,
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1617 user=None,
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1618 date=None,
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1619 local=True,
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1620 )
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1621 elif fold:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1622 # When folding multiple commits into one review with
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1623 # --fold, track even the commits that weren't amended, so
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1624 # that their association isn't lost if the properties are
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1625 # rewritten below.
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1626 newnodes.append(old.node())
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1627
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1628 # If the submitted commits are public, no amend takes place so
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1629 # there are no newnodes and therefore no diff update to do.
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1630 if fold and newnodes:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1631 diff = diffmap[old.node()]
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1632
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1633 # The diff object in diffmap doesn't have the local commits
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1634 # because that could be returned from differential.creatediff,
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1635 # not differential.querydiffs. So use the queried diff (if
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1636 # present), or force the amend (a new revision is being posted.)
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1637 if not olddiff or set(newnodes) != getlocalcommits(olddiff):
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1638 _debug(ui, b"updating local commit list for D%d\n" % drevid)
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1639 _amend_diff_properties(unfi, drevid, newnodes, diff)
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1640 else:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1641 _debug(
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1642 ui,
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1643 b"local commit list for D%d is already up-to-date\n"
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1644 % drevid,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1645 )
44717
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1646 elif fold:
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1647 _debug(ui, b"no newnodes to update\n")
3dc6a70779f2 phabricator: add an option to fold several commits into one review (issue6244)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44715
diff changeset
1648
44720
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1649 # Restack any children of first-time submissions that were orphaned
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1650 # in the process. The ctx won't report that it is an orphan until
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1651 # the cleanup takes place below.
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1652 for old in restack:
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1653 parents = [
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1654 mapping.get(old.p1().node(), (old.p1(),))[0],
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1655 mapping.get(old.p2().node(), (old.p2(),))[0],
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1656 ]
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1657 new = context.metadataonlyctx(
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1658 repo,
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1659 old,
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1660 parents=parents,
45437
1a5d3e555c70 phabricator: update the hashes in commit messages as they get submitted
Matt Harbison <matt_harbison@yahoo.com>
parents: 45272
diff changeset
1661 text=rewriteutil.update_hash_refs(
1a5d3e555c70 phabricator: update the hashes in commit messages as they get submitted
Matt Harbison <matt_harbison@yahoo.com>
parents: 45272
diff changeset
1662 repo, old.description(), mapping
1a5d3e555c70 phabricator: update the hashes in commit messages as they get submitted
Matt Harbison <matt_harbison@yahoo.com>
parents: 45272
diff changeset
1663 ),
44720
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1664 user=old.user(),
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1665 date=old.date(),
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1666 extra=old.extra(),
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1667 )
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1668
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1669 newnode = new.commit()
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1670
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1671 # Don't obsolete unselected descendants of nodes that have not
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1672 # been changed in this transaction- that results in an error.
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1673 if newnode != old.node():
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1674 mapping[old.node()] = [newnode]
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1675 _debug(
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1676 ui,
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1677 b"restabilizing %s as %s\n"
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1678 % (short(old.node()), short(newnode)),
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1679 )
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1680 else:
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1681 _debug(
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1682 ui,
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1683 b"not restabilizing unchanged %s\n" % short(old.node()),
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1684 )
601ce5392cb0 phabricator: restack any new orphans created by phabsend (issue6045)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44719
diff changeset
1685
38429
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 38398
diff changeset
1686 scmutil.cleanupnodes(repo, mapping, b'phabsend', fixphase=True)
33808
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1687 if wnode in mapping:
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1688 unfi.setparents(mapping[wnode][0])
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33806
diff changeset
1689
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1690
33264
266321579c68 phabricator: add node and p1 to hg:meta property
Jun Wu <quark@fb.com>
parents: 33263
diff changeset
1691 # Map from "hg:meta" keys to header understood by "hg import". The order is
266321579c68 phabricator: add node and p1 to hg:meta property
Jun Wu <quark@fb.com>
parents: 33263
diff changeset
1692 # consistent with "hg export" output.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1693 _metanamemap = util.sortdict(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1694 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1695 (b'user', b'User'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1696 (b'date', b'Date'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1697 (b'branch', b'Branch'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1698 (b'node', b'Node ID'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1699 (b'parent', b'Parent '),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1700 ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1701 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1702
33264
266321579c68 phabricator: add node and p1 to hg:meta property
Jun Wu <quark@fb.com>
parents: 33263
diff changeset
1703
33996
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33995
diff changeset
1704 def _confirmbeforesend(repo, revs, oldmap):
42449
500b64c5d991 phabricator: pass ui into readurltoken instead of passing repo
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42447
diff changeset
1705 url, token = readurltoken(repo.ui)
33716
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1706 ui = repo.ui
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1707 for rev in revs:
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1708 ctx = repo[rev]
33996
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33995
diff changeset
1709 oldnode, olddiff, drevid = oldmap.get(ctx.node(), (None, None, None))
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33995
diff changeset
1710 if drevid:
43321
a2ff3aff81d2 py3: use %d instead of %s when formatting an int into a bytestring
Ian Moody <moz-ian@perix.co.uk>
parents: 43282
diff changeset
1711 drevdesc = ui.label(b'D%d' % drevid, b'phabricator.drev')
33996
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33995
diff changeset
1712 else:
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1713 drevdesc = ui.label(_(b'NEW'), b'phabricator.drev')
33996
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33995
diff changeset
1714
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1715 ui.write(
45795
294aab57a5f3 phabsend: use default one-line summary
Martin von Zweigbergk <martinvonz@google.com>
parents: 45513
diff changeset
1716 _(b'%s - %s\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1717 % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1718 drevdesc,
45795
294aab57a5f3 phabsend: use default one-line summary
Martin von Zweigbergk <martinvonz@google.com>
parents: 45513
diff changeset
1719 cmdutil.format_changeset_summary(ui, ctx, b'phabsend'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1720 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1721 )
33716
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1722
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1723 if ui.promptchoice(
44986
7a0a1be721a3 phabricator: make it clear what happen when no response
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 44906
diff changeset
1724 _(b'Send the above changes to %s (Y/n)?$$ &Yes $$ &No') % url
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1725 ):
33716
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1726 return False
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1727
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1728 return True
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1729
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1730
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1731 _knownstatusnames = {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1732 b'accepted',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1733 b'needsreview',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1734 b'needsrevision',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1735 b'closed',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1736 b'abandoned',
43868
74ec6ca0eb75 phabricator: add the "Changes Planned" status name
Matt Harbison <matt_harbison@yahoo.com>
parents: 43858
diff changeset
1737 b'changesplanned',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1738 }
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1739
33854
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33853
diff changeset
1740
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33853
diff changeset
1741 def _getstatusname(drev):
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33853
diff changeset
1742 """get normalized status name from a Differential Revision"""
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1743 return drev[b'statusName'].replace(b' ', b'').lower()
33854
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33853
diff changeset
1744
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1745
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1746 # Small language to specify differential revisions. Support symbols: (), :X,
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1747 # +, and -.
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1748
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1749 _elements = {
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1750 # token-type: binding-strength, primary, prefix, infix, suffix
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1751 b'(': (12, None, (b'group', 1, b')'), None, None),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1752 b':': (8, None, (b'ancestors', 8), None, None),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1753 b'&': (5, None, None, (b'and_', 5), None),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1754 b'+': (4, None, None, (b'add', 4), None),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1755 b'-': (4, None, None, (b'sub', 4), None),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1756 b')': (0, None, None, None, None),
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1757 b'symbol': (0, b'symbol', None, None, None),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1758 b'end': (0, None, None, None, None),
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1759 }
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1760
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1761
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1762 def _tokenize(text):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1763 view = memoryview(text) # zero-copy slice
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1764 special = b'():+-& '
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1765 pos = 0
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1766 length = len(text)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1767 while pos < length:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1768 symbol = b''.join(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1769 itertools.takewhile(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1770 lambda ch: ch not in special, pycompat.iterbytestr(view[pos:])
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1771 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1772 )
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1773 if symbol:
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1774 yield (b'symbol', symbol, pos)
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1775 pos += len(symbol)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1776 else: # special char, ignore space
43282
47946f08e463 py3: don't index into bytes in phabricator's _tokenize()
Ian Moody <moz-ian@perix.co.uk>
parents: 43264
diff changeset
1777 if text[pos : pos + 1] != b' ':
47946f08e463 py3: don't index into bytes in phabricator's _tokenize()
Ian Moody <moz-ian@perix.co.uk>
parents: 43264
diff changeset
1778 yield (text[pos : pos + 1], None, pos)
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1779 pos += 1
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1780 yield (b'end', None, pos)
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1781
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1782
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1783 def _parse(text):
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1784 tree, pos = parser.parser(_elements).parse(_tokenize(text))
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1785 if pos != len(text):
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1786 raise error.ParseError(b'invalid token', pos)
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1787 return tree
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1788
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1789
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1790 def _parsedrev(symbol):
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1791 """str -> int or None, ex. 'D45' -> 45; '12' -> 12; 'x' -> None"""
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1792 if symbol.startswith(b'D') and symbol[1:].isdigit():
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1793 return int(symbol[1:])
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1794 if symbol.isdigit():
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1795 return int(symbol)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1796
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1797
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1798 def _prefetchdrevs(tree):
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1799 """return ({single-drev-id}, {ancestor-drev-id}) to prefetch"""
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1800 drevs = set()
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1801 ancestordrevs = set()
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1802 op = tree[0]
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1803 if op == b'symbol':
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1804 r = _parsedrev(tree[1])
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1805 if r:
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1806 drevs.add(r)
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1807 elif op == b'ancestors':
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1808 r, a = _prefetchdrevs(tree[1])
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1809 drevs.update(r)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1810 ancestordrevs.update(r)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1811 ancestordrevs.update(a)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1812 else:
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1813 for t in tree[1:]:
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1814 r, a = _prefetchdrevs(t)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1815 drevs.update(r)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1816 ancestordrevs.update(a)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1817 return drevs, ancestordrevs
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1818
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1819
44444
df8053082364 phabricator: pass ui instead of repo to `querydrev()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44443
diff changeset
1820 def querydrev(ui, spec):
33267
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1821 """return a list of "Differential Revision" dicts
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1822
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1823 spec is a string using a simple query language, see docstring in phabread
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1824 for details.
33267
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1825
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1826 A "Differential Revision dict" looks like:
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1827
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1828 {
44424
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1829 "activeDiffPHID": "PHID-DIFF-xoqnjkobbm6k4dk6hi72",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1830 "authorPHID": "PHID-USER-tv3ohwc4v4jeu34otlye",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1831 "auxiliary": {
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1832 "phabricator:depends-on": [
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1833 "PHID-DREV-gbapp366kutjebt7agcd"
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1834 ]
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1835 "phabricator:projects": [],
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1836 },
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1837 "branch": "default",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1838 "ccs": [],
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1839 "commits": [],
33267
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1840 "dateCreated": "1499181406",
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1841 "dateModified": "1499182103",
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1842 "diffs": [
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1843 "3",
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1844 "4",
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1845 ],
44424
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1846 "hashes": [],
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1847 "id": "2",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1848 "lineCount": "2",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1849 "phid": "PHID-DREV-672qvysjcczopag46qty",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1850 "properties": {},
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1851 "repositoryPHID": "PHID-REPO-hub2hx62ieuqeheznasv",
33267
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1852 "reviewers": [],
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1853 "sourcePath": null
44424
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1854 "status": "0",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1855 "statusName": "Needs Review",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1856 "summary": "",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1857 "testPlan": "",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1858 "title": "example",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1859 "uri": "https://phab.example.com/D2",
33267
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1860 }
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1861 """
44424
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1862 # TODO: replace differential.query and differential.querydiffs with
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1863 # differential.diff.search because the former (and their output) are
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
1864 # frozen, and planned to be deprecated and removed.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1865
33269
ead6749354e1 phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents: 33268
diff changeset
1866 def fetch(params):
ead6749354e1 phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents: 33268
diff changeset
1867 """params -> single drev or None"""
41907
59bae59b7498 py3: fix a few "dict keys as str instead of bytes" issues in phabricator.py
Ian Moody <moz-ian@perix.co.uk>
parents: 41906
diff changeset
1868 key = (params.get(b'ids') or params.get(b'phids') or [None])[0]
33269
ead6749354e1 phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents: 33268
diff changeset
1869 if key in prefetched:
ead6749354e1 phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents: 33268
diff changeset
1870 return prefetched[key]
44444
df8053082364 phabricator: pass ui instead of repo to `querydrev()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44443
diff changeset
1871 drevs = callconduit(ui, b'differential.query', params)
33269
ead6749354e1 phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents: 33268
diff changeset
1872 # Fill prefetched with the result
ead6749354e1 phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents: 33268
diff changeset
1873 for drev in drevs:
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1874 prefetched[drev[b'phid']] = drev
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1875 prefetched[int(drev[b'id'])] = drev
33269
ead6749354e1 phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents: 33268
diff changeset
1876 if key not in prefetched:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1877 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1878 _(b'cannot get Differential Revision %r') % params
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1879 )
33269
ead6749354e1 phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents: 33268
diff changeset
1880 return prefetched[key]
ead6749354e1 phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents: 33268
diff changeset
1881
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1882 def getstack(topdrevids):
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1883 """given a top, get a stack from the bottom, [id] -> [id]"""
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1884 visited = set()
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1885 result = []
41907
59bae59b7498 py3: fix a few "dict keys as str instead of bytes" issues in phabricator.py
Ian Moody <moz-ian@perix.co.uk>
parents: 41906
diff changeset
1886 queue = [{b'ids': [i]} for i in topdrevids]
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1887 while queue:
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1888 params = queue.pop()
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1889 drev = fetch(params)
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1890 if drev[b'id'] in visited:
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1891 continue
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1892 visited.add(drev[b'id'])
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1893 result.append(int(drev[b'id']))
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1894 auxiliary = drev.get(b'auxiliary', {})
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1895 depends = auxiliary.get(b'phabricator:depends-on', [])
33267
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1896 for phid in depends:
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1897 queue.append({b'phids': [phid]})
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1898 result.reverse()
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1899 return smartset.baseset(result)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1900
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1901 # Initialize prefetch cache
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1902 prefetched = {} # {id or phid: drev}
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1903
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1904 tree = _parse(spec)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1905 drevs, ancestordrevs = _prefetchdrevs(tree)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1906
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1907 # developer config: phabricator.batchsize
44444
df8053082364 phabricator: pass ui instead of repo to `querydrev()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44443
diff changeset
1908 batchsize = ui.configint(b'phabricator', b'batchsize')
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1909
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1910 # Prefetch Differential Revisions in batch
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1911 tofetch = set(drevs)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1912 for r in ancestordrevs:
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1913 tofetch.update(range(max(1, r - batchsize), r + 1))
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1914 if drevs:
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1915 fetch({b'ids': list(tofetch)})
33854
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33853
diff changeset
1916 validids = sorted(set(getstack(list(ancestordrevs))) | set(drevs))
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1917
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1918 # Walk through the tree, return smartsets
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1919 def walk(tree):
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1920 op = tree[0]
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1921 if op == b'symbol':
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1922 drev = _parsedrev(tree[1])
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1923 if drev:
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1924 return smartset.baseset([drev])
33854
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33853
diff changeset
1925 elif tree[1] in _knownstatusnames:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1926 drevs = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1927 r
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1928 for r in validids
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1929 if _getstatusname(prefetched[r]) == tree[1]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1930 ]
33854
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33853
diff changeset
1931 return smartset.baseset(drevs)
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1932 else:
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1933 raise error.Abort(_(b'unknown symbol: %s') % tree[1])
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1934 elif op in {b'and_', b'add', b'sub'}:
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1935 assert len(tree) == 3
51131
4ed9efb25bc7 phabricator: stringify the argument to `getattr()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 50952
diff changeset
1936 return getattr(operator, pycompat.sysstr(op))(
4ed9efb25bc7 phabricator: stringify the argument to `getattr()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 50952
diff changeset
1937 walk(tree[1]), walk(tree[2])
4ed9efb25bc7 phabricator: stringify the argument to `getattr()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 50952
diff changeset
1938 )
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1939 elif op == b'group':
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1940 return walk(tree[1])
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1941 elif op == b'ancestors':
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1942 return getstack(walk(tree[1]))
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1943 else:
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1944 raise error.ProgrammingError(b'illegal tree: %r' % tree)
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1945
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
1946 return [prefetched[r] for r in walk(tree)]
33267
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1947
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1948
33268
85391b95961d phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents: 33267
diff changeset
1949 def getdescfromdrev(drev):
85391b95961d phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents: 33267
diff changeset
1950 """get description (commit message) from "Differential Revision"
85391b95961d phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents: 33267
diff changeset
1951
85391b95961d phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents: 33267
diff changeset
1952 This is similar to differential.getcommitmessage API. But we only care
85391b95961d phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents: 33267
diff changeset
1953 about limited fields: title, summary, test plan, and URL.
85391b95961d phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents: 33267
diff changeset
1954 """
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1955 title = drev[b'title']
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1956 summary = drev[b'summary'].rstrip()
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1957 testplan = drev[b'testPlan'].rstrip()
33268
85391b95961d phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents: 33267
diff changeset
1958 if testplan:
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1959 testplan = b'Test Plan:\n%s' % testplan
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
1960 uri = b'Differential Revision: %s' % drev[b'uri']
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
1961 return b'\n\n'.join(filter(None, [title, summary, testplan, uri]))
33268
85391b95961d phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents: 33267
diff changeset
1962
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1963
44648
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1964 def get_amended_desc(drev, ctx, folded):
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1965 """similar to ``getdescfromdrev``, but supports a folded series of commits
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1966
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1967 This is used when determining if an individual commit needs to have its
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1968 message amended after posting it for review. The determination is made for
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1969 each individual commit, even when they were folded into one review.
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1970 """
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1971 if not folded:
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1972 return getdescfromdrev(drev)
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1973
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1974 uri = b'Differential Revision: %s' % drev[b'uri']
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1975
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1976 # Since the commit messages were combined when posting multiple commits
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1977 # with --fold, the fields can't be read from Phabricator here, or *all*
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1978 # affected local revisions will end up with the same commit message after
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1979 # the URI is amended in. Append in the DREV line, or update it if it
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1980 # exists. At worst, this means commit message or test plan updates on
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1981 # Phabricator aren't propagated back to the repository, but that seems
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1982 # reasonable for the case where local commits are effectively combined
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1983 # in Phabricator.
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1984 m = _differentialrevisiondescre.search(ctx.description())
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1985 if not m:
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1986 return b'\n\n'.join([ctx.description(), uri])
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1987
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1988 return _differentialrevisiondescre.sub(uri, ctx.description())
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1989
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1990
44650
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
1991 def getlocalcommits(diff):
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
1992 """get the set of local commits from a diff object
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
1993
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
1994 See ``getdiffmeta()`` for an example diff object.
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
1995 """
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
1996 props = diff.get(b'properties') or {}
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
1997 commits = props.get(b'local:commits') or {}
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
1998 if len(commits) > 1:
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
1999 return {bin(c) for c in commits.keys()}
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
2000
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
2001 # Storing the diff metadata predates storing `local:commits`, so continue
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
2002 # to use that in the --no-fold case.
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
2003 return {bin(getdiffmeta(diff).get(b'node', b'')) or None}
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
2004
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44649
diff changeset
2005
33441
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2006 def getdiffmeta(diff):
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2007 """get commit metadata (date, node, user, p1) from a diff object
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2008
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2009 The metadata could be "hg:meta", sent by phabsend, like:
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2010
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2011 "properties": {
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2012 "hg:meta": {
44424
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
2013 "branch": "default",
33441
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2014 "date": "1499571514 25200",
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2015 "node": "98c08acae292b2faf60a279b4189beb6cff1414d",
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2016 "user": "Foo Bar <foo@example.com>",
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2017 "parent": "6d0abad76b30e4724a37ab8721d630394070fe16"
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2018 }
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2019 }
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2020
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2021 Or converted from "local:commits", sent by "arc", like:
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2022
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2023 "properties": {
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2024 "local:commits": {
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2025 "98c08acae292b2faf60a279b4189beb6cff1414d": {
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2026 "author": "Foo Bar",
44424
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
2027 "authorEmail": "foo@example.com"
33441
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2028 "branch": "default",
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2029 "commit": "98c08acae292b2faf60a279b4189beb6cff1414d",
44424
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
2030 "local": "1000",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
2031 "message": "...",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
2032 "parents": ["6d0abad76b30e4724a37ab8721d630394070fe16"],
33441
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2033 "rev": "98c08acae292b2faf60a279b4189beb6cff1414d",
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2034 "summary": "...",
44424
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
2035 "tag": "",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44183
diff changeset
2036 "time": 1499546314,
33441
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2037 }
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2038 }
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2039 }
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2040
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2041 Note: metadata extracted from "local:commits" will lose time zone
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2042 information.
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2043 """
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
2044 props = diff.get(b'properties') or {}
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
2045 meta = props.get(b'hg:meta')
42285
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2046 if not meta:
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2047 if props.get(b'local:commits'):
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2048 commit = sorted(props[b'local:commits'].values())[0]
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2049 meta = {}
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2050 if b'author' in commit and b'authorEmail' in commit:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2051 meta[b'user'] = b'%s <%s>' % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2052 commit[b'author'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2053 commit[b'authorEmail'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2054 )
42285
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2055 if b'time' in commit:
42618
c17e6a3e7356 phabricator: handle local:commits time being string or int
Ian Moody <moz-ian@perix.co.uk>
parents: 42465
diff changeset
2056 meta[b'date'] = b'%d 0' % int(commit[b'time'])
42285
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2057 if b'branch' in commit:
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2058 meta[b'branch'] = commit[b'branch']
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2059 node = commit.get(b'commit', commit.get(b'rev'))
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2060 if node:
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2061 meta[b'node'] = node
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2062 if len(commit.get(b'parents', ())) >= 1:
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2063 meta[b'parent'] = commit[b'parents'][0]
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2064 else:
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2065 meta = {}
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2066 if b'date' not in meta and b'dateCreated' in diff:
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2067 meta[b'date'] = b'%s 0' % diff[b'dateCreated']
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2068 if b'branch' not in meta and diff.get(b'branch'):
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2069 meta[b'branch'] = diff[b'branch']
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2070 if b'parent' not in meta and diff.get(b'sourceControlBaseRevision'):
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2071 meta[b'parent'] = diff[b'sourceControlBaseRevision']
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42284
diff changeset
2072 return meta
33441
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2073
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2074
44593
2d63a8910db6 phabricator: remove *-argument from _getdrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 44588
diff changeset
2075 def _getdrevs(ui, stack, specs):
44587
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2076 """convert user supplied DREVSPECs into "Differential Revision" dicts
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2077
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2078 See ``hg help phabread`` for how to specify each DREVSPEC.
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2079 """
44593
2d63a8910db6 phabricator: remove *-argument from _getdrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 44588
diff changeset
2080 if len(specs) > 0:
44587
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2081
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2082 def _formatspec(s):
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2083 if stack:
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2084 s = b':(%s)' % s
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2085 return b'(%s)' % s
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2086
44593
2d63a8910db6 phabricator: remove *-argument from _getdrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 44588
diff changeset
2087 spec = b'+'.join(pycompat.maplist(_formatspec, specs))
44587
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2088
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2089 drevs = querydrev(ui, spec)
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2090 if drevs:
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2091 return drevs
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2092
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2093 raise error.Abort(_(b"empty DREVSPEC set"))
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2094
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44577
diff changeset
2095
44443
41217dfa7a6d phabricator: pass ui instead of repo to `readpatch()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44424
diff changeset
2096 def readpatch(ui, drevs, write):
33202
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33201
diff changeset
2097 """generate plain-text patch readable by 'hg import'
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33201
diff changeset
2098
44447
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44446
diff changeset
2099 write takes a list of (DREV, bytes), where DREV is the differential number
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44446
diff changeset
2100 (as bytes, without the "D" prefix) and the bytes are the text of a patch
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44446
diff changeset
2101 to be imported. drevs is what "querydrev" returns, results of
33852
75fdaf851e83 phabricator: change "readpatch" to be more flexible
Jun Wu <quark@fb.com>
parents: 33808
diff changeset
2102 "differential.query".
33202
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33201
diff changeset
2103 """
33267
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
2104 # Prefetch hg:meta property for all diffs
44470
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 44456
diff changeset
2105 diffids = sorted({max(int(v) for v in drev[b'diffs']) for drev in drevs})
44443
41217dfa7a6d phabricator: pass ui instead of repo to `readpatch()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44424
diff changeset
2106 diffs = callconduit(ui, b'differential.querydiffs', {b'ids': diffids})
33202
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33201
diff changeset
2107
44447
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44446
diff changeset
2108 patches = []
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44446
diff changeset
2109
33267
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
2110 # Generate patch for each drev
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
2111 for drev in drevs:
44443
41217dfa7a6d phabricator: pass ui instead of repo to `readpatch()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44424
diff changeset
2112 ui.note(_(b'reading D%s\n') % drev[b'id'])
33202
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33201
diff changeset
2113
41902
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41716
diff changeset
2114 diffid = max(int(v) for v in drev[b'diffs'])
44443
41217dfa7a6d phabricator: pass ui instead of repo to `readpatch()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44424
diff changeset
2115 body = callconduit(ui, b'differential.getrawdiff', {b'diffID': diffid})
33268
85391b95961d phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents: 33267
diff changeset
2116 desc = getdescfromdrev(drev)
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
2117 header = b'# HG changeset patch\n'
33267
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
2118
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
2119 # Try to preserve metadata from hg:meta property. Write hg patch
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
2120 # headers that can be read by the "import" command. See patchheadermap
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
2121 # and extract in mercurial/patch.py for supported headers.
41907
59bae59b7498 py3: fix a few "dict keys as str instead of bytes" issues in phabricator.py
Ian Moody <moz-ian@perix.co.uk>
parents: 41906
diff changeset
2122 meta = getdiffmeta(diffs[b'%d' % diffid])
33441
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2123 for k in _metanamemap.keys():
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
2124 if k in meta:
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
2125 header += b'# %s %s\n' % (_metanamemap[k], meta[k])
33202
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33201
diff changeset
2126
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
2127 content = b'%s%s\n%s' % (header, desc, body)
44447
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44446
diff changeset
2128 patches.append((drev[b'id'], content))
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44446
diff changeset
2129
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44446
diff changeset
2130 # Write patches to the supplied callback
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44446
diff changeset
2131 write(patches)
33202
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33201
diff changeset
2132
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2133
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2134 @vcrcommand(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2135 b'phabread',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2136 [(b'', b'stack', False, _(b'read dependencies'))],
44588
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44587
diff changeset
2137 _(b'DREVSPEC... [OPTIONS]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2138 helpcategory=command.CATEGORY_IMPORT_EXPORT,
44448
5e2d74e5f450 phabricator: make `hg phabread` work outside of a repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 44447
diff changeset
2139 optionalrepo=True,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2140 )
44588
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44587
diff changeset
2141 def phabread(ui, repo, *specs, **opts):
33202
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33201
diff changeset
2142 """print patches from Phabricator suitable for importing
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33201
diff changeset
2143
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
2144 DREVSPEC could be a Differential Revision identity, like ``D123``, or just
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
2145 the number ``123``. It could also have common operators like ``+``, ``-``,
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
2146 ``&``, ``(``, ``)`` for complex queries. Prefix ``:`` could be used to
44588
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44587
diff changeset
2147 select a stack. If multiple DREVSPEC values are given, the result is the
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44587
diff changeset
2148 union of each individually evaluated value. No attempt is currently made
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44587
diff changeset
2149 to reorder the values to run from parent to child.
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
2150
33854
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33853
diff changeset
2151 ``abandoned``, ``accepted``, ``closed``, ``needsreview``, ``needsrevision``
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33853
diff changeset
2152 could be used to filter patches by status. For performance reason, they
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33853
diff changeset
2153 only represent a subset of non-status selections and cannot be used alone.
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33853
diff changeset
2154
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
2155 For example, ``:D6+8-(2+D4)`` selects a stack up to D6, plus D8 and exclude
33854
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33853
diff changeset
2156 D2 and D4. ``:D9 & needsreview`` selects "Needs Review" revisions in a
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33853
diff changeset
2157 stack up to D9.
33202
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33201
diff changeset
2158
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33201
diff changeset
2159 If --stack is given, follow dependencies information and read all patches.
33853
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33852
diff changeset
2160 It is equivalent to the ``:`` operator.
33202
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33201
diff changeset
2161 """
41975
51ba9fbcca52 py3: use pycompat.byteskwargs on opts in phabricator.py
Ian Moody <moz-ian@perix.co.uk>
parents: 41955
diff changeset
2162 opts = pycompat.byteskwargs(opts)
44588
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44587
diff changeset
2163 drevs = _getdrevs(ui, opts.get(b'stack'), specs)
44447
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44446
diff changeset
2164
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44446
diff changeset
2165 def _write(patches):
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44446
diff changeset
2166 for drev, content in patches:
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44446
diff changeset
2167 ui.write(content)
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44446
diff changeset
2168
44448
5e2d74e5f450 phabricator: make `hg phabread` work outside of a repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 44447
diff changeset
2169 readpatch(ui, drevs, _write)
33855
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33854
diff changeset
2170
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2171
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2172 @vcrcommand(
44560
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2173 b'phabimport',
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2174 [(b'', b'stack', False, _(b'import dependencies as well'))],
44588
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44587
diff changeset
2175 _(b'DREVSPEC... [OPTIONS]'),
44560
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2176 helpcategory=command.CATEGORY_IMPORT_EXPORT,
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2177 )
44588
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44587
diff changeset
2178 def phabimport(ui, repo, *specs, **opts):
44560
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2179 """import patches from Phabricator for the specified Differential Revisions
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2180
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2181 The patches are read and applied starting at the parent of the working
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2182 directory.
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2183
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2184 See ``hg help phabread`` for how to specify DREVSPEC.
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2185 """
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2186 opts = pycompat.byteskwargs(opts)
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2187
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2188 # --bypass avoids losing exec and symlink bits when importing on Windows,
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2189 # and allows importing with a dirty wdir. It also aborts instead of leaving
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2190 # rejects.
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2191 opts[b'bypass'] = True
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2192
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2193 # Mandatory default values, synced with commands.import
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2194 opts[b'strip'] = 1
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2195 opts[b'prefix'] = b''
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2196 # Evolve 9.3.0 assumes this key is present in cmdutil.tryimportone()
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2197 opts[b'obsolete'] = False
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2198
44561
9bae1d1a0f4c phabricator: add a config knob to import in the secret phase
Matt Harbison <matt_harbison@yahoo.com>
parents: 44560
diff changeset
2199 if ui.configbool(b'phabimport', b'secret'):
9bae1d1a0f4c phabricator: add a config knob to import in the secret phase
Matt Harbison <matt_harbison@yahoo.com>
parents: 44560
diff changeset
2200 opts[b'secret'] = True
44562
f10055b099b3 phabricator: add a config knob to create obsolete markers when importing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44561
diff changeset
2201 if ui.configbool(b'phabimport', b'obsolete'):
f10055b099b3 phabricator: add a config knob to create obsolete markers when importing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44561
diff changeset
2202 opts[b'obsolete'] = True # Handled by evolve wrapping tryimportone()
44561
9bae1d1a0f4c phabricator: add a config knob to import in the secret phase
Matt Harbison <matt_harbison@yahoo.com>
parents: 44560
diff changeset
2203
44560
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2204 def _write(patches):
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2205 parents = repo[None].parents()
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2206
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2207 with repo.wlock(), repo.lock(), repo.transaction(b'phabimport'):
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2208 for drev, contents in patches:
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2209 ui.status(_(b'applying patch from D%s\n') % drev)
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2210
48964
5aafc3c5bdec py3: use io.BytesIO directly
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48128
diff changeset
2211 with patch.extract(ui, io.BytesIO(contents)) as patchdata:
44560
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2212 msg, node, rej = cmdutil.tryimportone(
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2213 ui,
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2214 repo,
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2215 patchdata,
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2216 parents,
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2217 opts,
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2218 [],
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2219 None, # Never update wdir to another revision
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2220 )
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2221
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2222 if not node:
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2223 raise error.Abort(_(b'D%s: no diffs found') % drev)
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2224
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2225 ui.note(msg + b'\n')
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2226 parents = [repo[node]]
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2227
44588
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44587
diff changeset
2228 drevs = _getdrevs(ui, opts.get(b'stack'), specs)
44560
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2229
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2230 readpatch(repo.ui, drevs, _write)
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2231
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2232
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44470
diff changeset
2233 @vcrcommand(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2234 b'phabupdate',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2235 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2236 (b'', b'accept', False, _(b'accept revisions')),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2237 (b'', b'reject', False, _(b'reject revisions')),
45136
1ff5070c0ab4 phabupdate: allows revisions to be marked "request-review"
Matt Harbison <matt_harbison@yahoo.com>
parents: 45135
diff changeset
2238 (b'', b'request-review', False, _(b'request review on revisions')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2239 (b'', b'abandon', False, _(b'abandon revisions')),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2240 (b'', b'reclaim', False, _(b'reclaim revisions')),
45137
3ad0855cc602 phabupdate: allow revisions to be marked "closed"
Matt Harbison <matt_harbison@yahoo.com>
parents: 45136
diff changeset
2241 (b'', b'close', False, _(b'close revisions')),
45138
2010f3143062 phabupdate: allow revisions to be reopened
Matt Harbison <matt_harbison@yahoo.com>
parents: 45137
diff changeset
2242 (b'', b'reopen', False, _(b'reopen revisions')),
45135
225588c4c255 phabupdate: allow revisions to be marked with "plan changes"
Matt Harbison <matt_harbison@yahoo.com>
parents: 44986
diff changeset
2243 (b'', b'plan-changes', False, _(b'plan changes for revisions')),
45140
c59e7bed8924 phabupdate: allow resigning from revisions
Matt Harbison <matt_harbison@yahoo.com>
parents: 45139
diff changeset
2244 (b'', b'resign', False, _(b'resign as a reviewer from revisions')),
45139
383b8c77096d phabupdate: allow revisions to be commandeered
Matt Harbison <matt_harbison@yahoo.com>
parents: 45138
diff changeset
2245 (b'', b'commandeer', False, _(b'commandeer revisions')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2246 (b'm', b'comment', b'', _(b'comment on the last revision')),
46041
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2247 (b'r', b'rev', b'', _(b'local revision to update'), _(b'REV')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2248 ],
46041
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2249 _(b'[DREVSPEC...| -r REV...] [OPTIONS]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2250 helpcategory=command.CATEGORY_IMPORT_EXPORT,
44446
b715432fabba phabricator: make `hg phabupdate` work outside of a repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 44445
diff changeset
2251 optionalrepo=True,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2252 )
44588
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44587
diff changeset
2253 def phabupdate(ui, repo, *specs, **opts):
33855
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33854
diff changeset
2254 """update Differential Revision in batch
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33854
diff changeset
2255
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33854
diff changeset
2256 DREVSPEC selects revisions. See :hg:`help phabread` for its usage.
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33854
diff changeset
2257 """
41975
51ba9fbcca52 py3: use pycompat.byteskwargs on opts in phabricator.py
Ian Moody <moz-ian@perix.co.uk>
parents: 41955
diff changeset
2258 opts = pycompat.byteskwargs(opts)
45135
225588c4c255 phabupdate: allow revisions to be marked with "plan changes"
Matt Harbison <matt_harbison@yahoo.com>
parents: 44986
diff changeset
2259 transactions = [
225588c4c255 phabupdate: allow revisions to be marked with "plan changes"
Matt Harbison <matt_harbison@yahoo.com>
parents: 44986
diff changeset
2260 b'abandon',
225588c4c255 phabupdate: allow revisions to be marked with "plan changes"
Matt Harbison <matt_harbison@yahoo.com>
parents: 44986
diff changeset
2261 b'accept',
45137
3ad0855cc602 phabupdate: allow revisions to be marked "closed"
Matt Harbison <matt_harbison@yahoo.com>
parents: 45136
diff changeset
2262 b'close',
45139
383b8c77096d phabupdate: allow revisions to be commandeered
Matt Harbison <matt_harbison@yahoo.com>
parents: 45138
diff changeset
2263 b'commandeer',
45135
225588c4c255 phabupdate: allow revisions to be marked with "plan changes"
Matt Harbison <matt_harbison@yahoo.com>
parents: 44986
diff changeset
2264 b'plan-changes',
225588c4c255 phabupdate: allow revisions to be marked with "plan changes"
Matt Harbison <matt_harbison@yahoo.com>
parents: 44986
diff changeset
2265 b'reclaim',
225588c4c255 phabupdate: allow revisions to be marked with "plan changes"
Matt Harbison <matt_harbison@yahoo.com>
parents: 44986
diff changeset
2266 b'reject',
45138
2010f3143062 phabupdate: allow revisions to be reopened
Matt Harbison <matt_harbison@yahoo.com>
parents: 45137
diff changeset
2267 b'reopen',
45136
1ff5070c0ab4 phabupdate: allows revisions to be marked "request-review"
Matt Harbison <matt_harbison@yahoo.com>
parents: 45135
diff changeset
2268 b'request-review',
45140
c59e7bed8924 phabupdate: allow resigning from revisions
Matt Harbison <matt_harbison@yahoo.com>
parents: 45139
diff changeset
2269 b'resign',
45135
225588c4c255 phabupdate: allow revisions to be marked with "plan changes"
Matt Harbison <matt_harbison@yahoo.com>
parents: 44986
diff changeset
2270 ]
225588c4c255 phabupdate: allow revisions to be marked with "plan changes"
Matt Harbison <matt_harbison@yahoo.com>
parents: 44986
diff changeset
2271 flags = [n for n in transactions if opts.get(n.replace(b'-', b'_'))]
33855
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33854
diff changeset
2272 if len(flags) > 1:
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
2273 raise error.Abort(_(b'%s cannot be used together') % b', '.join(flags))
33855
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33854
diff changeset
2274
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33854
diff changeset
2275 actions = []
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33854
diff changeset
2276 for f in flags:
43350
132ddd1cba85 phabricator: use True primitive instead of b'true' for phabupdate actions
Ian Moody <moz-ian@perix.co.uk>
parents: 43321
diff changeset
2277 actions.append({b'type': f, b'value': True})
33855
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33854
diff changeset
2278
46041
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2279 revs = opts.get(b'rev')
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2280 if revs:
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2281 if not repo:
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2282 raise error.InputError(_(b'--rev requires a repository'))
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2283
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2284 if specs:
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2285 raise error.InputError(_(b'cannot specify both DREVSPEC and --rev'))
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2286
48128
5ced12cfa41b errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents: 47084
diff changeset
2287 drevmap = getdrevmap(repo, logcmdutil.revrange(repo, [revs]))
46041
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2288 specs = []
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2289 unknown = []
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
2290 for r, d in drevmap.items():
46041
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2291 if d is None:
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2292 unknown.append(repo[r])
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2293 else:
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2294 specs.append(b'D%d' % d)
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2295 if unknown:
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2296 raise error.InputError(
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2297 _(b'selected revisions without a Differential: %s')
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2298 % scmutil.nodesummaries(repo, unknown)
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2299 )
9624bf057c2a phabricator: allow local revisions to be specified with `phabupdate`
Matt Harbison <matt_harbison@yahoo.com>
parents: 45985
diff changeset
2300
44588
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44587
diff changeset
2301 drevs = _getdrevs(ui, opts.get(b'stack'), specs)
33855
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33854
diff changeset
2302 for i, drev in enumerate(drevs):
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
2303 if i + 1 == len(drevs) and opts.get(b'comment'):
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
2304 actions.append({b'type': b'comment', b'value': opts[b'comment']})
33855
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33854
diff changeset
2305 if actions:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2306 params = {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2307 b'objectIdentifier': drev[b'phid'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2308 b'transactions': actions,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2309 }
42450
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42449
diff changeset
2310 callconduit(ui, b'differential.revision.edit', params)
35722
f18ba40d792f phabricator: add a template item for linking to a differential review
Tom Prince <mozilla@hocat.ca>
parents: 35626
diff changeset
2311
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2312
42975
24bf7a3d3c30 phabricator: use exthelper to register commands, config, and templates
Matt Harbison <matt_harbison@yahoo.com>
parents: 42955
diff changeset
2313 @eh.templatekeyword(b'phabreview', requires={b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 35722
diff changeset
2314 def template_review(context, mapping):
35722
f18ba40d792f phabricator: add a template item for linking to a differential review
Tom Prince <mozilla@hocat.ca>
parents: 35626
diff changeset
2315 """:phabreview: Object describing the review for this changeset.
f18ba40d792f phabricator: add a template item for linking to a differential review
Tom Prince <mozilla@hocat.ca>
parents: 35626
diff changeset
2316 Has attributes `url` and `id`.
f18ba40d792f phabricator: add a template item for linking to a differential review
Tom Prince <mozilla@hocat.ca>
parents: 35626
diff changeset
2317 """
38398
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38342
diff changeset
2318 ctx = context.resource(mapping, b'ctx')
35722
f18ba40d792f phabricator: add a template item for linking to a differential review
Tom Prince <mozilla@hocat.ca>
parents: 35626
diff changeset
2319 m = _differentialrevisiondescre.search(ctx.description())
f18ba40d792f phabricator: add a template item for linking to a differential review
Tom Prince <mozilla@hocat.ca>
parents: 35626
diff changeset
2320 if m:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2321 return templateutil.hybriddict(
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
2322 {
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
2323 b'url': m.group('url'),
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
2324 b'id': b"D%s" % m.group('id'),
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
2325 }
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2326 )
41164
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
2327 else:
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
2328 tags = ctx.repo().nodetags(ctx.node())
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
2329 for t in tags:
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
2330 if _differentialrevisiontagre.match(t):
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
2331 url = ctx.repo().ui.config(b'phabricator', b'url')
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
2332 if not url.endswith(b'/'):
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
2333 url += b'/'
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
2334 url += t
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
2335
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
2336 return templateutil.hybriddict(
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
2337 {
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
2338 b'url': url,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
2339 b'id': t,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
2340 }
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
2341 )
41164
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
2342 return None
43857
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2343
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2344
43858
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2345 @eh.templatekeyword(b'phabstatus', requires={b'ctx', b'repo', b'ui'})
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2346 def template_status(context, mapping):
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
2347 """:phabstatus: String. Status of Phabricator differential."""
43858
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2348 ctx = context.resource(mapping, b'ctx')
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2349 repo = context.resource(mapping, b'repo')
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2350 ui = context.resource(mapping, b'ui')
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2351
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2352 rev = ctx.rev()
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2353 try:
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2354 drevid = getdrevmap(repo, [rev])[rev]
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2355 except KeyError:
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2356 return None
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2357 drevs = callconduit(ui, b'differential.query', {b'ids': [drevid]})
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2358 for drev in drevs:
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2359 if int(drev[b'id']) == drevid:
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2360 return templateutil.hybriddict(
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
2361 {
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
2362 b'url': drev[b'uri'],
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
2363 b'status': drev[b'statusName'],
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45795
diff changeset
2364 }
43858
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2365 )
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2366 return None
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2367
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43857
diff changeset
2368
43857
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2369 @show.showview(b'phabstatus', csettopic=b'work')
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2370 def phabstatusshowview(ui, repo, displayer):
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2371 """Phabricator differiential status"""
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2372 revs = repo.revs('sort(_underway(), topo)')
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2373 drevmap = getdrevmap(repo, revs)
44470
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 44456
diff changeset
2374 unknownrevs, drevids, revsbydrevid = [], set(), {}
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
2375 for rev, drevid in drevmap.items():
43857
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2376 if drevid is not None:
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2377 drevids.add(drevid)
44470
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 44456
diff changeset
2378 revsbydrevid.setdefault(drevid, set()).add(rev)
43857
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2379 else:
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2380 unknownrevs.append(rev)
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2381
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2382 drevs = callconduit(ui, b'differential.query', {b'ids': list(drevids)})
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2383 drevsbyrev = {}
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2384 for drev in drevs:
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2385 for rev in revsbydrevid[int(drev[b'id'])]:
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2386 drevsbyrev[rev] = drev
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2387
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2388 def phabstatus(ctx):
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2389 drev = drevsbyrev[ctx.rev()]
43869
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43868
diff changeset
2390 status = ui.label(
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43868
diff changeset
2391 b'%(statusName)s' % drev,
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43868
diff changeset
2392 b'phabricator.status.%s' % _getstatusname(drev),
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43868
diff changeset
2393 )
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43868
diff changeset
2394 ui.write(b"\n%s %s\n" % (drev[b'uri'], status))
43857
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2395
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2396 revs -= smartset.baseset(unknownrevs)
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2397 revdag = graphmod.dagwalker(repo, revs)
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2398
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2399 ui.setconfig(b'experimental', b'graphshorten', True)
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2400 displayer._exthook = phabstatus
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2401 nodelen = show.longestshortest(repo, revs)
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2402 logcmdutil.displaygraph(
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2403 ui,
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2404 repo,
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2405 revdag,
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2406 displayer,
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2407 graphmod.asciiedges,
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2408 props={b'nodelen': nodelen},
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43847
diff changeset
2409 )