annotate hgext/phabricator.py @ 44648:949a87145336

phabricator: extract logic to print the status when posting a commit This will make it easier to list each commit when folding. That makes the output less confusing because it matches the output of `--confirm` and the revisions listed on the command line. Differential Revision: https://phab.mercurial-scm.org/D8313
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 18 Mar 2020 14:53:53 -0400
parents 99fa161a883c
children 38f7b2f02f6d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33198
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.
39655
87539f615b87 phabricator: mark extension as experimental for now
Augie Fackler <raf@durin42.com>
parents: 39654
diff changeset
7 """simple Phabricator integration (EXPERIMENTAL)
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
8
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
9 This extension provides a ``phabsend`` command which sends a stack of
33975
07ffff841863 phabsend: make --amend the default
Jun Wu <quark@fb.com>
parents: 33974
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: 33974
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: 33974
diff changeset
12 to update statuses in batch.
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
13
43839
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
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: 43829
diff changeset
15 information of Phabricator differentials associated with unfinished
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
16 changesets.
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
17
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
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: 33198
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: 33198
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: 33198
diff changeset
21
33198
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
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
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: 33198
diff changeset
29 # callsign is "FOO".
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
30 callsign = FOO
33200
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33199
diff changeset
31
34064
8b659b7388c0 phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents: 34063
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: 34063
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: 34063
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: 34063
diff changeset
35 # the internal library.
8b659b7388c0 phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents: 34063
diff changeset
36 curlcmd = curl --connect-timeout 2 --retry 3 --silent
36787
4397909f82d3 phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents: 36514
diff changeset
37
37996
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 37976
diff changeset
38 [auth]
37997
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 37996
diff changeset
39 example.schemes = https
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 37996
diff changeset
40 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: 37996
diff changeset
41
36787
4397909f82d3 phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents: 36514
diff changeset
42 # API token. Get it from https://$HOST/conduit/login/
37996
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 37976
diff changeset
43 example.phabtoken = cli-xxxxxxxxxxxxxxxxxxxxxxxxxxxx
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
44 """
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
45
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
46 from __future__ import absolute_import
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
47
43187
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
48 import base64
41080
9d35ae3d9999 phabricator: ensure that the return of urlopener.open() is closed
Matt Harbison <matt_harbison@yahoo.com>
parents: 41078
diff changeset
49 import contextlib
43188
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
50 import hashlib
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
51 import itertools
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
52 import json
43189
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
53 import mimetypes
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
54 import operator
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
55 import re
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
56
33443
e48082e0a8d5 phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
57 from mercurial.node import bin, nullid
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
58 from mercurial.i18n import _
43089
c59eb1560c44 py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43080
diff changeset
59 from mercurial.pycompat import getattr
43183
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
60 from mercurial.thirdparty import attr
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
61 from mercurial import (
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
62 cmdutil,
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
63 context,
44610
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44609
diff changeset
64 copies,
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
65 encoding,
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
66 error,
42973
24bf7a3d3c30 phabricator: use exthelper to register commands, config, and templates
Matt Harbison <matt_harbison@yahoo.com>
parents: 42951
diff changeset
67 exthelper,
43839
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
68 graphmod,
37997
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 37996
diff changeset
69 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
70 localrepo,
43839
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
71 logcmdutil,
43186
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
72 match,
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
73 mdiff,
33735
e6d8ee3c9ec3 obsutil: rename allprecursors into allpredecessors
Boris Feld <boris.feld@octobus.net>
parents: 33692
diff changeset
74 obsutil,
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
75 parser,
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
76 patch,
41163
0101a35deae2 phabricator: warn if unable to amend, instead of aborting after posting
Matt Harbison <matt_harbison@yahoo.com>
parents: 41080
diff changeset
77 phases,
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
78 pycompat,
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
79 scmutil,
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
80 smartset,
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
81 tags,
42188
289d82a070e9 phabricator: use templatefilters.json in writediffproperties
Ian Moody <moz-ian@perix.co.uk>
parents: 41971
diff changeset
82 templatefilters,
39654
4057e38bba76 phabricator: fix templating bug by using hybriddict
Augie Fackler <raf@durin42.com>
parents: 39652
diff changeset
83 templateutil,
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
84 url as urlmod,
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
85 util,
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
86 )
37120
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36818
diff changeset
87 from mercurial.utils import (
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36818
diff changeset
88 procutil,
37800
6cf5f5b4eb57 phabricator: specify some metadata compatibly with arc
Tom Prince <mozilla@hocat.ca>
parents: 37120
diff changeset
89 stringutil,
37120
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36818
diff changeset
90 )
43839
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
91 from . import show
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
92
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
93
39735
c0c703861b60 phabricator: add testedwith boilerplate
Yuya Nishihara <yuya@tcha.org>
parents: 39655
diff changeset
94 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
c0c703861b60 phabricator: add testedwith boilerplate
Yuya Nishihara <yuya@tcha.org>
parents: 39655
diff changeset
95 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
c0c703861b60 phabricator: add testedwith boilerplate
Yuya Nishihara <yuya@tcha.org>
parents: 39655
diff changeset
96 # be specifying the version(s) of Mercurial they are tested with, or
c0c703861b60 phabricator: add testedwith boilerplate
Yuya Nishihara <yuya@tcha.org>
parents: 39655
diff changeset
97 # leave the attribute unspecified.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
98 testedwith = b'ships-with-hg-core'
39735
c0c703861b60 phabricator: add testedwith boilerplate
Yuya Nishihara <yuya@tcha.org>
parents: 39655
diff changeset
99
42973
24bf7a3d3c30 phabricator: use exthelper to register commands, config, and templates
Matt Harbison <matt_harbison@yahoo.com>
parents: 42951
diff changeset
100 eh = exthelper.exthelper()
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
101
42973
24bf7a3d3c30 phabricator: use exthelper to register commands, config, and templates
Matt Harbison <matt_harbison@yahoo.com>
parents: 42951
diff changeset
102 cmdtable = eh.cmdtable
24bf7a3d3c30 phabricator: use exthelper to register commands, config, and templates
Matt Harbison <matt_harbison@yahoo.com>
parents: 42951
diff changeset
103 command = eh.command
24bf7a3d3c30 phabricator: use exthelper to register commands, config, and templates
Matt Harbison <matt_harbison@yahoo.com>
parents: 42951
diff changeset
104 configtable = eh.configtable
24bf7a3d3c30 phabricator: use exthelper to register commands, config, and templates
Matt Harbison <matt_harbison@yahoo.com>
parents: 42951
diff changeset
105 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
106 uisetup = eh.finaluisetup
38042
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 37997
diff changeset
107
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 37997
diff changeset
108 # developer config: phabricator.batchsize
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
109 eh.configitem(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
110 b'phabricator', b'batchsize', default=12,
38042
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 37997
diff changeset
111 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
112 eh.configitem(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
113 b'phabricator', b'callsign', default=None,
38042
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 37997
diff changeset
114 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
115 eh.configitem(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
116 b'phabricator', b'curlcmd', default=None,
38042
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 37997
diff changeset
117 )
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 37997
diff changeset
118 # developer config: phabricator.repophid
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
119 eh.configitem(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
120 b'phabricator', b'repophid', default=None,
38042
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 37997
diff changeset
121 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
122 eh.configitem(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
123 b'phabricator', b'url', default=None,
38042
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 37997
diff changeset
124 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
125 eh.configitem(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
126 b'phabsend', b'confirm', default=False,
38042
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 37997
diff changeset
127 )
44551
9bae1d1a0f4c phabricator: add a config knob to import in the secret phase
Matt Harbison <matt_harbison@yahoo.com>
parents: 44550
diff changeset
128 eh.configitem(
9bae1d1a0f4c phabricator: add a config knob to import in the secret phase
Matt Harbison <matt_harbison@yahoo.com>
parents: 44550
diff changeset
129 b'phabimport', b'secret', default=False,
9bae1d1a0f4c phabricator: add a config knob to import in the secret phase
Matt Harbison <matt_harbison@yahoo.com>
parents: 44550
diff changeset
130 )
44552
f10055b099b3 phabricator: add a config knob to create obsolete markers when importing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44551
diff changeset
131 eh.configitem(
f10055b099b3 phabricator: add a config knob to create obsolete markers when importing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44551
diff changeset
132 b'phabimport', b'obsolete', default=False,
f10055b099b3 phabricator: add a config knob to create obsolete markers when importing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44551
diff changeset
133 )
38042
5a7cf42ba6ef phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents: 37997
diff changeset
134
34063
941c33cfde81 phabricator: standardize colors
Jun Wu <quark@fb.com>
parents: 33978
diff changeset
135 colortable = {
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
136 b'phabricator.action.created': b'green',
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
137 b'phabricator.action.skipped': b'magenta',
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
138 b'phabricator.action.updated': b'magenta',
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
139 b'phabricator.desc': b'',
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
140 b'phabricator.drev': b'bold',
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
141 b'phabricator.node': b'',
43858
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43857
diff changeset
142 b'phabricator.status.abandoned': b'magenta dim',
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43857
diff changeset
143 b'phabricator.status.accepted': b'green bold',
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43857
diff changeset
144 b'phabricator.status.closed': b'green',
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43857
diff changeset
145 b'phabricator.status.needsreview': b'yellow',
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43857
diff changeset
146 b'phabricator.status.needsrevision': b'red',
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43857
diff changeset
147 b'phabricator.status.changesplanned': b'red',
34063
941c33cfde81 phabricator: standardize colors
Jun Wu <quark@fb.com>
parents: 33978
diff changeset
148 }
941c33cfde81 phabricator: standardize colors
Jun Wu <quark@fb.com>
parents: 33978
diff changeset
149
39650
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38945
diff changeset
150 _VCR_FLAGS = [
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
151 (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
152 b'',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
153 b'test-vcr',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
154 b'',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
155 _(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
156 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
157 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
158 b' (ADVANCED)'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
159 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
160 ),
39650
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38945
diff changeset
161 ]
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38945
diff changeset
162
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
163
44127
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
164 @eh.wrapfunction(localrepo, "loadhgrc")
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
165 def _loadhgrc(orig, ui, wdirvfs, hgvfs, requirements):
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
166 """Load ``.arcconfig`` content into a ui instance on repository open.
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
167 """
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
168 result = False
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
169 arcconfig = {}
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
170
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
171 try:
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
172 # 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
173 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
174 # 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
175 arcconfig = pycompat.rapply(
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
176 lambda x: encoding.unitolocal(x)
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
177 if isinstance(x, pycompat.unicode)
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
178 else x,
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
179 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
180 )
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
181
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
182 result = True
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
183 except ValueError:
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
184 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
185 except IOError:
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
186 pass
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
187
44128
ff396501e841 phabricator: use .arcconfig for `phabricator.url` if not set locally
Matt Harbison <matt_harbison@yahoo.com>
parents: 44127
diff changeset
188 cfg = util.sortdict()
ff396501e841 phabricator: use .arcconfig for `phabricator.url` if not set locally
Matt Harbison <matt_harbison@yahoo.com>
parents: 44127
diff changeset
189
44127
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
190 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
191 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
192
ff396501e841 phabricator: use .arcconfig for `phabricator.url` if not set locally
Matt Harbison <matt_harbison@yahoo.com>
parents: 44127
diff changeset
193 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
194 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
195
ff396501e841 phabricator: use .arcconfig for `phabricator.url` if not set locally
Matt Harbison <matt_harbison@yahoo.com>
parents: 44127
diff changeset
196 if cfg:
ff396501e841 phabricator: use .arcconfig for `phabricator.url` if not set locally
Matt Harbison <matt_harbison@yahoo.com>
parents: 44127
diff changeset
197 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
198
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
199 return orig(ui, wdirvfs, hgvfs, requirements) or result # Load .hg/hgrc
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
200
59b3fe1e2021 phabricator: use .arcconfig for the callsign if not set locally (issue6243)
Matt Harbison <matt_harbison@yahoo.com>
parents: 44076
diff changeset
201
42435
16312ea45a8b phabricator: make `hg debugcallconduit` work outside a hg repo
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42434
diff changeset
202 def vcrcommand(name, flags, spec, helpcategory=None, optionalrepo=False):
39650
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38945
diff changeset
203 fullflags = flags + _VCR_FLAGS
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
204
42268
af13e2088f77 phabricator: add custom vcr matcher to match request bodies
Ian Moody <moz-ian@perix.co.uk>
parents: 42258
diff changeset
205 def hgmatcher(r1, r2):
af13e2088f77 phabricator: add custom vcr matcher to match request bodies
Ian Moody <moz-ian@perix.co.uk>
parents: 42258
diff changeset
206 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: 42258
diff changeset
207 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
208 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
209 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
210 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
211 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
212 return False
a4da1c3b82ab phabricator: update hgmatcher to cope with the new data format
Ian Moody <moz-ian@perix.co.uk>
parents: 43263
diff changeset
213 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
214 # 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
215 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
216 r1json = pycompat.json_loads(value)
579672b347d2 py3: define and use json.loads polyfill
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43350
diff changeset
217 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
218 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
219 return False
a4da1c3b82ab phabricator: update hgmatcher to cope with the new data format
Ian Moody <moz-ian@perix.co.uk>
parents: 43263
diff changeset
220 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
221 return False
a4da1c3b82ab phabricator: update hgmatcher to cope with the new data format
Ian Moody <moz-ian@perix.co.uk>
parents: 43263
diff changeset
222 return True
42268
af13e2088f77 phabricator: add custom vcr matcher to match request bodies
Ian Moody <moz-ian@perix.co.uk>
parents: 42258
diff changeset
223
42443
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42435
diff changeset
224 def sanitiserequest(request):
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42435
diff changeset
225 request.body = re.sub(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
226 br'cli-[a-z0-9]+', br'cli-hahayouwish', request.body
42443
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42435
diff changeset
227 )
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42435
diff changeset
228 return request
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42435
diff changeset
229
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42435
diff changeset
230 def sanitiseresponse(response):
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43504
diff changeset
231 if 'set-cookie' in response['headers']:
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43504
diff changeset
232 del response['headers']['set-cookie']
42443
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42435
diff changeset
233 return response
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42435
diff changeset
234
39650
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38945
diff changeset
235 def decorate(fn):
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38945
diff changeset
236 def inner(*args, **kwargs):
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43504
diff changeset
237 cassette = pycompat.fsdecode(kwargs.pop('test_vcr', None))
39650
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38945
diff changeset
238 if cassette:
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38945
diff changeset
239 import hgdemandimport
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
240
39650
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38945
diff changeset
241 with hgdemandimport.deactivated():
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38945
diff changeset
242 import vcr as vcrmod
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38945
diff changeset
243 import vcr.stubs as stubs
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
244
40378
b015f30a91fb phabricator: do more of the VCR work in demandimport.deactivated()
Augie Fackler <augie@google.com>
parents: 40151
diff changeset
245 vcr = vcrmod.VCR(
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43504
diff changeset
246 serializer='json',
42443
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42435
diff changeset
247 before_record_request=sanitiserequest,
d3c81439e2ee phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings
Ian Moody <moz-ian@perix.co.uk>
parents: 42435
diff changeset
248 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
249 custom_patches=[
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
250 (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
251 urlmod,
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43504
diff changeset
252 'httpconnection',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
253 stubs.VCRHTTPConnection,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
254 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
255 (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
256 urlmod,
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43504
diff changeset
257 'httpsconnection',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
258 stubs.VCRHTTPSConnection,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
259 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
260 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
261 )
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43504
diff changeset
262 vcr.register_matcher('hgmatcher', hgmatcher)
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43504
diff changeset
263 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
264 return fn(*args, **kwargs)
39650
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38945
diff changeset
265 return fn(*args, **kwargs)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
266
44436
09f3e003fc2a phabricator: avoid a stacktrace when command arguments are missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44427
diff changeset
267 cmd = util.checksignature(inner, depth=2)
09f3e003fc2a phabricator: avoid a stacktrace when command arguments are missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44427
diff changeset
268 cmd.__name__ = fn.__name__
09f3e003fc2a phabricator: avoid a stacktrace when command arguments are missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44427
diff changeset
269 cmd.__doc__ = fn.__doc__
09f3e003fc2a phabricator: avoid a stacktrace when command arguments are missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44427
diff changeset
270
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
271 return command(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
272 name,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
273 fullflags,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
274 spec,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
275 helpcategory=helpcategory,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
276 optionalrepo=optionalrepo,
44436
09f3e003fc2a phabricator: avoid a stacktrace when command arguments are missing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44427
diff changeset
277 )(cmd)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
278
39650
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38945
diff changeset
279 return decorate
d8f07b16abfc phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents: 38945
diff changeset
280
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
281
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
282 def urlencodenested(params):
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
283 """like urlencode, but works with nested parameters.
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
284
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
285 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
286 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
287 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
288 """
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
289 flatparams = util.sortdict()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
290
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
291 def process(prefix, obj):
41017
d7d3164e6a31 phabricator: properly encode boolean types in the request body
Matt Harbison <matt_harbison@yahoo.com>
parents: 40546
diff changeset
292 if isinstance(obj, bool):
d7d3164e6a31 phabricator: properly encode boolean types in the request body
Matt Harbison <matt_harbison@yahoo.com>
parents: 40546
diff changeset
293 obj = {True: b'true', False: b'false'}[obj] # Python -> PHP form
41900
47125193bad0 py3: convert indexes into bytes when enumerating lists in urlencodenested
Ian Moody <moz-ian@perix.co.uk>
parents: 41899
diff changeset
294 lister = lambda l: [(b'%d' % k, v) for k, v in enumerate(l)]
47125193bad0 py3: convert indexes into bytes when enumerating lists in urlencodenested
Ian Moody <moz-ian@perix.co.uk>
parents: 41899
diff changeset
295 items = {list: lister, dict: lambda x: x.items()}.get(type(obj))
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
296 if items is None:
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
297 flatparams[prefix] = obj
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
298 else:
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
299 for k, v in items(obj):
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
300 if prefix:
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
301 process(b'%s[%s]' % (prefix, k), v)
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
302 else:
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
303 process(k, v)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
304
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
305 process(b'', params)
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
306 return util.urlreq.urlencode(flatparams)
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
307
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
308
42433
500b64c5d991 phabricator: pass ui into readurltoken instead of passing repo
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42431
diff changeset
309 def readurltoken(ui):
37996
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 37976
diff changeset
310 """return conduit url, token and make sure they exist
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 37976
diff changeset
311
37997
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 37996
diff changeset
312 Currently read from [auth] config section. In the future, it might
37996
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 37976
diff changeset
313 make sense to read from .arcconfig and .arcrc as well.
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 37976
diff changeset
314 """
42433
500b64c5d991 phabricator: pass ui into readurltoken instead of passing repo
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42431
diff changeset
315 url = ui.config(b'phabricator', b'url')
37996
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 37976
diff changeset
316 if not url:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
317 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
318 _(b'config %s.%s is required') % (b'phabricator', b'url')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
319 )
37996
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 37976
diff changeset
320
42433
500b64c5d991 phabricator: pass ui into readurltoken instead of passing repo
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42431
diff changeset
321 res = httpconnectionmod.readauthforuri(ui, url, util.url(url).user)
37997
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 37996
diff changeset
322 token = None
37996
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 37976
diff changeset
323
37997
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 37996
diff changeset
324 if res:
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 37996
diff changeset
325 group, auth = res
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 37996
diff changeset
326
42433
500b64c5d991 phabricator: pass ui into readurltoken instead of passing repo
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42431
diff changeset
327 ui.debug(b"using auth.%s.* for authentication\n" % group)
37997
71cf20d47f25 phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents: 37996
diff changeset
328
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
329 token = auth.get(b'phabtoken')
37996
0fa050bc68cb phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents: 37976
diff changeset
330
36787
4397909f82d3 phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents: 36514
diff changeset
331 if not token:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
332 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
333 _(b'Can\'t find conduit token associated to %s') % (url,)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
334 )
36787
4397909f82d3 phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents: 36514
diff changeset
335
4397909f82d3 phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents: 36514
diff changeset
336 return url, token
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
337
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
338
42434
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42433
diff changeset
339 def callconduit(ui, name, params):
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
340 """call Conduit API, params is a dict. return json.loads result, or None"""
42434
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42433
diff changeset
341 host, token = readurltoken(ui)
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
342 url, authinfo = util.url(b'/'.join([host, b'api', name])).authinfo()
42434
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42433
diff changeset
343 ui.debug(b'Conduit Call: %s %s\n' % (url, pycompat.byterepr(params)))
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
344 params = params.copy()
43261
f5aa4a53acd1 phabricator: change conduit data format to match arcanist
Ian Moody <moz-ian@perix.co.uk>
parents: 43259
diff changeset
345 params[b'__conduit__'] = {
f5aa4a53acd1 phabricator: change conduit data format to match arcanist
Ian Moody <moz-ian@perix.co.uk>
parents: 43259
diff changeset
346 b'token': token,
f5aa4a53acd1 phabricator: change conduit data format to match arcanist
Ian Moody <moz-ian@perix.co.uk>
parents: 43259
diff changeset
347 }
f5aa4a53acd1 phabricator: change conduit data format to match arcanist
Ian Moody <moz-ian@perix.co.uk>
parents: 43259
diff changeset
348 rawdata = {
f5aa4a53acd1 phabricator: change conduit data format to match arcanist
Ian Moody <moz-ian@perix.co.uk>
parents: 43259
diff changeset
349 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
350 b'output': b'json',
f5aa4a53acd1 phabricator: change conduit data format to match arcanist
Ian Moody <moz-ian@perix.co.uk>
parents: 43259
diff changeset
351 b'__conduit__': 1,
f5aa4a53acd1 phabricator: change conduit data format to match arcanist
Ian Moody <moz-ian@perix.co.uk>
parents: 43259
diff changeset
352 }
f5aa4a53acd1 phabricator: change conduit data format to match arcanist
Ian Moody <moz-ian@perix.co.uk>
parents: 43259
diff changeset
353 data = urlencodenested(rawdata)
42434
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42433
diff changeset
354 curlcmd = ui.config(b'phabricator', b'curlcmd')
34064
8b659b7388c0 phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents: 34063
diff changeset
355 if curlcmd:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
356 sin, sout = procutil.popen2(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
357 b'%s -d @- %s' % (curlcmd, procutil.shellquote(url))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
358 )
34064
8b659b7388c0 phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents: 34063
diff changeset
359 sin.write(data)
8b659b7388c0 phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents: 34063
diff changeset
360 sin.close()
8b659b7388c0 phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents: 34063
diff changeset
361 body = sout.read()
8b659b7388c0 phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents: 34063
diff changeset
362 else:
42434
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42433
diff changeset
363 urlopener = urlmod.opener(ui, authinfo)
41901
a98dabdb5a7b py3: convert URL to str before passing it to request
Ian Moody <moz-ian@perix.co.uk>
parents: 41900
diff changeset
364 request = util.urlreq.request(pycompat.strurl(url), data=data)
41080
9d35ae3d9999 phabricator: ensure that the return of urlopener.open() is closed
Matt Harbison <matt_harbison@yahoo.com>
parents: 41078
diff changeset
365 with contextlib.closing(urlopener.open(request)) as rsp:
9d35ae3d9999 phabricator: ensure that the return of urlopener.open() is closed
Matt Harbison <matt_harbison@yahoo.com>
parents: 41078
diff changeset
366 body = rsp.read()
42434
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42433
diff changeset
367 ui.debug(b'Conduit Response: %s\n' % body)
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
368 parsed = pycompat.rapply(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
369 lambda x: encoding.unitolocal(x)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
370 if isinstance(x, pycompat.unicode)
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
371 else x,
43047
0f90c2d2d7e8 py3: fix phabricator's use of json.loads() for py3.5
Ian Moody <moz-ian@perix.co.uk>
parents: 42973
diff changeset
372 # 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
373 pycompat.json_loads(encoding.unifromlocal(body)),
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
374 )
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
375 if parsed.get(b'error_code'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
376 msg = _(b'Conduit Error (%s): %s') % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
377 parsed[b'error_code'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
378 parsed[b'error_info'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
379 )
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
380 raise error.Abort(msg)
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
381 return parsed[b'result']
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
382
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
383
42435
16312ea45a8b phabricator: make `hg debugcallconduit` work outside a hg repo
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42434
diff changeset
384 @vcrcommand(b'debugcallconduit', [], _(b'METHOD'), optionalrepo=True)
33198
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
385 def debugcallconduit(ui, repo, name):
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
386 """call Conduit API
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
387
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
388 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
389 to stdout as a JSON blob.
36b3febd739f phabricator: add a contrib script
Jun Wu <quark@fb.com>
parents:
diff changeset
390 """
41971
99e00e5c4746 py3: convert to/from bytes/unicode for json.(dump|load)s in debugcallconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41970
diff changeset
391 # 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: 41970
diff changeset
392 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: 41970
diff changeset
393 # json.loads only returns unicode strings
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
394 params = pycompat.rapply(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
395 lambda x: encoding.unitolocal(x)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
396 if isinstance(x, pycompat.unicode)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
397 else x,
43380
579672b347d2 py3: define and use json.loads polyfill
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43350
diff changeset
398 pycompat.json_loads(rawparams),
41971
99e00e5c4746 py3: convert to/from bytes/unicode for json.(dump|load)s in debugcallconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41970
diff changeset
399 )
99e00e5c4746 py3: convert to/from bytes/unicode for json.(dump|load)s in debugcallconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41970
diff changeset
400 # json.dumps only accepts unicode strings
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
401 result = pycompat.rapply(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
402 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
403 callconduit(ui, name, params),
41971
99e00e5c4746 py3: convert to/from bytes/unicode for json.(dump|load)s in debugcallconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41970
diff changeset
404 )
99e00e5c4746 py3: convert to/from bytes/unicode for json.(dump|load)s in debugcallconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41970
diff changeset
405 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: 41970
diff changeset
406 ui.write(b'%s\n' % encoding.unitolocal(s))
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
407
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
408
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
409 def getrepophid(repo):
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
410 """given callsign, return repository PHID or None"""
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
411 # developer config: phabricator.repophid
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
412 repophid = repo.ui.config(b'phabricator', b'repophid')
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
413 if repophid:
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
414 return repophid
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
415 callsign = repo.ui.config(b'phabricator', b'callsign')
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
416 if not callsign:
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
417 return None
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
418 query = callconduit(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
419 repo.ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
420 b'diffusion.repository.search',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
421 {b'constraints': {b'callsigns': [callsign]}},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
422 )
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
423 if len(query[b'data']) == 0:
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
424 return None
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
425 repophid = query[b'data'][0][b'phid']
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
426 repo.ui.setconfig(b'phabricator', b'repophid', repophid)
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
427 return repophid
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
428
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
429
41532
bd3f03d8cc9f global: use raw strings for regular expressions with escapes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41365
diff changeset
430 _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: 33200
diff changeset
431 _differentialrevisiondescre = re.compile(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
432 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
433 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
434
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
435
33442
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
436 def getoldnodedrevmap(repo, nodelist):
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
437 """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
438
33691
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
439 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
440 for node in nodelist with known previous sent versions, or associated
33691
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
441 Differential Revision IDs. ``oldnode`` and ``Differential diff`` could
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
442 be ``None``.
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
443
33691
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
444 Examines commit messages like "Differential Revision:" to get the
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
445 association information.
33263
ed61189763ef phabricator: check associated Differential Revision from commit message
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
446
33691
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
447 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: 33690
diff changeset
448 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: 33690
diff changeset
449 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: 33690
diff changeset
450
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
451 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: 33690
diff changeset
452 corresponding Differential Revision, and exist in the repo.
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
453 """
33442
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
454 unfi = repo.unfiltered()
43549
4cb3f5bb29ec index: use `index.has_node` in `phabricator.getoldnodedrevmap`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43506
diff changeset
455 has_node = unfi.changelog.index.has_node
33263
ed61189763ef phabricator: check associated Differential Revision from commit message
Jun Wu <quark@fb.com>
parents: 33200
diff changeset
456
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
457 result = {} # {node: (oldnode?, lastdiff?, drev)}
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
458 toconfirm = {} # {node: (force, {precnode}, drev)}
33442
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
459 for node in nodelist:
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
460 ctx = unfi[node]
33443
e48082e0a8d5 phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
461 # For tags like "D123", put them into "toconfirm" to verify later
33735
e6d8ee3c9ec3 obsutil: rename allprecursors into allpredecessors
Boris Feld <boris.feld@octobus.net>
parents: 33692
diff changeset
462 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
463 for n in precnodes:
43549
4cb3f5bb29ec index: use `index.has_node` in `phabricator.getoldnodedrevmap`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43506
diff changeset
464 if has_node(n):
33442
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
465 for tag in unfi.nodetags(n):
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
466 m = _differentialrevisiontagre.match(tag)
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
467 if m:
33691
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
468 toconfirm[node] = (0, set(precnodes), int(m.group(1)))
43829
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43549
diff changeset
469 break
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43549
diff changeset
470 else:
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43549
diff changeset
471 continue # move to next predecessor
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43549
diff changeset
472 break # found a tag, stop
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43549
diff changeset
473 else:
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43549
diff changeset
474 # Check commit message
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43549
diff changeset
475 m = _differentialrevisiondescre.search(ctx.description())
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43549
diff changeset
476 if m:
16b607e9f714 phabricator: fix processing of tags/desc in getoldnodedrevmap()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43549
diff changeset
477 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: 33200
diff changeset
478
33443
e48082e0a8d5 phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
479 # 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
480 # Phabricator, and expect precursors overlap with it.
e48082e0a8d5 phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
481 if toconfirm:
33691
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
482 drevs = [drev for force, precs, drev in toconfirm.values()]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
483 alldiffs = callconduit(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
484 unfi.ui, b'differential.querydiffs', {b'revisionIDs': drevs}
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
485 )
44646
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
486
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
487 def getnodes(d, precset):
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
488 # Ignore other nodes that were combined into the Differential
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
489 # that aren't predecessors of the current local node.
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
490 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: 44645
diff changeset
491
33691
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
492 for newnode, (force, precset, drev) in toconfirm.items():
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
493 diffs = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
494 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
495 ]
33691
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
496
44646
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
497 # local predecessors known by Phabricator
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
498 phprecset = {n for d in diffs for n in getnodes(d, precset)}
33691
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
499
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
500 # Ignore if precursors (Phabricator and local repo) do not overlap,
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
501 # and force is not set (when commit message says nothing)
44646
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
502 if not force and not phprecset:
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
503 tagname = b'D%d' % drev
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
504 tags.tag(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
505 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
506 tagname,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
507 nullid,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
508 message=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
509 user=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
510 date=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
511 local=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
512 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
513 unfi.ui.warn(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
514 _(
43399
742065def6ca py3: use %d to format an int
Ian Moody <moz-ian@perix.co.uk>
parents: 43380
diff changeset
515 b'D%d: local tag removed - does not match '
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
516 b'Differential history\n'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
517 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
518 % drev
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
519 )
33691
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
520 continue
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
521
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
522 # 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: 33690
diff changeset
523 # exists in the repo
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
524 oldnode = lastdiff = None
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
525 if diffs:
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
526 lastdiff = max(diffs, key=lambda d: int(d[b'id']))
44646
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
527 oldnodes = getnodes(lastdiff, precset)
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
528
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
529 # 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: 44645
diff changeset
530 # 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: 44645
diff changeset
531 # 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: 44645
diff changeset
532 # diff for the _same_ Differential Revision if this commit is
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
533 # the first or last in the selected range.
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
534 # 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: 44645
diff changeset
535 # scenario, there is a single oldnode here (and multiple
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
536 # 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: 44645
diff changeset
537 # 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: 44645
diff changeset
538 # oldnode each.
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
539 if len(oldnodes) == 1:
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
540 oldnode = oldnodes[0]
43549
4cb3f5bb29ec index: use `index.has_node` in `phabricator.getoldnodedrevmap`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43506
diff changeset
541 if oldnode and not has_node(oldnode):
33691
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
542 oldnode = None
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
543
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
544 result[newnode] = (oldnode, lastdiff, drev)
33443
e48082e0a8d5 phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
545
33442
3ab0d5767b54 phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents: 33441
diff changeset
546 return result
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
547
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
548
43839
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
549 def getdrevmap(repo, revs):
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
550 """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: 43829
diff changeset
551 ID or None.
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
552 """
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
553 result = {}
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
554 for rev in revs:
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
555 result[rev] = None
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
556 ctx = repo[rev]
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
557 # Check commit message
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
558 m = _differentialrevisiondescre.search(ctx.description())
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
559 if m:
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
560 result[rev] = int(m.group('id'))
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
561 continue
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
562 # Check tags
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
563 for tag in repo.nodetags(ctx.node()):
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
564 m = _differentialrevisiontagre.match(tag)
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
565 if m:
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
566 result[rev] = int(m.group(1))
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
567 break
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
568
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
569 return result
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
570
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
571
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
572 def getdiff(basectx, ctx, diffopts):
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
573 """plain-text diff without header (user, commit message, etc)"""
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
574 output = util.stringio()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
575 for chunk, _label in patch.diffui(
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
576 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
577 ):
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
578 output.write(chunk)
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
579 return output.getvalue()
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
580
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
581
43182
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
582 class DiffChangeType(object):
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
583 ADD = 1
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
584 CHANGE = 2
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
585 DELETE = 3
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
586 MOVE_AWAY = 4
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
587 COPY_AWAY = 5
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
588 MOVE_HERE = 6
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
589 COPY_HERE = 7
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
590 MULTICOPY = 8
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
591
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
592
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
593 class DiffFileType(object):
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
594 TEXT = 1
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
595 IMAGE = 2
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
596 BINARY = 3
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
597
a66e2844b0c6 phabricator: add the DiffChangeType and DiffFileType constants
Ian Moody <moz-ian@perix.co.uk>
parents: 43117
diff changeset
598
43183
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
599 @attr.s
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
600 class phabhunk(dict):
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
601 """Represents a Differential hunk, which is owned by a Differential change
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
602 """
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
603
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
604 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
605 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
606 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
607 newLength = attr.ib(default=0) # camelcase-required
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
608 corpus = attr.ib(default='')
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
609 # 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
610 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
611 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
612
73d4bc60e389 phabricator: add the phabhunk data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43182
diff changeset
613
43184
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
614 @attr.s
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
615 class phabchange(object):
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
616 """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
617 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
618 """
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
619
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
620 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
621 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
622 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
623 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
624 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
625 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
626 type = attr.ib(default=DiffChangeType.CHANGE)
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
627 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
628 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
629 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
630 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
631 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
632
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
633 def copynewmetadatatoold(self):
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
634 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
635 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
636 self.metadata[newkey] = self.metadata[key]
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
637
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
638 def addoldmode(self, value):
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
639 self.oldProperties[b'unix:filemode'] = value
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
640
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
641 def addnewmode(self, value):
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
642 self.newProperties[b'unix:filemode'] = value
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
643
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
644 def addhunk(self, hunk):
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
645 if not isinstance(hunk, phabhunk):
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
646 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
647 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
648 # 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
649 # 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
650 # in email subjects for the [+++--] bit.
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
651 self.addLines += hunk.addLines
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
652 self.delLines += hunk.delLines
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
653
99ee4afd352f phabricator: add the phabchange data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43183
diff changeset
654
43185
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
655 @attr.s
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
656 class phabdiff(object):
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
657 """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
658 to a commit.
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
659 """
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
660
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
661 # 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
662 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
663 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
664 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
665 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
666 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
667 branch = attr.ib(default=b'default')
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
668 bookmark = attr.ib(default=None)
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
669 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
670 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
671 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
672 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
673 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
674
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
675 def addchange(self, change):
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
676 if not isinstance(change, phabchange):
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
677 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
678 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
679 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
680 )
43185
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
681
75e7628b488f phabricator: add the phabdiff data structure
Ian Moody <moz-ian@perix.co.uk>
parents: 43184
diff changeset
682
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
683 def maketext(pchange, basectx, ctx, fname):
43186
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
684 """populate the phabchange for a text file"""
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
685 repo = ctx.repo()
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
686 fmatcher = match.exact([fname])
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
687 diffopts = mdiff.diffopts(git=True, context=32767)
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
688 _pfctx, _fctx, header, fhunks = next(
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
689 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
690 )
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
691
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
692 for fhunk in fhunks:
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
693 (oldOffset, oldLength, newOffset, newLength), lines = fhunk
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
694 corpus = b''.join(lines[1:])
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
695 shunk = list(header)
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
696 shunk.extend(lines)
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
697 _mf, _mt, addLines, delLines, _hb = patch.diffstatsum(
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
698 patch.diffstatdata(util.iterlines(shunk))
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
699 )
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
700 pchange.addhunk(
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
701 phabhunk(
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
702 oldOffset,
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
703 oldLength,
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
704 newOffset,
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
705 newLength,
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
706 corpus,
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
707 addLines,
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
708 delLines,
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
709 )
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
710 )
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
711
f742fabad507 phabricator: add the maketext function
Ian Moody <moz-ian@perix.co.uk>
parents: 43185
diff changeset
712
43187
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
713 def uploadchunks(fctx, fphid):
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
714 """upload large binary files as separate chunks.
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
715 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
716 """
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
717 ui = fctx.repo().ui
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
718 chunks = callconduit(ui, b'file.querychunks', {b'filePHID': fphid})
43504
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
719 with ui.makeprogress(
43187
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
720 _(b'uploading file chunks'), unit=_(b'chunks'), total=len(chunks)
43504
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
721 ) as progress:
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
722 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
723 progress.increment()
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
724 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
725 continue
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
726 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
727 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
728 callconduit(
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
729 ui,
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
730 b'file.uploadchunk',
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
731 {
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
732 b'filePHID': fphid,
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
733 b'byteStart': bstart,
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
734 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
735 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
736 },
a78a65c33b5a phabricator: use context manager form of progress in uploadchunks
Ian Moody <moz-ian@perix.co.uk>
parents: 43399
diff changeset
737 )
43187
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
738
453079605242 phabricator: add the uploadchunks function
Ian Moody <moz-ian@perix.co.uk>
parents: 43186
diff changeset
739
43188
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
740 def uploadfile(fctx):
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
741 """upload binary files to Phabricator"""
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
742 repo = fctx.repo()
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
743 ui = repo.ui
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
744 fname = fctx.path()
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
745 size = fctx.size()
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
746 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
747
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
748 # 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
749 # (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
750 allocateparams = {
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
751 b'name': fname,
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
752 b'contentLength': size,
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
753 b'contentHash': fhash,
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
754 }
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
755 filealloc = callconduit(ui, b'file.allocate', allocateparams)
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
756 fphid = filealloc[b'filePHID']
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
757
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
758 if filealloc[b'upload']:
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
759 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
760 if not fphid:
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
761 uploadparams = {
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
762 b'name': fname,
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
763 b'data_base64': base64.b64encode(fctx.data()),
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
764 }
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
765 fphid = callconduit(ui, b'file.upload', uploadparams)
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
766 else:
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
767 uploadchunks(fctx, fphid)
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
768 else:
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
769 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
770
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
771 if not fphid:
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
772 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
773
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
774 return fphid
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
775
24e8aac7c630 phabricator: add the uploadfile function
Ian Moody <moz-ian@perix.co.uk>
parents: 43187
diff changeset
776
44424
98f7b9cf7bfc phabricator: pass old `fctx` to `addoldbinary()` instead of inferring it
Matt Harbison <matt_harbison@yahoo.com>
parents: 44423
diff changeset
777 def addoldbinary(pchange, oldfctx, fctx):
43189
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
778 """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
779 phabchange for the new version
44424
98f7b9cf7bfc phabricator: pass old `fctx` to `addoldbinary()` instead of inferring it
Matt Harbison <matt_harbison@yahoo.com>
parents: 44423
diff changeset
780
98f7b9cf7bfc phabricator: pass old `fctx` to `addoldbinary()` instead of inferring it
Matt Harbison <matt_harbison@yahoo.com>
parents: 44423
diff changeset
781 ``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: 44423
diff changeset
782 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
783 """
44424
98f7b9cf7bfc phabricator: pass old `fctx` to `addoldbinary()` instead of inferring it
Matt Harbison <matt_harbison@yahoo.com>
parents: 44423
diff changeset
784 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
785 # Files differ, add the old one
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
786 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
787 mimeguess, _enc = mimetypes.guess_type(
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
788 encoding.unifromlocal(oldfctx.path())
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
789 )
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
790 if mimeguess:
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
791 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
792 mimeguess
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
793 )
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
794 fphid = uploadfile(oldfctx)
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
795 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
796 else:
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
797 # 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
798 pchange.fileType = DiffFileType.TEXT
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
799 pchange.copynewmetadatatoold()
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
800
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
801
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
802 def makebinary(pchange, fctx):
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
803 """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
804 pchange.fileType = DiffFileType.BINARY
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
805 fphid = uploadfile(fctx)
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
806 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
807 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
808 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
809 if mimeguess:
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
810 mimeguess = pycompat.bytestr(mimeguess)
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
811 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
812 if mimeguess.startswith(b'image/'):
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
813 pchange.fileType = DiffFileType.IMAGE
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
814
9f802243a42e phabricator: add makebinary and addoldbinary functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43188
diff changeset
815
43190
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
816 # Copied from mercurial/patch.py
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
817 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
818
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
819
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
820 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
821 """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
822 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
823 """
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
824 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
825 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
826 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
827 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
828 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
829 _(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
830 % 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
831 )
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
832 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
833
06a33a501aa2 phabricator: treat non-utf-8 text files as binary as phabricator requires
Ian Moody <moz-ian@perix.co.uk>
parents: 43262
diff changeset
834
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
835 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
836 """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
837 for fname in removed:
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
838 pchange = phabchange(
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
839 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
840 )
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
841 oldfctx = basectx.p1()[fname]
44608
7b9aaec17126 phabricator: eliminate a couple of duplicate filectx lookups
Matt Harbison <matt_harbison@yahoo.com>
parents: 44585
diff changeset
842 pchange.addoldmode(gitmode[oldfctx.flags()])
44425
aa9979bb6853 phabricator: rename a variable to clarify that it is the parent filecontext
Matt Harbison <matt_harbison@yahoo.com>
parents: 44424
diff changeset
843 if not (oldfctx.isbinary() or notutf8(oldfctx)):
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
844 maketext(pchange, basectx, ctx, fname)
43190
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
845
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
846 pdiff.addchange(pchange)
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
847
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
848
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
849 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
850 """add modified files to the phabdiff"""
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
851 for fname in modified:
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
852 fctx = ctx[fname]
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
853 oldfctx = basectx.p1()[fname]
43190
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
854 pchange = phabchange(currentPath=fname, oldPath=fname)
44608
7b9aaec17126 phabricator: eliminate a couple of duplicate filectx lookups
Matt Harbison <matt_harbison@yahoo.com>
parents: 44585
diff changeset
855 filemode = gitmode[fctx.flags()]
7b9aaec17126 phabricator: eliminate a couple of duplicate filectx lookups
Matt Harbison <matt_harbison@yahoo.com>
parents: 44585
diff changeset
856 originalmode = gitmode[oldfctx.flags()]
43190
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
857 if filemode != originalmode:
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
858 pchange.addoldmode(originalmode)
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
859 pchange.addnewmode(filemode)
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
860
44427
4ce2330f2d0b phabricator: also check parent fctx for binary where it is checked for UTF-8
Matt Harbison <matt_harbison@yahoo.com>
parents: 44426
diff changeset
861 if (
4ce2330f2d0b phabricator: also check parent fctx for binary where it is checked for UTF-8
Matt Harbison <matt_harbison@yahoo.com>
parents: 44426
diff changeset
862 fctx.isbinary()
4ce2330f2d0b phabricator: also check parent fctx for binary where it is checked for UTF-8
Matt Harbison <matt_harbison@yahoo.com>
parents: 44426
diff changeset
863 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: 44426
diff changeset
864 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: 44426
diff changeset
865 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: 44426
diff changeset
866 ):
43190
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
867 makebinary(pchange, fctx)
44608
7b9aaec17126 phabricator: eliminate a couple of duplicate filectx lookups
Matt Harbison <matt_harbison@yahoo.com>
parents: 44585
diff changeset
868 addoldbinary(pchange, oldfctx, fctx)
43190
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
869 else:
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
870 maketext(pchange, basectx, ctx, fname)
43190
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
871
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
872 pdiff.addchange(pchange)
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
873
c19b327017b9 phabricator: add addremoved and addmodified functions
Ian Moody <moz-ian@perix.co.uk>
parents: 43189
diff changeset
874
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
875 def addadded(pdiff, basectx, ctx, added, removed):
43258
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
876 """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
877 # 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
878 # 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
879 copiedchanges = {}
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
880 movedchanges = {}
44610
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44609
diff changeset
881
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44609
diff changeset
882 copy = {}
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44609
diff changeset
883 if basectx != ctx:
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44609
diff changeset
884 copy = copies.pathcopies(basectx.p1(), ctx)
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44609
diff changeset
885
43258
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
886 for fname in added:
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
887 fctx = ctx[fname]
44426
66a05dbb8b4c phabricator: don't infer the old `fctx` in `notutf8()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44425
diff changeset
888 oldfctx = None
43258
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
889 pchange = phabchange(currentPath=fname)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
890
44608
7b9aaec17126 phabricator: eliminate a couple of duplicate filectx lookups
Matt Harbison <matt_harbison@yahoo.com>
parents: 44585
diff changeset
891 filemode = gitmode[fctx.flags()]
44610
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44609
diff changeset
892
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44609
diff changeset
893 if copy:
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44609
diff changeset
894 originalfname = copy.get(fname, fname)
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44609
diff changeset
895 else:
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44609
diff changeset
896 originalfname = fname
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44609
diff changeset
897 if fctx.renamed():
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44609
diff changeset
898 originalfname = fctx.renamed()[0]
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44609
diff changeset
899
022bf71515c9 phabricator: account for `basectx != ctx` when calculating renames
Matt Harbison <matt_harbison@yahoo.com>
parents: 44609
diff changeset
900 renamed = fname != originalfname
43258
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
901
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
902 if renamed:
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
903 oldfctx = basectx.p1()[originalfname]
44426
66a05dbb8b4c phabricator: don't infer the old `fctx` in `notutf8()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44425
diff changeset
904 originalmode = gitmode[oldfctx.flags()]
43258
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
905 pchange.oldPath = originalfname
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
906
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
907 if originalfname in removed:
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
908 origpchange = phabchange(
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
909 currentPath=originalfname,
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
910 oldPath=originalfname,
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
911 type=DiffChangeType.MOVE_AWAY,
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
912 awayPaths=[fname],
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
913 )
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
914 movedchanges[originalfname] = origpchange
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
915 removed.remove(originalfname)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
916 pchange.type = DiffChangeType.MOVE_HERE
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
917 elif originalfname in movedchanges:
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
918 movedchanges[originalfname].type = DiffChangeType.MULTICOPY
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
919 movedchanges[originalfname].awayPaths.append(fname)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
920 pchange.type = DiffChangeType.COPY_HERE
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
921 else: # pure copy
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
922 if originalfname not in copiedchanges:
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
923 origpchange = phabchange(
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
924 currentPath=originalfname, type=DiffChangeType.COPY_AWAY
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
925 )
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
926 copiedchanges[originalfname] = origpchange
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
927 else:
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
928 origpchange = copiedchanges[originalfname]
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
929 origpchange.awayPaths.append(fname)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
930 pchange.type = DiffChangeType.COPY_HERE
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
931
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
932 if filemode != originalmode:
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
933 pchange.addoldmode(originalmode)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
934 pchange.addnewmode(filemode)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
935 else: # Brand-new file
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
936 pchange.addnewmode(gitmode[fctx.flags()])
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
937 pchange.type = DiffChangeType.ADD
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
938
44427
4ce2330f2d0b phabricator: also check parent fctx for binary where it is checked for UTF-8
Matt Harbison <matt_harbison@yahoo.com>
parents: 44426
diff changeset
939 if (
4ce2330f2d0b phabricator: also check parent fctx for binary where it is checked for UTF-8
Matt Harbison <matt_harbison@yahoo.com>
parents: 44426
diff changeset
940 fctx.isbinary()
4ce2330f2d0b phabricator: also check parent fctx for binary where it is checked for UTF-8
Matt Harbison <matt_harbison@yahoo.com>
parents: 44426
diff changeset
941 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: 44426
diff changeset
942 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: 44426
diff changeset
943 ):
43258
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
944 makebinary(pchange, fctx)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
945 if renamed:
44426
66a05dbb8b4c phabricator: don't infer the old `fctx` in `notutf8()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44425
diff changeset
946 addoldbinary(pchange, oldfctx, fctx)
43258
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
947 else:
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
948 maketext(pchange, basectx, ctx, fname)
43258
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
949
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
950 pdiff.addchange(pchange)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
951
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
952 for _path, copiedchange in copiedchanges.items():
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
953 pdiff.addchange(copiedchange)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
954 for _path, movedchange in movedchanges.items():
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
955 pdiff.addchange(movedchange)
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
956
d5d1edf66091 phabricator: add addadded function
Ian Moody <moz-ian@perix.co.uk>
parents: 43190
diff changeset
957
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
958 def creatediff(basectx, ctx):
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
959 """create a Differential Diff"""
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
960 repo = ctx.repo()
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
961 repophid = getrepophid(repo)
43262
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
962 # 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
963 pdiff = phabdiff(
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
964 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
965 branch=b'%s' % ctx.branch(),
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
966 )
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
967 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
968 # 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
969 # them
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
970 addadded(pdiff, basectx, ctx, added, removed)
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
971 addmodified(pdiff, basectx, ctx, modified)
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
972 addremoved(pdiff, basectx, ctx, removed)
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
973 if repophid:
43262
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
974 pdiff.repositoryPHID = repophid
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
975 diff = callconduit(
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
976 repo.ui,
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
977 b'differential.creatediff',
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
978 pycompat.byteskwargs(attr.asdict(pdiff)),
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
979 )
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
980 if not diff:
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
981 if basectx != ctx:
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
982 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: 44608
diff changeset
983 else:
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
984 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: 44608
diff changeset
985 raise error.Abort(msg)
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
986 return diff
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
987
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
988
44643
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
989 def writediffproperties(ctxs, diff):
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
990 """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: 44610
diff changeset
991
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
992 ``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: 44610
diff changeset
993 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: 44610
diff changeset
994 ``phabsend --fold``.
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
995 """
43262
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
996 # 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
997 diffid = diff.get(b'diffid', diff.get(b'id'))
44643
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
998 basectx = ctxs[0]
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
999 tipctx = ctxs[-1]
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
1000
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1001 params = {
43262
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1002 b'diff_id': diffid,
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1003 b'name': b'hg:meta',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1004 b'data': templatefilters.json(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1005 {
44643
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
1006 b'user': tipctx.user(),
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
1007 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: 44610
diff changeset
1008 b'branch': tipctx.branch(),
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
1009 b'node': tipctx.hex(),
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
1010 b'parent': basectx.p1().hex(),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1011 }
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1012 ),
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1013 }
44643
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
1014 callconduit(basectx.repo().ui, b'differential.setdiffproperty', params)
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1015
44643
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
1016 commits = {}
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
1017 for ctx in ctxs:
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
1018 commits[ctx.hex()] = {
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
1019 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: 44610
diff changeset
1020 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: 44610
diff changeset
1021 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: 44610
diff changeset
1022 b'commit': ctx.hex(),
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
1023 b'parents': [ctx.p1().hex()],
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
1024 b'branch': ctx.branch(),
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
1025 }
37800
6cf5f5b4eb57 phabricator: specify some metadata compatibly with arc
Tom Prince <mozilla@hocat.ca>
parents: 37120
diff changeset
1026 params = {
43262
af067d29b19e phabricator: switch to the creatediff endpoint
Ian Moody <moz-ian@perix.co.uk>
parents: 43261
diff changeset
1027 b'diff_id': diffid,
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1028 b'name': b'local:commits',
44643
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
1029 b'data': templatefilters.json(commits),
37800
6cf5f5b4eb57 phabricator: specify some metadata compatibly with arc
Tom Prince <mozilla@hocat.ca>
parents: 37120
diff changeset
1030 }
44643
0437959de6f5 phabricator: record all local commits used to create a Differential revision
Matt Harbison <matt_harbison@yahoo.com>
parents: 44610
diff changeset
1031 callconduit(basectx.repo().ui, b'differential.setdiffproperty', params)
37800
6cf5f5b4eb57 phabricator: specify some metadata compatibly with arc
Tom Prince <mozilla@hocat.ca>
parents: 37120
diff changeset
1032
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1033
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1034 def createdifferentialrevision(
44645
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1035 ctxs,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1036 revid=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1037 parentrevphid=None,
44645
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1038 oldbasenode=None,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1039 oldnode=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1040 olddiff=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1041 actions=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1042 comment=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1043 ):
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1044 """create or update a Differential Revision
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1045
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1046 If revid is None, create a new Differential Revision, otherwise update
42449
c19d259fd6ad phabricator: use parents.set to always set dependencies
Ian Moody <moz-ian@perix.co.uk>
parents: 42444
diff changeset
1047 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
1048
44645
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1049 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: 44644
diff changeset
1050 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: 44644
diff changeset
1051 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: 44644
diff changeset
1052 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: 44644
diff changeset
1053
33265
95f658b558a3 phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents: 33264
diff changeset
1054 If oldnode is not None, check if the patch content (without commit message
44645
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1055 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: 44644
diff changeset
1056 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: 44644
diff changeset
1057 Revision covering multiple commits, ``oldbasenode`` corresponds to
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1058 ``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: 44644
diff changeset
1059 corresponds to ``ctxs[-1]``.
33498
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1060
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1061 If actions is not None, they will be appended to the transaction.
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1062 """
44645
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1063 ctx = ctxs[-1]
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1064 basectx = ctxs[0]
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1065
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1066 repo = ctx.repo()
33265
95f658b558a3 phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents: 33264
diff changeset
1067 if oldnode:
33976
27ff2a87d8c0 phabsend: detect patch change with larger context
Jun Wu <quark@fb.com>
parents: 33975
diff changeset
1068 diffopts = mdiff.diffopts(git=True, context=32767)
44645
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1069 unfi = repo.unfiltered()
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1070 oldctx = unfi[oldnode]
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1071 oldbasectx = unfi[oldbasenode]
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
1072 neednewdiff = getdiff(basectx, ctx, diffopts) != getdiff(
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
1073 oldbasectx, oldctx, diffopts
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
1074 )
33265
95f658b558a3 phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents: 33264
diff changeset
1075 else:
95f658b558a3 phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents: 33264
diff changeset
1076 neednewdiff = True
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1077
33265
95f658b558a3 phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents: 33264
diff changeset
1078 transactions = []
95f658b558a3 phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents: 33264
diff changeset
1079 if neednewdiff:
44609
53d75fdeaaaa phabricator: add basectx arguments to file related `phabsend` utilities
Matt Harbison <matt_harbison@yahoo.com>
parents: 44608
diff changeset
1080 diff = creatediff(basectx, ctx)
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1081 transactions.append({b'type': b'update', b'value': diff[b'phid']})
42431
29528c4235a1 phabricator: add commenting to phabsend for new/updated Diffs
Ian Moody <moz-ian@perix.co.uk>
parents: 42268
diff changeset
1082 if comment:
29528c4235a1 phabricator: add commenting to phabsend for new/updated Diffs
Ian Moody <moz-ian@perix.co.uk>
parents: 42268
diff changeset
1083 transactions.append({b'type': b'comment', b'value': comment})
33692
f100354cce52 phabricator: update diff property even if we choose not to create a new diff
Jun Wu <quark@fb.com>
parents: 33691
diff changeset
1084 else:
f100354cce52 phabricator: update diff property even if we choose not to create a new diff
Jun Wu <quark@fb.com>
parents: 33691
diff changeset
1085 # 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: 33691
diff changeset
1086 # 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: 33691
diff changeset
1087 # 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: 33691
diff changeset
1088 assert olddiff
f100354cce52 phabricator: update diff property even if we choose not to create a new diff
Jun Wu <quark@fb.com>
parents: 33691
diff changeset
1089 diff = olddiff
44645
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1090 writediffproperties(ctxs, diff)
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1091
42449
c19d259fd6ad phabricator: use parents.set to always set dependencies
Ian Moody <moz-ian@perix.co.uk>
parents: 42444
diff changeset
1092 # 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: 42444
diff changeset
1093 if parentrevphid:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1094 transactions.append(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1095 {b'type': b'parents.set', b'value': [parentrevphid]}
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1096 )
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1097
33498
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1098 if actions:
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1099 transactions += actions
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1100
44644
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1101 # 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: 44643
diff changeset
1102 # 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: 44643
diff changeset
1103 # 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: 44643
diff changeset
1104 # 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: 44643
diff changeset
1105 # 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: 44643
diff changeset
1106 # 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: 44643
diff changeset
1107 # this gets assigned to the title.
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1108 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: 44643
diff changeset
1109
44645
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1110 for i, _ctx in enumerate(ctxs):
44644
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1111 # 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: 44643
diff changeset
1112 desc = _ctx.description()
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1113 info = callconduit(
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1114 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: 44643
diff changeset
1115 )
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1116
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1117 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: 44643
diff changeset
1118 v = info[b'fields'].get(k)
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1119 if not v:
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1120 continue
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1121
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1122 if i == 0:
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1123 # 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: 44643
diff changeset
1124 # for the first commit.
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1125 fields[k] = v.rstrip()
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1126 continue
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1127 elif k == b'title':
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1128 # 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: 44643
diff changeset
1129 # message) back to the summary.
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1130 k = b'summary'
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1131
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1132 # 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: 44643
diff changeset
1133 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: 44643
diff changeset
1134
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1135 for k, v in fields.items():
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1136 transactions.append({b'type': k, b'value': v})
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1137
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1138 params = {b'transactions': transactions}
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1139 if revid is not None:
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1140 # Update an existing Differential Revision
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1141 params[b'objectIdentifier'] = revid
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1142
42434
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42433
diff changeset
1143 revision = callconduit(repo.ui, b'differential.revision.edit', params)
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1144 if not revision:
44645
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1145 if len(ctxs) == 1:
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1146 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: 44644
diff changeset
1147 else:
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1148 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: 44644
diff changeset
1149 raise error.Abort(msg)
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1150
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1151 return revision, diff
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1152
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1153
44420
ddcb51390891 phabricator: pass ui instead of repo to `userphids()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44419
diff changeset
1154 def userphids(ui, names):
33498
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1155 """convert user names to PHIDs"""
41705
570e62f1dcf2 phabricator: make user searches case-insensitive
Julien Cristau <jcristau@mozilla.com>
parents: 41532
diff changeset
1156 names = [name.lower() for name in names]
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1157 query = {b'constraints': {b'usernames': names}}
44420
ddcb51390891 phabricator: pass ui instead of repo to `userphids()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44419
diff changeset
1158 result = callconduit(ui, b'user.search', query)
33498
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1159 # 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
1160 # some names here.
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1161 data = result[b'data']
44452
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 44436
diff changeset
1162 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
1163 unresolved = set(names) - resolved
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1164 if unresolved:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1165 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1166 _(b'unknown username: %s') % b' '.join(sorted(unresolved))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1167 )
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1168 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
1169
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1170
44648
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1171 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: 44647
diff changeset
1172 """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: 44647
diff changeset
1173
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1174 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: 44647
diff changeset
1175 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: 44647
diff changeset
1176 """
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1177 actiondesc = ui.label(
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1178 {
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1179 b'created': _(b'created'),
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1180 b'skipped': _(b'skipped'),
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1181 b'updated': _(b'updated'),
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1182 }[action],
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1183 b'phabricator.action.%s' % action,
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1184 )
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1185 drevdesc = ui.label(b'D%d' % newrevid, b'phabricator.drev')
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1186 nodedesc = ui.label(bytes(ctx), b'phabricator.node')
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1187 desc = ui.label(ctx.description().split(b'\n')[0], b'phabricator.desc')
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1188 ui.write(_(b'%s - %s - %s: %s\n') % (drevdesc, actiondesc, nodedesc, desc))
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1189
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1190
44647
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44646
diff changeset
1191 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: 44646
diff changeset
1192 """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: 44646
diff changeset
1193
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44646
diff changeset
1194 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: 44646
diff changeset
1195 converts failures to warning messages.
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44646
diff changeset
1196 """
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44646
diff changeset
1197 try:
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44646
diff changeset
1198 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: 44646
diff changeset
1199 except util.urlerr.urlerror:
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44646
diff changeset
1200 # 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: 44646
diff changeset
1201 # associations will be lost
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44646
diff changeset
1202 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: 44646
diff changeset
1203
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44646
diff changeset
1204
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1205 @vcrcommand(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1206 b'phabsend',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1207 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1208 (b'r', b'rev', [], _(b'revisions to send'), _(b'REV')),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1209 (b'', b'amend', True, _(b'update commit messages')),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1210 (b'', b'reviewer', [], _(b'specify reviewers')),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1211 (b'', b'blocker', [], _(b'specify blocking reviewers')),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1212 (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1213 b'm',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1214 b'comment',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1215 b'',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1216 _(b'add a comment to Revisions with new/updated Diffs'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1217 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1218 (b'', b'confirm', None, _(b'ask for confirmation before sending')),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1219 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1220 _(b'REV [OPTIONS]'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1221 helpcategory=command.CATEGORY_IMPORT_EXPORT,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1222 )
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1223 def phabsend(ui, repo, *revs, **opts):
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1224 """upload changesets to Phabricator
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1225
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1226 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: 33198
diff changeset
1227 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: 33198
diff changeset
1228 revset.
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1229
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1230 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: 33198
diff changeset
1231 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: 33198
diff changeset
1232 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: 33198
diff changeset
1233 existing Differential Revision, or create a new one.
33690
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1234
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1235 If --amend is set, update commit messages so they have the
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1236 ``Differential Revision`` URL, remove related tags. This is similar to what
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1237 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: 33785
diff changeset
1238 use local tags to record the ``Differential Revision`` association.
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1239
33690
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1240 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
1241 can also add following to your configuration file to make it default
33974
45a8cd74de4e phabsend: polish the docstring a bit
Jun Wu <quark@fb.com>
parents: 33834
diff changeset
1242 behaviour::
33690
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1243
33974
45a8cd74de4e phabsend: polish the docstring a bit
Jun Wu <quark@fb.com>
parents: 33834
diff changeset
1244 [phabsend]
45a8cd74de4e phabsend: polish the docstring a bit
Jun Wu <quark@fb.com>
parents: 33834
diff changeset
1245 confirm = true
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1246
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1247 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: 33785
diff changeset
1248 update an existing Differential Revision, or create a new one.
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1249 """
41970
51ba9fbcca52 py3: use pycompat.byteskwargs on opts in phabricator.py
Ian Moody <moz-ian@perix.co.uk>
parents: 41950
diff changeset
1250 opts = pycompat.byteskwargs(opts)
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1251 revs = list(revs) + opts.get(b'rev', [])
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1252 revs = scmutil.revrange(repo, revs)
44076
a7c4bcf7018a phabricator: post revisions in ascending topological order (issue6241)
Matt Harbison <matt_harbison@yahoo.com>
parents: 43858
diff changeset
1253 revs.sort() # ascending order to preserve topological parent/child in phab
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1254
33266
5b2391b46906 phabricator: abort if phabsend gets empty revs
Jun Wu <quark@fb.com>
parents: 33265
diff changeset
1255 if not revs:
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1256 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: 38336
diff changeset
1257 if opts.get(b'amend'):
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1258 cmdutil.checkunfinished(repo)
33266
5b2391b46906 phabricator: abort if phabsend gets empty revs
Jun Wu <quark@fb.com>
parents: 33265
diff changeset
1259
33978
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33977
diff changeset
1260 # {newnode: (oldnode, olddiff, olddrev}
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33977
diff changeset
1261 oldmap = getoldnodedrevmap(repo, [repo[r].node() for r in revs])
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33977
diff changeset
1262
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1263 confirm = ui.configbool(b'phabsend', b'confirm')
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1264 confirm |= bool(opts.get(b'confirm'))
33690
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1265 if confirm:
33978
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33977
diff changeset
1266 confirmed = _confirmbeforesend(repo, revs, oldmap)
33690
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1267 if not confirmed:
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1268 raise error.Abort(_(b'phabsend cancelled'))
33690
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1269
33498
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1270 actions = []
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1271 reviewers = opts.get(b'reviewer', [])
42444
f33d3ee110da phabricator: add --blocker argument to phabsend to specify blocking reviewers
Ian Moody <moz-ian@perix.co.uk>
parents: 42443
diff changeset
1272 blockers = opts.get(b'blocker', [])
f33d3ee110da phabricator: add --blocker argument to phabsend to specify blocking reviewers
Ian Moody <moz-ian@perix.co.uk>
parents: 42443
diff changeset
1273 phids = []
33498
b7a75b9a3386 phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents: 33443
diff changeset
1274 if reviewers:
44420
ddcb51390891 phabricator: pass ui instead of repo to `userphids()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44419
diff changeset
1275 phids.extend(userphids(repo.ui, reviewers))
42444
f33d3ee110da phabricator: add --blocker argument to phabsend to specify blocking reviewers
Ian Moody <moz-ian@perix.co.uk>
parents: 42443
diff changeset
1276 if blockers:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1277 phids.extend(
44420
ddcb51390891 phabricator: pass ui instead of repo to `userphids()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44419
diff changeset
1278 map(
ddcb51390891 phabricator: pass ui instead of repo to `userphids()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44419
diff changeset
1279 lambda phid: b'blocking(%s)' % phid,
ddcb51390891 phabricator: pass ui instead of repo to `userphids()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44419
diff changeset
1280 userphids(repo.ui, blockers),
ddcb51390891 phabricator: pass ui instead of repo to `userphids()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44419
diff changeset
1281 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1282 )
42444
f33d3ee110da phabricator: add --blocker argument to phabsend to specify blocking reviewers
Ian Moody <moz-ian@perix.co.uk>
parents: 42443
diff changeset
1283 if phids:
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1284 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
1285
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1286 drevids = [] # [int]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1287 diffmap = {} # {newnode: diff}
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1288
42449
c19d259fd6ad phabricator: use parents.set to always set dependencies
Ian Moody <moz-ian@perix.co.uk>
parents: 42444
diff changeset
1289 # Send patches one by one so we know their Differential Revision PHIDs and
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1290 # can provide dependency relationship
42449
c19d259fd6ad phabricator: use parents.set to always set dependencies
Ian Moody <moz-ian@perix.co.uk>
parents: 42444
diff changeset
1291 lastrevphid = None
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1292 for rev in revs:
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1293 ui.debug(b'sending rev %d\n' % rev)
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1294 ctx = repo[rev]
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1295
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1296 # Get Differential Revision ID
33691
1664406a44d9 phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents: 33690
diff changeset
1297 oldnode, olddiff, revid = oldmap.get(ctx.node(), (None, None, None))
44645
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1298 oldbasenode = oldnode
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1299 if oldnode != ctx.node() or opts.get(b'amend'):
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1300 # Create or update Differential Revision
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1301 revision, diff = createdifferentialrevision(
44645
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1302 [ctx],
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1303 revid,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1304 lastrevphid,
44645
419fec8237b7 phabricator: teach createdifferentialrevision() to allow a folded commit range
Matt Harbison <matt_harbison@yahoo.com>
parents: 44644
diff changeset
1305 oldbasenode,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1306 oldnode,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1307 olddiff,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1308 actions,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1309 opts.get(b'comment'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1310 )
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1311 diffmap[ctx.node()] = diff
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1312 newrevid = int(revision[b'object'][b'id'])
42449
c19d259fd6ad phabricator: use parents.set to always set dependencies
Ian Moody <moz-ian@perix.co.uk>
parents: 42444
diff changeset
1313 newrevphid = revision[b'object'][b'phid']
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1314 if revid:
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1315 action = b'updated'
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1316 else:
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1317 action = b'created'
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1318
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1319 # Create a local tag to note the association, if commit message
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1320 # does not have it already
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1321 m = _differentialrevisiondescre.search(ctx.description())
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43504
diff changeset
1322 if not m or int(m.group('id')) != newrevid:
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1323 tagname = b'D%d' % newrevid
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1324 tags.tag(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1325 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1326 tagname,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1327 ctx.node(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1328 message=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1329 user=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1330 date=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1331 local=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1332 )
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1333 else:
42449
c19d259fd6ad phabricator: use parents.set to always set dependencies
Ian Moody <moz-ian@perix.co.uk>
parents: 42444
diff changeset
1334 # 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: 42444
diff changeset
1335 # could depend on this one and "newrevid" for the summary line.
44419
df8053082364 phabricator: pass ui instead of repo to `querydrev()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44418
diff changeset
1336 newrevphid = querydrev(repo.ui, b'%d' % revid)[0][b'phid']
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1337 newrevid = revid
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1338 action = b'skipped'
33199
228ad1e58a85 phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents: 33198
diff changeset
1339
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1340 drevids.append(newrevid)
42449
c19d259fd6ad phabricator: use parents.set to always set dependencies
Ian Moody <moz-ian@perix.co.uk>
parents: 42444
diff changeset
1341 lastrevphid = newrevphid
33200
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33199
diff changeset
1342
44648
949a87145336 phabricator: extract logic to print the status when posting a commit
Matt Harbison <matt_harbison@yahoo.com>
parents: 44647
diff changeset
1343 _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: 44647
diff changeset
1344
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1345 # Update commit messages and remove tags
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1346 if opts.get(b'amend'):
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1347 unfi = repo.unfiltered()
42434
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42433
diff changeset
1348 drevs = callconduit(ui, b'differential.query', {b'ids': drevids})
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1349 with repo.wlock(), repo.lock(), repo.transaction(b'phabsend'):
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1350 wnode = unfi[b'.'].node()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1351 mapping = {} # {oldnode: [newnode]}
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1352 for i, rev in enumerate(revs):
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1353 old = unfi[rev]
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1354 drevid = drevids[i]
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1355 drev = [d for d in drevs if int(d[b'id']) == drevid][0]
44644
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1356 newdesc = get_amended_desc(drev, old, False)
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1357 # Make sure commit message contain "Differential Revision"
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1358 if old.description() != newdesc:
41163
0101a35deae2 phabricator: warn if unable to amend, instead of aborting after posting
Matt Harbison <matt_harbison@yahoo.com>
parents: 41080
diff changeset
1359 if old.phase() == phases.public:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1360 ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1361 _(b"warning: not updating public commit %s\n")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1362 % scmutil.formatchangeid(old)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1363 )
41163
0101a35deae2 phabricator: warn if unable to amend, instead of aborting after posting
Matt Harbison <matt_harbison@yahoo.com>
parents: 41080
diff changeset
1364 continue
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1365 parents = [
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1366 mapping.get(old.p1().node(), (old.p1(),))[0],
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1367 mapping.get(old.p2().node(), (old.p2(),))[0],
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1368 ]
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1369 new = context.metadataonlyctx(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1370 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1371 old,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1372 parents=parents,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1373 text=newdesc,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1374 user=old.user(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1375 date=old.date(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1376 extra=old.extra(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1377 )
38336
bb7e3c6ef592 phabricator: preserve the phase when amending in the Differential fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 38042
diff changeset
1378
38423
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 38392
diff changeset
1379 newnode = new.commit()
38336
bb7e3c6ef592 phabricator: preserve the phase when amending in the Differential fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 38042
diff changeset
1380
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1381 mapping[old.node()] = [newnode]
44647
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44646
diff changeset
1382
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44646
diff changeset
1383 _amend_diff_properties(
99fa161a883c phabricator: extract the logic to amend diff properties to a function
Matt Harbison <matt_harbison@yahoo.com>
parents: 44646
diff changeset
1384 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: 44646
diff changeset
1385 )
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1386 # Remove local tags since it's no longer necessary
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1387 tagname = b'D%d' % drevid
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1388 if tagname in repo.tags():
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1389 tags.tag(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1390 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1391 tagname,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1392 nullid,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1393 message=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1394 user=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1395 date=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1396 local=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1397 )
38423
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 38392
diff changeset
1398 scmutil.cleanupnodes(repo, mapping, b'phabsend', fixphase=True)
33787
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1399 if wnode in mapping:
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1400 unfi.setparents(mapping[wnode][0])
fa3aa6c98bb7 phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents: 33785
diff changeset
1401
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1402
33264
266321579c68 phabricator: add node and p1 to hg:meta property
Jun Wu <quark@fb.com>
parents: 33263
diff changeset
1403 # 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
1404 # consistent with "hg export" output.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1405 _metanamemap = util.sortdict(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1406 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1407 (b'user', b'User'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1408 (b'date', b'Date'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1409 (b'branch', b'Branch'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1410 (b'node', b'Node ID'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1411 (b'parent', b'Parent '),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1412 ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1413 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1414
33264
266321579c68 phabricator: add node and p1 to hg:meta property
Jun Wu <quark@fb.com>
parents: 33263
diff changeset
1415
33978
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33977
diff changeset
1416 def _confirmbeforesend(repo, revs, oldmap):
42433
500b64c5d991 phabricator: pass ui into readurltoken instead of passing repo
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42431
diff changeset
1417 url, token = readurltoken(repo.ui)
33690
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1418 ui = repo.ui
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1419 for rev in revs:
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1420 ctx = repo[rev]
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1421 desc = ctx.description().splitlines()[0]
33978
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33977
diff changeset
1422 oldnode, olddiff, drevid = oldmap.get(ctx.node(), (None, None, None))
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33977
diff changeset
1423 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
1424 drevdesc = ui.label(b'D%d' % drevid, b'phabricator.drev')
33978
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33977
diff changeset
1425 else:
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1426 drevdesc = ui.label(_(b'NEW'), b'phabricator.drev')
33978
088598153aa2 phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents: 33977
diff changeset
1427
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1428 ui.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1429 _(b'%s - %s: %s\n')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1430 % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1431 drevdesc,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1432 ui.label(bytes(ctx), b'phabricator.node'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1433 ui.label(desc, b'phabricator.desc'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1434 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1435 )
33690
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1436
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1437 if ui.promptchoice(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43094
diff changeset
1438 _(b'Send the above changes to %s (yn)?$$ &Yes $$ &No') % url
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1439 ):
33690
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1440 return False
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1441
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1442 return True
40cfe3197bc1 phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33601
diff changeset
1443
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1444
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1445 _knownstatusnames = {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1446 b'accepted',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1447 b'needsreview',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1448 b'needsrevision',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1449 b'closed',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1450 b'abandoned',
43857
74ec6ca0eb75 phabricator: add the "Changes Planned" status name
Matt Harbison <matt_harbison@yahoo.com>
parents: 43840
diff changeset
1451 b'changesplanned',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1452 }
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1453
33833
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33832
diff changeset
1454
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33832
diff changeset
1455 def _getstatusname(drev):
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33832
diff changeset
1456 """get normalized status name from a Differential Revision"""
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1457 return drev[b'statusName'].replace(b' ', b'').lower()
33833
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33832
diff changeset
1458
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1459
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1460 # 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: 33831
diff changeset
1461 # +, and -.
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1462
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1463 _elements = {
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1464 # token-type: binding-strength, primary, prefix, infix, suffix
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1465 b'(': (12, None, (b'group', 1, b')'), None, None),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1466 b':': (8, None, (b'ancestors', 8), None, None),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1467 b'&': (5, None, None, (b'and_', 5), None),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1468 b'+': (4, None, None, (b'add', 4), None),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1469 b'-': (4, None, None, (b'sub', 4), None),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1470 b')': (0, None, None, None, None),
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1471 b'symbol': (0, b'symbol', None, None, None),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1472 b'end': (0, None, None, None, None),
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1473 }
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1474
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1475
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1476 def _tokenize(text):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1477 view = memoryview(text) # zero-copy slice
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1478 special = b'():+-& '
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1479 pos = 0
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1480 length = len(text)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1481 while pos < length:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1482 symbol = b''.join(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1483 itertools.takewhile(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1484 lambda ch: ch not in special, pycompat.iterbytestr(view[pos:])
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1485 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1486 )
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1487 if symbol:
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1488 yield (b'symbol', symbol, pos)
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1489 pos += len(symbol)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1490 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
1491 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
1492 yield (text[pos : pos + 1], None, pos)
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1493 pos += 1
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1494 yield (b'end', None, pos)
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1495
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1496
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1497 def _parse(text):
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1498 tree, pos = parser.parser(_elements).parse(_tokenize(text))
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1499 if pos != len(text):
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1500 raise error.ParseError(b'invalid token', pos)
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1501 return tree
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1502
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1503
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1504 def _parsedrev(symbol):
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1505 """str -> int or None, ex. 'D45' -> 45; '12' -> 12; 'x' -> None"""
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1506 if symbol.startswith(b'D') and symbol[1:].isdigit():
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1507 return int(symbol[1:])
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1508 if symbol.isdigit():
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1509 return int(symbol)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1510
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1511
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1512 def _prefetchdrevs(tree):
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1513 """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: 33831
diff changeset
1514 drevs = set()
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1515 ancestordrevs = set()
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1516 op = tree[0]
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1517 if op == b'symbol':
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1518 r = _parsedrev(tree[1])
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1519 if r:
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1520 drevs.add(r)
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1521 elif op == b'ancestors':
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1522 r, a = _prefetchdrevs(tree[1])
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1523 drevs.update(r)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1524 ancestordrevs.update(r)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1525 ancestordrevs.update(a)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1526 else:
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1527 for t in tree[1:]:
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1528 r, a = _prefetchdrevs(t)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1529 drevs.update(r)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1530 ancestordrevs.update(a)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1531 return drevs, ancestordrevs
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1532
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1533
44419
df8053082364 phabricator: pass ui instead of repo to `querydrev()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44418
diff changeset
1534 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
1535 """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
1536
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1537 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: 33831
diff changeset
1538 for details.
33267
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1539
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1540 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
1541
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1542 {
44393
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1543 "activeDiffPHID": "PHID-DIFF-xoqnjkobbm6k4dk6hi72",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1544 "authorPHID": "PHID-USER-tv3ohwc4v4jeu34otlye",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1545 "auxiliary": {
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1546 "phabricator:depends-on": [
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1547 "PHID-DREV-gbapp366kutjebt7agcd"
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1548 ]
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1549 "phabricator:projects": [],
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1550 },
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1551 "branch": "default",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1552 "ccs": [],
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1553 "commits": [],
33267
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1554 "dateCreated": "1499181406",
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1555 "dateModified": "1499182103",
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1556 "diffs": [
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1557 "3",
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1558 "4",
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1559 ],
44393
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1560 "hashes": [],
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1561 "id": "2",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1562 "lineCount": "2",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1563 "phid": "PHID-DREV-672qvysjcczopag46qty",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1564 "properties": {},
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1565 "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
1566 "reviewers": [],
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1567 "sourcePath": null
44393
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1568 "status": "0",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1569 "statusName": "Needs Review",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1570 "summary": "",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1571 "testPlan": "",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1572 "title": "example",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1573 "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
1574 }
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1575 """
44393
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1576 # TODO: replace differential.query and differential.querydiffs with
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1577 # differential.diff.search because the former (and their output) are
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1578 # frozen, and planned to be deprecated and removed.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1579
33269
ead6749354e1 phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents: 33268
diff changeset
1580 def fetch(params):
ead6749354e1 phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents: 33268
diff changeset
1581 """params -> single drev or None"""
41902
59bae59b7498 py3: fix a few "dict keys as str instead of bytes" issues in phabricator.py
Ian Moody <moz-ian@perix.co.uk>
parents: 41901
diff changeset
1582 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
1583 if key in prefetched:
ead6749354e1 phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents: 33268
diff changeset
1584 return prefetched[key]
44419
df8053082364 phabricator: pass ui instead of repo to `querydrev()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44418
diff changeset
1585 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
1586 # Fill prefetched with the result
ead6749354e1 phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents: 33268
diff changeset
1587 for drev in drevs:
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1588 prefetched[drev[b'phid']] = drev
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1589 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
1590 if key not in prefetched:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1591 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1592 _(b'cannot get Differential Revision %r') % params
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1593 )
33269
ead6749354e1 phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents: 33268
diff changeset
1594 return prefetched[key]
ead6749354e1 phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents: 33268
diff changeset
1595
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1596 def getstack(topdrevids):
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1597 """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: 33831
diff changeset
1598 visited = set()
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1599 result = []
41902
59bae59b7498 py3: fix a few "dict keys as str instead of bytes" issues in phabricator.py
Ian Moody <moz-ian@perix.co.uk>
parents: 41901
diff changeset
1600 queue = [{b'ids': [i]} for i in topdrevids]
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1601 while queue:
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1602 params = queue.pop()
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1603 drev = fetch(params)
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1604 if drev[b'id'] in visited:
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1605 continue
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1606 visited.add(drev[b'id'])
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1607 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: 41705
diff changeset
1608 auxiliary = drev.get(b'auxiliary', {})
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1609 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
1610 for phid in depends:
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1611 queue.append({b'phids': [phid]})
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1612 result.reverse()
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1613 return smartset.baseset(result)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1614
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1615 # Initialize prefetch cache
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1616 prefetched = {} # {id or phid: drev}
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1617
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1618 tree = _parse(spec)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1619 drevs, ancestordrevs = _prefetchdrevs(tree)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1620
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1621 # developer config: phabricator.batchsize
44419
df8053082364 phabricator: pass ui instead of repo to `querydrev()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44418
diff changeset
1622 batchsize = ui.configint(b'phabricator', b'batchsize')
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1623
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1624 # Prefetch Differential Revisions in batch
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1625 tofetch = set(drevs)
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1626 for r in ancestordrevs:
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1627 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: 33831
diff changeset
1628 if drevs:
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1629 fetch({b'ids': list(tofetch)})
33833
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33832
diff changeset
1630 validids = sorted(set(getstack(list(ancestordrevs))) | set(drevs))
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1631
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1632 # Walk through the tree, return smartsets
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1633 def walk(tree):
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1634 op = tree[0]
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1635 if op == b'symbol':
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1636 drev = _parsedrev(tree[1])
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1637 if drev:
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1638 return smartset.baseset([drev])
33833
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33832
diff changeset
1639 elif tree[1] in _knownstatusnames:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1640 drevs = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1641 r
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1642 for r in validids
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1643 if _getstatusname(prefetched[r]) == tree[1]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1644 ]
33833
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33832
diff changeset
1645 return smartset.baseset(drevs)
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1646 else:
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1647 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: 38336
diff changeset
1648 elif op in {b'and_', b'add', b'sub'}:
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1649 assert len(tree) == 3
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1650 return getattr(operator, op)(walk(tree[1]), walk(tree[2]))
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1651 elif op == b'group':
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1652 return walk(tree[1])
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1653 elif op == b'ancestors':
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1654 return getstack(walk(tree[1]))
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1655 else:
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1656 raise error.ProgrammingError(b'illegal tree: %r' % tree)
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1657
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1658 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
1659
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1660
33268
85391b95961d phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents: 33267
diff changeset
1661 def getdescfromdrev(drev):
85391b95961d phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents: 33267
diff changeset
1662 """get description (commit message) from "Differential Revision"
85391b95961d phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents: 33267
diff changeset
1663
85391b95961d phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents: 33267
diff changeset
1664 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
1665 about limited fields: title, summary, test plan, and URL.
85391b95961d phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents: 33267
diff changeset
1666 """
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1667 title = drev[b'title']
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1668 summary = drev[b'summary'].rstrip()
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1669 testplan = drev[b'testPlan'].rstrip()
33268
85391b95961d phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents: 33267
diff changeset
1670 if testplan:
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1671 testplan = b'Test Plan:\n%s' % testplan
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1672 uri = b'Differential Revision: %s' % drev[b'uri']
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1673 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
1674
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1675
44644
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1676 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: 44643
diff changeset
1677 """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: 44643
diff changeset
1678
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1679 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: 44643
diff changeset
1680 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: 44643
diff changeset
1681 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: 44643
diff changeset
1682 """
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1683 if not folded:
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1684 return getdescfromdrev(drev)
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1685
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1686 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: 44643
diff changeset
1687
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1688 # 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: 44643
diff changeset
1689 # 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: 44643
diff changeset
1690 # 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: 44643
diff changeset
1691 # 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: 44643
diff changeset
1692 # 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: 44643
diff changeset
1693 # 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: 44643
diff changeset
1694 # 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: 44643
diff changeset
1695 # in Phabricator.
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1696 m = _differentialrevisiondescre.search(ctx.description())
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1697 if not m:
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1698 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: 44643
diff changeset
1699
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1700 return _differentialrevisiondescre.sub(uri, ctx.description())
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1701
dbe9182c90f5 phabricator: combine commit messages into the review when folding commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 44643
diff changeset
1702
44646
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
1703 def getlocalcommits(diff):
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
1704 """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: 44645
diff changeset
1705
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
1706 See ``getdiffmeta()`` for an example diff object.
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
1707 """
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
1708 props = diff.get(b'properties') or {}
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
1709 commits = props.get(b'local:commits') or {}
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
1710 if len(commits) > 1:
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
1711 return {bin(c) for c in commits.keys()}
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
1712
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
1713 # 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: 44645
diff changeset
1714 # to use that in the --no-fold case.
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
1715 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: 44645
diff changeset
1716
5f9c917e3b50 phabricator: teach `getoldnodedrevmap()` to handle folded reviews
Matt Harbison <matt_harbison@yahoo.com>
parents: 44645
diff changeset
1717
33441
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1718 def getdiffmeta(diff):
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1719 """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
1720
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1721 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
1722
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1723 "properties": {
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1724 "hg:meta": {
44393
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1725 "branch": "default",
33441
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1726 "date": "1499571514 25200",
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1727 "node": "98c08acae292b2faf60a279b4189beb6cff1414d",
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1728 "user": "Foo Bar <foo@example.com>",
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1729 "parent": "6d0abad76b30e4724a37ab8721d630394070fe16"
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1730 }
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1731 }
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1732
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1733 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
1734
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1735 "properties": {
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1736 "local:commits": {
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1737 "98c08acae292b2faf60a279b4189beb6cff1414d": {
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1738 "author": "Foo Bar",
44393
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1739 "authorEmail": "foo@example.com"
33441
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1740 "branch": "default",
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1741 "commit": "98c08acae292b2faf60a279b4189beb6cff1414d",
44393
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1742 "local": "1000",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1743 "message": "...",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1744 "parents": ["6d0abad76b30e4724a37ab8721d630394070fe16"],
33441
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1745 "rev": "98c08acae292b2faf60a279b4189beb6cff1414d",
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1746 "summary": "...",
44393
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1747 "tag": "",
adb93aa98c78 phabricator: update the protocol documentation
Matt Harbison <matt_harbison@yahoo.com>
parents: 44329
diff changeset
1748 "time": 1499546314,
33441
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1749 }
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1750 }
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1751 }
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1752
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1753 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
1754 information.
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1755 """
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1756 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: 41705
diff changeset
1757 meta = props.get(b'hg:meta')
42257
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42256
diff changeset
1758 if not meta:
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42256
diff changeset
1759 if props.get(b'local:commits'):
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42256
diff changeset
1760 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: 42256
diff changeset
1761 meta = {}
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42256
diff changeset
1762 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
1763 meta[b'user'] = b'%s <%s>' % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1764 commit[b'author'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1765 commit[b'authorEmail'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1766 )
42257
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42256
diff changeset
1767 if b'time' in commit:
42618
c17e6a3e7356 phabricator: handle local:commits time being string or int
Ian Moody <moz-ian@perix.co.uk>
parents: 42449
diff changeset
1768 meta[b'date'] = b'%d 0' % int(commit[b'time'])
42257
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42256
diff changeset
1769 if b'branch' in commit:
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42256
diff changeset
1770 meta[b'branch'] = commit[b'branch']
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42256
diff changeset
1771 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: 42256
diff changeset
1772 if node:
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42256
diff changeset
1773 meta[b'node'] = node
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42256
diff changeset
1774 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: 42256
diff changeset
1775 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: 42256
diff changeset
1776 else:
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42256
diff changeset
1777 meta = {}
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42256
diff changeset
1778 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: 42256
diff changeset
1779 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: 42256
diff changeset
1780 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: 42256
diff changeset
1781 meta[b'branch'] = diff[b'branch']
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42256
diff changeset
1782 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: 42256
diff changeset
1783 meta[b'parent'] = diff[b'sourceControlBaseRevision']
a4f7dceb07bf phabricator: fallback to reading metadata from diff for phabread
Ian Moody <moz-ian@perix.co.uk>
parents: 42256
diff changeset
1784 return meta
33441
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1785
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1786
44585
2d63a8910db6 phabricator: remove *-argument from _getdrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 44579
diff changeset
1787 def _getdrevs(ui, stack, specs):
44578
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44568
diff changeset
1788 """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: 44568
diff changeset
1789
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44568
diff changeset
1790 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: 44568
diff changeset
1791 """
44585
2d63a8910db6 phabricator: remove *-argument from _getdrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 44579
diff changeset
1792 if len(specs) > 0:
44578
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44568
diff changeset
1793
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44568
diff changeset
1794 def _formatspec(s):
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44568
diff changeset
1795 if stack:
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44568
diff changeset
1796 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: 44568
diff changeset
1797 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: 44568
diff changeset
1798
44585
2d63a8910db6 phabricator: remove *-argument from _getdrevs()
Yuya Nishihara <yuya@tcha.org>
parents: 44579
diff changeset
1799 spec = b'+'.join(pycompat.maplist(_formatspec, specs))
44578
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44568
diff changeset
1800
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44568
diff changeset
1801 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: 44568
diff changeset
1802 if drevs:
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44568
diff changeset
1803 return drevs
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44568
diff changeset
1804
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44568
diff changeset
1805 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: 44568
diff changeset
1806
90adda73676a phabricator: add a helper function to convert DREVSPECs to a DREV dict list
Matt Harbison <matt_harbison@yahoo.com>
parents: 44568
diff changeset
1807
44418
41217dfa7a6d phabricator: pass ui instead of repo to `readpatch()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44393
diff changeset
1808 def readpatch(ui, drevs, write):
33200
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33199
diff changeset
1809 """generate plain-text patch readable by 'hg import'
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33199
diff changeset
1810
44422
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44421
diff changeset
1811 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: 44421
diff changeset
1812 (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: 44421
diff changeset
1813 to be imported. drevs is what "querydrev" returns, results of
33831
75fdaf851e83 phabricator: change "readpatch" to be more flexible
Jun Wu <quark@fb.com>
parents: 33787
diff changeset
1814 "differential.query".
33200
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33199
diff changeset
1815 """
33267
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1816 # Prefetch hg:meta property for all diffs
44452
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 44436
diff changeset
1817 diffids = sorted({max(int(v) for v in drev[b'diffs']) for drev in drevs})
44418
41217dfa7a6d phabricator: pass ui instead of repo to `readpatch()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44393
diff changeset
1818 diffs = callconduit(ui, b'differential.querydiffs', {b'ids': diffids})
33200
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33199
diff changeset
1819
44422
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44421
diff changeset
1820 patches = []
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44421
diff changeset
1821
33267
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1822 # 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
1823 for drev in drevs:
44418
41217dfa7a6d phabricator: pass ui instead of repo to `readpatch()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44393
diff changeset
1824 ui.note(_(b'reading D%s\n') % drev[b'id'])
33200
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33199
diff changeset
1825
41897
c340a8ac7ef3 phabricator: convert conduit response JSON unicode to bytes inside callconduit
Ian Moody <moz-ian@perix.co.uk>
parents: 41705
diff changeset
1826 diffid = max(int(v) for v in drev[b'diffs'])
44418
41217dfa7a6d phabricator: pass ui instead of repo to `readpatch()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 44393
diff changeset
1827 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
1828 desc = getdescfromdrev(drev)
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1829 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
1830
dba9f88659a3 phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents: 33266
diff changeset
1831 # 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
1832 # 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
1833 # and extract in mercurial/patch.py for supported headers.
41902
59bae59b7498 py3: fix a few "dict keys as str instead of bytes" issues in phabricator.py
Ian Moody <moz-ian@perix.co.uk>
parents: 41901
diff changeset
1834 meta = getdiffmeta(diffs[b'%d' % diffid])
33441
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1835 for k in _metanamemap.keys():
de7c6ec27d99 phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents: 33271
diff changeset
1836 if k in meta:
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1837 header += b'# %s %s\n' % (_metanamemap[k], meta[k])
33200
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33199
diff changeset
1838
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1839 content = b'%s%s\n%s' % (header, desc, body)
44422
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44421
diff changeset
1840 patches.append((drev[b'id'], content))
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44421
diff changeset
1841
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44421
diff changeset
1842 # Write patches to the supplied callback
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44421
diff changeset
1843 write(patches)
33200
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33199
diff changeset
1844
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1845
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1846 @vcrcommand(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1847 b'phabread',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1848 [(b'', b'stack', False, _(b'read dependencies'))],
44579
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44578
diff changeset
1849 _(b'DREVSPEC... [OPTIONS]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1850 helpcategory=command.CATEGORY_IMPORT_EXPORT,
44423
5e2d74e5f450 phabricator: make `hg phabread` work outside of a repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 44422
diff changeset
1851 optionalrepo=True,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1852 )
44579
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44578
diff changeset
1853 def phabread(ui, repo, *specs, **opts):
33200
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33199
diff changeset
1854 """print patches from Phabricator suitable for importing
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33199
diff changeset
1855
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1856 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: 33831
diff changeset
1857 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: 33831
diff changeset
1858 ``&``, ``(``, ``)`` for complex queries. Prefix ``:`` could be used to
44579
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44578
diff changeset
1859 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: 44578
diff changeset
1860 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: 44578
diff changeset
1861 to reorder the values to run from parent to child.
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1862
33833
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33832
diff changeset
1863 ``abandoned``, ``accepted``, ``closed``, ``needsreview``, ``needsrevision``
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33832
diff changeset
1864 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: 33832
diff changeset
1865 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: 33832
diff changeset
1866
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1867 For example, ``:D6+8-(2+D4)`` selects a stack up to D6, plus D8 and exclude
33833
fb59192b4981 phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents: 33832
diff changeset
1868 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: 33832
diff changeset
1869 stack up to D9.
33200
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33199
diff changeset
1870
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33199
diff changeset
1871 If --stack is given, follow dependencies information and read all patches.
33832
539541779010 phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents: 33831
diff changeset
1872 It is equivalent to the ``:`` operator.
33200
04cf9927f350 phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents: 33199
diff changeset
1873 """
41970
51ba9fbcca52 py3: use pycompat.byteskwargs on opts in phabricator.py
Ian Moody <moz-ian@perix.co.uk>
parents: 41950
diff changeset
1874 opts = pycompat.byteskwargs(opts)
44579
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44578
diff changeset
1875 drevs = _getdrevs(ui, opts.get(b'stack'), specs)
44422
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44421
diff changeset
1876
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44421
diff changeset
1877 def _write(patches):
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44421
diff changeset
1878 for drev, content in patches:
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44421
diff changeset
1879 ui.write(content)
d5d262c7e7a2 phabricator: refactor `phabread` to write all patches at once
Matt Harbison <matt_harbison@yahoo.com>
parents: 44421
diff changeset
1880
44423
5e2d74e5f450 phabricator: make `hg phabread` work outside of a repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 44422
diff changeset
1881 readpatch(ui, drevs, _write)
33834
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33833
diff changeset
1882
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1883
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1884 @vcrcommand(
44550
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1885 b'phabimport',
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1886 [(b'', b'stack', False, _(b'import dependencies as well'))],
44579
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44578
diff changeset
1887 _(b'DREVSPEC... [OPTIONS]'),
44550
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1888 helpcategory=command.CATEGORY_IMPORT_EXPORT,
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1889 )
44579
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44578
diff changeset
1890 def phabimport(ui, repo, *specs, **opts):
44550
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1891 """import patches from Phabricator for the specified Differential Revisions
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1892
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1893 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: 44452
diff changeset
1894 directory.
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1895
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1896 See ``hg help phabread`` for how to specify DREVSPEC.
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1897 """
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1898 opts = pycompat.byteskwargs(opts)
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1899
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1900 # --bypass avoids losing exec and symlink bits when importing on Windows,
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1901 # 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: 44452
diff changeset
1902 # rejects.
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1903 opts[b'bypass'] = True
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1904
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1905 # Mandatory default values, synced with commands.import
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1906 opts[b'strip'] = 1
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1907 opts[b'prefix'] = b''
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1908 # 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: 44452
diff changeset
1909 opts[b'obsolete'] = False
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1910
44551
9bae1d1a0f4c phabricator: add a config knob to import in the secret phase
Matt Harbison <matt_harbison@yahoo.com>
parents: 44550
diff changeset
1911 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: 44550
diff changeset
1912 opts[b'secret'] = True
44552
f10055b099b3 phabricator: add a config knob to create obsolete markers when importing
Matt Harbison <matt_harbison@yahoo.com>
parents: 44551
diff changeset
1913 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: 44551
diff changeset
1914 opts[b'obsolete'] = True # Handled by evolve wrapping tryimportone()
44551
9bae1d1a0f4c phabricator: add a config knob to import in the secret phase
Matt Harbison <matt_harbison@yahoo.com>
parents: 44550
diff changeset
1915
44550
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1916 def _write(patches):
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1917 parents = repo[None].parents()
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1918
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1919 with repo.wlock(), repo.lock(), repo.transaction(b'phabimport'):
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1920 for drev, contents in patches:
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1921 ui.status(_(b'applying patch from D%s\n') % drev)
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1922
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1923 with patch.extract(ui, pycompat.bytesio(contents)) as patchdata:
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1924 msg, node, rej = cmdutil.tryimportone(
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1925 ui,
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1926 repo,
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1927 patchdata,
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1928 parents,
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1929 opts,
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1930 [],
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1931 None, # Never update wdir to another revision
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1932 )
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1933
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1934 if not node:
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1935 raise error.Abort(_(b'D%s: no diffs found') % drev)
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1936
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1937 ui.note(msg + b'\n')
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1938 parents = [repo[node]]
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1939
44579
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44578
diff changeset
1940 drevs = _getdrevs(ui, opts.get(b'stack'), specs)
44550
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1941
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1942 readpatch(repo.ui, drevs, _write)
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1943
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1944
bbb170f9396d phabricator: add a `phabimport` command
Matt Harbison <matt_harbison@yahoo.com>
parents: 44452
diff changeset
1945 @vcrcommand(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1946 b'phabupdate',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1947 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1948 (b'', b'accept', False, _(b'accept revisions')),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1949 (b'', b'reject', False, _(b'reject revisions')),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1950 (b'', b'abandon', False, _(b'abandon revisions')),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1951 (b'', b'reclaim', False, _(b'reclaim revisions')),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1952 (b'm', b'comment', b'', _(b'comment on the last revision')),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1953 ],
44579
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44578
diff changeset
1954 _(b'DREVSPEC... [OPTIONS]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1955 helpcategory=command.CATEGORY_IMPORT_EXPORT,
44421
b715432fabba phabricator: make `hg phabupdate` work outside of a repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 44420
diff changeset
1956 optionalrepo=True,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1957 )
44579
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44578
diff changeset
1958 def phabupdate(ui, repo, *specs, **opts):
33834
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33833
diff changeset
1959 """update Differential Revision in batch
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33833
diff changeset
1960
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33833
diff changeset
1961 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: 33833
diff changeset
1962 """
41970
51ba9fbcca52 py3: use pycompat.byteskwargs on opts in phabricator.py
Ian Moody <moz-ian@perix.co.uk>
parents: 41950
diff changeset
1963 opts = pycompat.byteskwargs(opts)
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1964 flags = [n for n in b'accept reject abandon reclaim'.split() if opts.get(n)]
33834
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33833
diff changeset
1965 if len(flags) > 1:
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1966 raise error.Abort(_(b'%s cannot be used together') % b', '.join(flags))
33834
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33833
diff changeset
1967
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33833
diff changeset
1968 actions = []
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33833
diff changeset
1969 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
1970 actions.append({b'type': f, b'value': True})
33834
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33833
diff changeset
1971
44579
a7f8c657a3f0 phabricator: allow multiple DREVSPEC args to phabread|phabimport|phabupdate
Matt Harbison <matt_harbison@yahoo.com>
parents: 44578
diff changeset
1972 drevs = _getdrevs(ui, opts.get(b'stack'), specs)
33834
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33833
diff changeset
1973 for i, drev in enumerate(drevs):
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1974 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: 38336
diff changeset
1975 actions.append({b'type': b'comment', b'value': opts[b'comment']})
33834
6e666cd59879 phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents: 33833
diff changeset
1976 if actions:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1977 params = {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1978 b'objectIdentifier': drev[b'phid'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1979 b'transactions': actions,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1980 }
42434
f163e2b2594c phabricator: pass ui instead of repo to callconduit
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42433
diff changeset
1981 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
1982
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1983
42973
24bf7a3d3c30 phabricator: use exthelper to register commands, config, and templates
Matt Harbison <matt_harbison@yahoo.com>
parents: 42951
diff changeset
1984 @eh.templatekeyword(b'phabreview', requires={b'ctx'})
36514
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 35722
diff changeset
1985 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
1986 """: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
1987 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
1988 """
38392
81a4be7099fa py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents: 38336
diff changeset
1989 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
1990 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
1991 if m:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1992 return templateutil.hybriddict(
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43504
diff changeset
1993 {b'url': m.group('url'), b'id': b"D%s" % m.group('id'),}
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
1994 )
41164
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
1995 else:
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
1996 tags = ctx.repo().nodetags(ctx.node())
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
1997 for t in tags:
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
1998 if _differentialrevisiontagre.match(t):
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
1999 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
2000 if not url.endswith(b'/'):
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
2001 url += b'/'
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
2002 url += t
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
2003
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43047
diff changeset
2004 return templateutil.hybriddict({b'url': url, b'id': t,})
41164
43fd1947301d phabricator: teach {phabreview} to work without --amend
Matt Harbison <matt_harbison@yahoo.com>
parents: 41163
diff changeset
2005 return None
43839
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2006
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2007
43840
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2008 @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: 43839
diff changeset
2009 def template_status(context, mapping):
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2010 """:phabstatus: String. Status of Phabricator differential.
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2011 """
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2012 ctx = context.resource(mapping, b'ctx')
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2013 repo = context.resource(mapping, b'repo')
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2014 ui = context.resource(mapping, b'ui')
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2015
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2016 rev = ctx.rev()
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2017 try:
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2018 drevid = getdrevmap(repo, [rev])[rev]
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2019 except KeyError:
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2020 return None
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2021 drevs = callconduit(ui, b'differential.query', {b'ids': [drevid]})
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2022 for drev in drevs:
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2023 if int(drev[b'id']) == drevid:
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2024 return templateutil.hybriddict(
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2025 {b'url': drev[b'uri'], b'status': drev[b'statusName'],}
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2026 )
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2027 return None
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2028
79c0121220e3 phabricator: add a "phabstatus" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43839
diff changeset
2029
43839
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2030 @show.showview(b'phabstatus', csettopic=b'work')
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2031 def phabstatusshowview(ui, repo, displayer):
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2032 """Phabricator differiential status"""
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2033 revs = repo.revs('sort(_underway(), topo)')
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2034 drevmap = getdrevmap(repo, revs)
44452
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 44436
diff changeset
2035 unknownrevs, drevids, revsbydrevid = [], set(), {}
43839
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2036 for rev, drevid in pycompat.iteritems(drevmap):
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2037 if drevid is not None:
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2038 drevids.add(drevid)
44452
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 44436
diff changeset
2039 revsbydrevid.setdefault(drevid, set()).add(rev)
43839
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2040 else:
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2041 unknownrevs.append(rev)
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2042
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2043 drevs = callconduit(ui, b'differential.query', {b'ids': list(drevids)})
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2044 drevsbyrev = {}
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2045 for drev in drevs:
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2046 for rev in revsbydrevid[int(drev[b'id'])]:
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2047 drevsbyrev[rev] = drev
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2048
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2049 def phabstatus(ctx):
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2050 drev = drevsbyrev[ctx.rev()]
43858
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43857
diff changeset
2051 status = ui.label(
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43857
diff changeset
2052 b'%(statusName)s' % drev,
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43857
diff changeset
2053 b'phabricator.status.%s' % _getstatusname(drev),
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43857
diff changeset
2054 )
b0867b7751ba phabricator: color the status in the "phabstatus" view
Matt Harbison <matt_harbison@yahoo.com>
parents: 43857
diff changeset
2055 ui.write(b"\n%s %s\n" % (drev[b'uri'], status))
43839
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2056
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2057 revs -= smartset.baseset(unknownrevs)
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2058 revdag = graphmod.dagwalker(repo, revs)
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2059
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2060 ui.setconfig(b'experimental', b'graphshorten', True)
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2061 displayer._exthook = phabstatus
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2062 nodelen = show.longestshortest(repo, revs)
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2063 logcmdutil.displaygraph(
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2064 ui,
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2065 repo,
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2066 revdag,
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2067 displayer,
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2068 graphmod.asciiedges,
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2069 props={b'nodelen': nodelen},
70060915c3f2 phabricator: add a "phabstatus" show view
Denis Laxalde <denis@laxalde.org>
parents: 43829
diff changeset
2070 )