Mercurial > public > mercurial-scm > hg-stable
annotate contrib/phabricator.py @ 39666:d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
I'll use this in an upcoming test. The decorator dancing in this is
more complicated than I'd like, but it beats repeating all this code
everywhere.
Differential Revision: https://phab.mercurial-scm.org/D4600
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Sat, 15 Sep 2018 00:20:03 -0400 |
parents | 0dce1297dd01 |
children |
rev | line source |
---|---|
33200 | 1 # phabricator.py - simple Phabricator integration |
2 # | |
3 # Copyright 2017 Facebook, Inc. | |
4 # | |
5 # This software may be used and distributed according to the terms of the | |
6 # GNU General Public License version 2 or any later version. | |
7 """simple Phabricator integration | |
8 | |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
9 This extension provides a ``phabsend`` command which sends a stack of |
33993 | 10 changesets to Phabricator, and a ``phabread`` command which prints a stack of |
11 revisions in a format suitable for :hg:`import`, and a ``phabupdate`` command | |
12 to update statuses in batch. | |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
13 |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
14 By default, Phabricator requires ``Test Plan`` which might prevent some |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
15 changeset from being sent. The requirement could be disabled by changing |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
16 ``differential.require-test-plan-field`` config server side. |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
17 |
33200 | 18 Config:: |
19 | |
20 [phabricator] | |
21 # Phabricator URL | |
22 url = https://phab.example.com/ | |
23 | |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
24 # Repo callsign. If a repo has a URL https://$HOST/diffusion/FOO, then its |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
25 # callsign is "FOO". |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
26 callsign = FOO |
33202
04cf9927f350
phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents:
33201
diff
changeset
|
27 |
34081
8b659b7388c0
phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents:
34080
diff
changeset
|
28 # curl command to use. If not set (default), use builtin HTTP library to |
8b659b7388c0
phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents:
34080
diff
changeset
|
29 # communicate. If set, use the specified curl command. This could be useful |
8b659b7388c0
phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents:
34080
diff
changeset
|
30 # if you need to specify advanced options that is not easily supported by |
8b659b7388c0
phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents:
34080
diff
changeset
|
31 # the internal library. |
8b659b7388c0
phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents:
34080
diff
changeset
|
32 curlcmd = curl --connect-timeout 2 --retry 3 --silent |
36795
4397909f82d3
phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents:
36543
diff
changeset
|
33 |
38039
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
34 [auth] |
38040
71cf20d47f25
phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents:
38039
diff
changeset
|
35 example.schemes = https |
71cf20d47f25
phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents:
38039
diff
changeset
|
36 example.prefix = phab.example.com |
71cf20d47f25
phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents:
38039
diff
changeset
|
37 |
36795
4397909f82d3
phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents:
36543
diff
changeset
|
38 # API token. Get it from https://$HOST/conduit/login/ |
38039
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
39 example.phabtoken = cli-xxxxxxxxxxxxxxxxxxxxxxxxxxxx |
33200 | 40 """ |
41 | |
42 from __future__ import absolute_import | |
43 | |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
44 import itertools |
33200 | 45 import json |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
46 import operator |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
47 import re |
33200 | 48 |
33443
e48082e0a8d5
phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents:
33442
diff
changeset
|
49 from mercurial.node import bin, nullid |
33200 | 50 from mercurial.i18n import _ |
51 from mercurial import ( | |
33808
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
52 cmdutil, |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
53 context, |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
54 encoding, |
33200 | 55 error, |
38040
71cf20d47f25
phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents:
38039
diff
changeset
|
56 httpconnection as httpconnectionmod, |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
57 mdiff, |
33761
e6d8ee3c9ec3
obsutil: rename allprecursors into allpredecessors
Boris Feld <boris.feld@octobus.net>
parents:
33718
diff
changeset
|
58 obsutil, |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
59 parser, |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
60 patch, |
33200 | 61 registrar, |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
62 scmutil, |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
63 smartset, |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
64 tags, |
33200 | 65 url as urlmod, |
66 util, | |
67 ) | |
37123
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36826
diff
changeset
|
68 from mercurial.utils import ( |
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36826
diff
changeset
|
69 procutil, |
37800
6cf5f5b4eb57
phabricator: specify some metadata compatibly with arc
Tom Prince <mozilla@hocat.ca>
parents:
37123
diff
changeset
|
70 stringutil, |
37123
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36826
diff
changeset
|
71 ) |
33200 | 72 |
73 cmdtable = {} | |
74 command = registrar.command(cmdtable) | |
75 | |
38075
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
76 configtable = {} |
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
77 configitem = registrar.configitem(configtable) |
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
78 |
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
79 # developer config: phabricator.batchsize |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
80 configitem(b'phabricator', b'batchsize', |
38075
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
81 default=12, |
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
82 ) |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
83 configitem(b'phabricator', b'callsign', |
38075
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
84 default=None, |
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
85 ) |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
86 configitem(b'phabricator', b'curlcmd', |
38075
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
87 default=None, |
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
88 ) |
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
89 # developer config: phabricator.repophid |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
90 configitem(b'phabricator', b'repophid', |
38075
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
91 default=None, |
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
92 ) |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
93 configitem(b'phabricator', b'url', |
38075
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
94 default=None, |
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
95 ) |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
96 configitem(b'phabsend', b'confirm', |
38075
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
97 default=False, |
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
98 ) |
5a7cf42ba6ef
phabricator: register config settings
Matt Harbison <matt_harbison@yahoo.com>
parents:
38040
diff
changeset
|
99 |
34080 | 100 colortable = { |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
101 b'phabricator.action.created': b'green', |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
102 b'phabricator.action.skipped': b'magenta', |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
103 b'phabricator.action.updated': b'magenta', |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
104 b'phabricator.desc': b'', |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
105 b'phabricator.drev': b'bold', |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
106 b'phabricator.node': b'', |
34080 | 107 } |
108 | |
39666
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
109 _VCR_FLAGS = [ |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
110 (b'', b'test-vcr', b'', |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
111 _(b'Path to a vcr file. If nonexistent, will record a new vcr transcript' |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
112 b', otherwise will mock all http requests using the specified vcr file.' |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
113 b' (ADVANCED)' |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
114 )), |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
115 ] |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
116 |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
117 def vcrcommand(name, flags, spec): |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
118 fullflags = flags + _VCR_FLAGS |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
119 def decorate(fn): |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
120 def inner(*args, **kwargs): |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
121 cassette = kwargs.pop(r'test_vcr', None) |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
122 if cassette: |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
123 import hgdemandimport |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
124 with hgdemandimport.deactivated(): |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
125 import vcr as vcrmod |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
126 import vcr.stubs as stubs |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
127 vcr = vcrmod.VCR( |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
128 serializer=r'json', |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
129 custom_patches=[ |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
130 (urlmod, 'httpconnection', stubs.VCRHTTPConnection), |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
131 (urlmod, 'httpsconnection', stubs.VCRHTTPSConnection), |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
132 ]) |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
133 with vcr.use_cassette(cassette): |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
134 return fn(*args, **kwargs) |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
135 return fn(*args, **kwargs) |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
136 inner.__name__ = fn.__name__ |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
137 return command(name, fullflags, spec)(inner) |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
138 return decorate |
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
139 |
33200 | 140 def urlencodenested(params): |
141 """like urlencode, but works with nested parameters. | |
142 | |
143 For example, if params is {'a': ['b', 'c'], 'd': {'e': 'f'}}, it will be | |
144 flattened to {'a[0]': 'b', 'a[1]': 'c', 'd[e]': 'f'} and then passed to | |
145 urlencode. Note: the encoding is consistent with PHP's http_build_query. | |
146 """ | |
147 flatparams = util.sortdict() | |
148 def process(prefix, obj): | |
149 items = {list: enumerate, dict: lambda x: x.items()}.get(type(obj)) | |
150 if items is None: | |
151 flatparams[prefix] = obj | |
152 else: | |
153 for k, v in items(obj): | |
154 if prefix: | |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
155 process(b'%s[%s]' % (prefix, k), v) |
33200 | 156 else: |
157 process(k, v) | |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
158 process(b'', params) |
33200 | 159 return util.urlreq.urlencode(flatparams) |
160 | |
38039
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
161 printed_token_warning = False |
33200 | 162 |
38039
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
163 def readlegacytoken(repo, url): |
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
164 """Transitional support for old phabricator tokens. |
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
165 |
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
166 Remove before the 4.7 release. |
33200 | 167 """ |
36795
4397909f82d3
phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents:
36543
diff
changeset
|
168 groups = {} |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
169 for key, val in repo.ui.configitems(b'phabricator.auth'): |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
170 if b'.' not in key: |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
171 repo.ui.warn(_(b"ignoring invalid [phabricator.auth] key '%s'\n") |
36795
4397909f82d3
phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents:
36543
diff
changeset
|
172 % key) |
4397909f82d3
phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents:
36543
diff
changeset
|
173 continue |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
174 group, setting = key.rsplit(b'.', 1) |
36795
4397909f82d3
phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents:
36543
diff
changeset
|
175 groups.setdefault(group, {})[setting] = val |
4397909f82d3
phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents:
36543
diff
changeset
|
176 |
4397909f82d3
phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents:
36543
diff
changeset
|
177 token = None |
4397909f82d3
phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents:
36543
diff
changeset
|
178 for group, auth in groups.iteritems(): |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
179 if url != auth.get(b'url'): |
36795
4397909f82d3
phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents:
36543
diff
changeset
|
180 continue |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
181 token = auth.get(b'token') |
36795
4397909f82d3
phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents:
36543
diff
changeset
|
182 if token: |
4397909f82d3
phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents:
36543
diff
changeset
|
183 break |
4397909f82d3
phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents:
36543
diff
changeset
|
184 |
38039
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
185 global printed_token_warning |
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
186 |
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
187 if token and not printed_token_warning: |
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
188 printed_token_warning = True |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
189 repo.ui.warn(_(b'phabricator.auth.token is deprecated - please ' |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
190 b'migrate to auth.phabtoken.\n')) |
38039
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
191 return token |
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
192 |
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
193 def readurltoken(repo): |
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
194 """return conduit url, token and make sure they exist |
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
195 |
38040
71cf20d47f25
phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents:
38039
diff
changeset
|
196 Currently read from [auth] config section. In the future, it might |
38039
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
197 make sense to read from .arcconfig and .arcrc as well. |
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
198 """ |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
199 url = repo.ui.config(b'phabricator', b'url') |
38039
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
200 if not url: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
201 raise error.Abort(_(b'config %s.%s is required') |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
202 % (b'phabricator', b'url')) |
38039
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
203 |
38040
71cf20d47f25
phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents:
38039
diff
changeset
|
204 res = httpconnectionmod.readauthforuri(repo.ui, url, util.url(url).user) |
71cf20d47f25
phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents:
38039
diff
changeset
|
205 token = None |
38039
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
206 |
38040
71cf20d47f25
phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents:
38039
diff
changeset
|
207 if res: |
71cf20d47f25
phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents:
38039
diff
changeset
|
208 group, auth = res |
71cf20d47f25
phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents:
38039
diff
changeset
|
209 |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
210 repo.ui.debug(b"using auth.%s.* for authentication\n" % group) |
38040
71cf20d47f25
phabricator: split auth.url into the standard auth.schemes and auth.prefix
Matt Harbison <matt_harbison@yahoo.com>
parents:
38039
diff
changeset
|
211 |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
212 token = auth.get(b'phabtoken') |
38039
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
213 |
36795
4397909f82d3
phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents:
36543
diff
changeset
|
214 if not token: |
38039
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
215 token = readlegacytoken(repo, url) |
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
216 if not token: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
217 raise error.Abort(_(b'Can\'t find conduit token associated to %s') |
38039
0fa050bc68cb
phabricator: migrate [phabricator.auth] to [auth]
Matt Harbison <matt_harbison@yahoo.com>
parents:
38020
diff
changeset
|
218 % (url,)) |
36795
4397909f82d3
phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents:
36543
diff
changeset
|
219 |
4397909f82d3
phabricator: specify API tokens per host, rather than per repo
Tom Prince <mozilla@hocat.ca>
parents:
36543
diff
changeset
|
220 return url, token |
33200 | 221 |
222 def callconduit(repo, name, params): | |
223 """call Conduit API, params is a dict. return json.loads result, or None""" | |
224 host, token = readurltoken(repo) | |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
225 url, authinfo = util.url(b'/'.join([host, b'api', name])).authinfo() |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
226 repo.ui.debug(b'Conduit Call: %s %s\n' % (url, params)) |
33200 | 227 params = params.copy() |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
228 params[b'api.token'] = token |
34081
8b659b7388c0
phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents:
34080
diff
changeset
|
229 data = urlencodenested(params) |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
230 curlcmd = repo.ui.config(b'phabricator', b'curlcmd') |
34081
8b659b7388c0
phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents:
34080
diff
changeset
|
231 if curlcmd: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
232 sin, sout = procutil.popen2(b'%s -d @- %s' |
37123
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36826
diff
changeset
|
233 % (curlcmd, procutil.shellquote(url))) |
34081
8b659b7388c0
phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents:
34080
diff
changeset
|
234 sin.write(data) |
8b659b7388c0
phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents:
34080
diff
changeset
|
235 sin.close() |
8b659b7388c0
phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents:
34080
diff
changeset
|
236 body = sout.read() |
8b659b7388c0
phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents:
34080
diff
changeset
|
237 else: |
8b659b7388c0
phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents:
34080
diff
changeset
|
238 urlopener = urlmod.opener(repo.ui, authinfo) |
8b659b7388c0
phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents:
34080
diff
changeset
|
239 request = util.urlreq.request(url, data=data) |
8b659b7388c0
phabricator: add a config to use curl for communication
Jun Wu <quark@fb.com>
parents:
34080
diff
changeset
|
240 body = urlopener.open(request).read() |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
241 repo.ui.debug(b'Conduit Response: %s\n' % body) |
33200 | 242 parsed = json.loads(body) |
243 if parsed.get(r'error_code'): | |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
244 msg = (_(b'Conduit Error (%s): %s') |
33200 | 245 % (parsed[r'error_code'], parsed[r'error_info'])) |
246 raise error.Abort(msg) | |
247 return parsed[r'result'] | |
248 | |
39666
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
249 @vcrcommand(b'debugcallconduit', [], _(b'METHOD')) |
33200 | 250 def debugcallconduit(ui, repo, name): |
251 """call Conduit API | |
252 | |
253 Call parameters are read from stdin as a JSON blob. Result will be written | |
254 to stdout as a JSON blob. | |
255 """ | |
256 params = json.loads(ui.fin.read()) | |
257 result = callconduit(repo, name, params) | |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
258 s = json.dumps(result, sort_keys=True, indent=2, separators=(b',', b': ')) |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
259 ui.write(b'%s\n' % s) |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
260 |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
261 def getrepophid(repo): |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
262 """given callsign, return repository PHID or None""" |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
263 # developer config: phabricator.repophid |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
264 repophid = repo.ui.config(b'phabricator', b'repophid') |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
265 if repophid: |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
266 return repophid |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
267 callsign = repo.ui.config(b'phabricator', b'callsign') |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
268 if not callsign: |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
269 return None |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
270 query = callconduit(repo, b'diffusion.repository.search', |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
271 {b'constraints': {b'callsigns': [callsign]}}) |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
272 if len(query[r'data']) == 0: |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
273 return None |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
274 repophid = encoding.strtolocal(query[r'data'][0][r'phid']) |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
275 repo.ui.setconfig(b'phabricator', b'repophid', repophid) |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
276 return repophid |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
277 |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
278 _differentialrevisiontagre = re.compile(b'\AD([1-9][0-9]*)\Z') |
33263
ed61189763ef
phabricator: check associated Differential Revision from commit message
Jun Wu <quark@fb.com>
parents:
33202
diff
changeset
|
279 _differentialrevisiondescre = re.compile( |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
280 b'^Differential Revision:\s*(?P<url>(?:.*)D(?P<id>[1-9][0-9]*))$', re.M) |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
281 |
33442
3ab0d5767b54
phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents:
33441
diff
changeset
|
282 def getoldnodedrevmap(repo, nodelist): |
3ab0d5767b54
phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents:
33441
diff
changeset
|
283 """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
|
284 |
33717
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
285 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
|
286 for node in nodelist with known previous sent versions, or associated |
33717
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
287 Differential Revision IDs. ``oldnode`` and ``Differential diff`` could |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
288 be ``None``. |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
289 |
33717
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
290 Examines commit messages like "Differential Revision:" to get the |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
291 association information. |
33263
ed61189763ef
phabricator: check associated Differential Revision from commit message
Jun Wu <quark@fb.com>
parents:
33202
diff
changeset
|
292 |
33717
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
293 If such commit message line is not found, examines all precursors and their |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
294 tags. Tags with format like "D1234" are considered a match and the node |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
295 with that tag, and the number after "D" (ex. 1234) will be returned. |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
296 |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
297 The ``old node``, if not None, is guaranteed to be the last diff of |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
298 corresponding Differential Revision, and exist in the repo. |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
299 """ |
33442
3ab0d5767b54
phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents:
33441
diff
changeset
|
300 url, token = readurltoken(repo) |
3ab0d5767b54
phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents:
33441
diff
changeset
|
301 unfi = repo.unfiltered() |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
302 nodemap = unfi.changelog.nodemap |
33263
ed61189763ef
phabricator: check associated Differential Revision from commit message
Jun Wu <quark@fb.com>
parents:
33202
diff
changeset
|
303 |
33717
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
304 result = {} # {node: (oldnode?, lastdiff?, drev)} |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
305 toconfirm = {} # {node: (force, {precnode}, drev)} |
33442
3ab0d5767b54
phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents:
33441
diff
changeset
|
306 for node in nodelist: |
3ab0d5767b54
phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents:
33441
diff
changeset
|
307 ctx = unfi[node] |
33443
e48082e0a8d5
phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents:
33442
diff
changeset
|
308 # For tags like "D123", put them into "toconfirm" to verify later |
33761
e6d8ee3c9ec3
obsutil: rename allprecursors into allpredecessors
Boris Feld <boris.feld@octobus.net>
parents:
33718
diff
changeset
|
309 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
|
310 for n in precnodes: |
33442
3ab0d5767b54
phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents:
33441
diff
changeset
|
311 if n in nodemap: |
3ab0d5767b54
phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents:
33441
diff
changeset
|
312 for tag in unfi.nodetags(n): |
3ab0d5767b54
phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents:
33441
diff
changeset
|
313 m = _differentialrevisiontagre.match(tag) |
3ab0d5767b54
phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents:
33441
diff
changeset
|
314 if m: |
33717
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
315 toconfirm[node] = (0, set(precnodes), int(m.group(1))) |
33442
3ab0d5767b54
phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents:
33441
diff
changeset
|
316 continue |
33263
ed61189763ef
phabricator: check associated Differential Revision from commit message
Jun Wu <quark@fb.com>
parents:
33202
diff
changeset
|
317 |
33717
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
318 # Check commit message |
33442
3ab0d5767b54
phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents:
33441
diff
changeset
|
319 m = _differentialrevisiondescre.search(ctx.description()) |
3ab0d5767b54
phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents:
33441
diff
changeset
|
320 if m: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
321 toconfirm[node] = (1, set(precnodes), int(m.group(b'id'))) |
33263
ed61189763ef
phabricator: check associated Differential Revision from commit message
Jun Wu <quark@fb.com>
parents:
33202
diff
changeset
|
322 |
33443
e48082e0a8d5
phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents:
33442
diff
changeset
|
323 # 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
|
324 # Phabricator, and expect precursors overlap with it. |
e48082e0a8d5
phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents:
33442
diff
changeset
|
325 if toconfirm: |
33717
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
326 drevs = [drev for force, precs, drev in toconfirm.values()] |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
327 alldiffs = callconduit(unfi, b'differential.querydiffs', |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
328 {b'revisionIDs': drevs}) |
33717
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
329 getnode = lambda d: bin(encoding.unitolocal( |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
330 getdiffmeta(d).get(r'node', b''))) or None |
33717
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
331 for newnode, (force, precset, drev) in toconfirm.items(): |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
332 diffs = [d for d in alldiffs.values() |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
333 if int(d[r'revisionID']) == drev] |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
334 |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
335 # "precursors" as known by Phabricator |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
336 phprecset = set(getnode(d) for d in diffs) |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
337 |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
338 # Ignore if precursors (Phabricator and local repo) do not overlap, |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
339 # and force is not set (when commit message says nothing) |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
340 if not force and not bool(phprecset & precset): |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
341 tagname = b'D%d' % drev |
33443
e48082e0a8d5
phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents:
33442
diff
changeset
|
342 tags.tag(repo, tagname, nullid, message=None, user=None, |
e48082e0a8d5
phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents:
33442
diff
changeset
|
343 date=None, local=True) |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
344 unfi.ui.warn(_(b'D%s: local tag removed - does not match ' |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
345 b'Differential history\n') % drev) |
33717
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
346 continue |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
347 |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
348 # Find the last node using Phabricator metadata, and make sure it |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
349 # exists in the repo |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
350 oldnode = lastdiff = None |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
351 if diffs: |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
352 lastdiff = max(diffs, key=lambda d: int(d[r'id'])) |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
353 oldnode = getnode(lastdiff) |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
354 if oldnode and oldnode not in nodemap: |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
355 oldnode = None |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
356 |
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
357 result[newnode] = (oldnode, lastdiff, drev) |
33443
e48082e0a8d5
phabricator: verify local tags before trusting them
Jun Wu <quark@fb.com>
parents:
33442
diff
changeset
|
358 |
33442
3ab0d5767b54
phabricator: finding old nodes in batch
Jun Wu <quark@fb.com>
parents:
33441
diff
changeset
|
359 return result |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
360 |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
361 def getdiff(ctx, diffopts): |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
362 """plain-text diff without header (user, commit message, etc)""" |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
363 output = util.stringio() |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
364 for chunk, _label in patch.diffui(ctx.repo(), ctx.p1().node(), ctx.node(), |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
365 None, opts=diffopts): |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
366 output.write(chunk) |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
367 return output.getvalue() |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
368 |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
369 def creatediff(ctx): |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
370 """create a Differential Diff""" |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
371 repo = ctx.repo() |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
372 repophid = getrepophid(repo) |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
373 # Create a "Differential Diff" via "differential.createrawdiff" API |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
374 params = {b'diff': getdiff(ctx, mdiff.diffopts(git=True, context=32767))} |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
375 if repophid: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
376 params[b'repositoryPHID'] = repophid |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
377 diff = callconduit(repo, b'differential.createrawdiff', params) |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
378 if not diff: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
379 raise error.Abort(_(b'cannot create diff for %s') % ctx) |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
380 return diff |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
381 |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
382 def writediffproperties(ctx, diff): |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
383 """write metadata to diff so patches could be applied losslessly""" |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
384 params = { |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
385 b'diff_id': diff[r'id'], |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
386 b'name': b'hg:meta', |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
387 b'data': json.dumps({ |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
388 b'user': ctx.user(), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
389 b'date': b'%d %d' % ctx.date(), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
390 b'node': ctx.hex(), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
391 b'parent': ctx.p1().hex(), |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
392 }), |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
393 } |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
394 callconduit(ctx.repo(), b'differential.setdiffproperty', params) |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
395 |
37800
6cf5f5b4eb57
phabricator: specify some metadata compatibly with arc
Tom Prince <mozilla@hocat.ca>
parents:
37123
diff
changeset
|
396 params = { |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
397 b'diff_id': diff[r'id'], |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
398 b'name': b'local:commits', |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
399 b'data': json.dumps({ |
37800
6cf5f5b4eb57
phabricator: specify some metadata compatibly with arc
Tom Prince <mozilla@hocat.ca>
parents:
37123
diff
changeset
|
400 ctx.hex(): { |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
401 b'author': stringutil.person(ctx.user()), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
402 b'authorEmail': stringutil.email(ctx.user()), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
403 b'time': ctx.date()[0], |
37800
6cf5f5b4eb57
phabricator: specify some metadata compatibly with arc
Tom Prince <mozilla@hocat.ca>
parents:
37123
diff
changeset
|
404 }, |
6cf5f5b4eb57
phabricator: specify some metadata compatibly with arc
Tom Prince <mozilla@hocat.ca>
parents:
37123
diff
changeset
|
405 }), |
6cf5f5b4eb57
phabricator: specify some metadata compatibly with arc
Tom Prince <mozilla@hocat.ca>
parents:
37123
diff
changeset
|
406 } |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
407 callconduit(ctx.repo(), b'differential.setdiffproperty', params) |
37800
6cf5f5b4eb57
phabricator: specify some metadata compatibly with arc
Tom Prince <mozilla@hocat.ca>
parents:
37123
diff
changeset
|
408 |
33498
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
409 def createdifferentialrevision(ctx, revid=None, parentrevid=None, oldnode=None, |
33718
f100354cce52
phabricator: update diff property even if we choose not to create a new diff
Jun Wu <quark@fb.com>
parents:
33717
diff
changeset
|
410 olddiff=None, actions=None): |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
411 """create or update a Differential Revision |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
412 |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
413 If revid is None, create a new Differential Revision, otherwise update |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
414 revid. If parentrevid 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
|
415 |
95f658b558a3
phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents:
33264
diff
changeset
|
416 If oldnode is not None, check if the patch content (without commit message |
95f658b558a3
phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents:
33264
diff
changeset
|
417 and metadata) has changed before creating another diff. |
33498
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
418 |
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
419 If actions is not None, they will be appended to the transaction. |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
420 """ |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
421 repo = ctx.repo() |
33265
95f658b558a3
phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents:
33264
diff
changeset
|
422 if oldnode: |
33994
27ff2a87d8c0
phabsend: detect patch change with larger context
Jun Wu <quark@fb.com>
parents:
33993
diff
changeset
|
423 diffopts = mdiff.diffopts(git=True, context=32767) |
33265
95f658b558a3
phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents:
33264
diff
changeset
|
424 oldctx = repo.unfiltered()[oldnode] |
95f658b558a3
phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents:
33264
diff
changeset
|
425 neednewdiff = (getdiff(ctx, diffopts) != getdiff(oldctx, diffopts)) |
95f658b558a3
phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents:
33264
diff
changeset
|
426 else: |
95f658b558a3
phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents:
33264
diff
changeset
|
427 neednewdiff = True |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
428 |
33265
95f658b558a3
phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents:
33264
diff
changeset
|
429 transactions = [] |
95f658b558a3
phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents:
33264
diff
changeset
|
430 if neednewdiff: |
95f658b558a3
phabricator: do not upload new diff if nothing changes
Jun Wu <quark@fb.com>
parents:
33264
diff
changeset
|
431 diff = creatediff(ctx) |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
432 transactions.append({b'type': b'update', b'value': diff[r'phid']}) |
33718
f100354cce52
phabricator: update diff property even if we choose not to create a new diff
Jun Wu <quark@fb.com>
parents:
33717
diff
changeset
|
433 else: |
f100354cce52
phabricator: update diff property even if we choose not to create a new diff
Jun Wu <quark@fb.com>
parents:
33717
diff
changeset
|
434 # Even if we don't need to upload a new diff because the patch content |
f100354cce52
phabricator: update diff property even if we choose not to create a new diff
Jun Wu <quark@fb.com>
parents:
33717
diff
changeset
|
435 # does not change. We might still need to update its metadata so |
f100354cce52
phabricator: update diff property even if we choose not to create a new diff
Jun Wu <quark@fb.com>
parents:
33717
diff
changeset
|
436 # pushers could know the correct node metadata. |
f100354cce52
phabricator: update diff property even if we choose not to create a new diff
Jun Wu <quark@fb.com>
parents:
33717
diff
changeset
|
437 assert olddiff |
f100354cce52
phabricator: update diff property even if we choose not to create a new diff
Jun Wu <quark@fb.com>
parents:
33717
diff
changeset
|
438 diff = olddiff |
f100354cce52
phabricator: update diff property even if we choose not to create a new diff
Jun Wu <quark@fb.com>
parents:
33717
diff
changeset
|
439 writediffproperties(ctx, diff) |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
440 |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
441 # Use a temporary summary to set dependency. There might be better ways but |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
442 # I cannot find them for now. But do not do that if we are updating an |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
443 # existing revision (revid is not None) since that introduces visible |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
444 # churns (someone edited "Summary" twice) on the web page. |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
445 if parentrevid and revid is None: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
446 summary = b'Depends on D%s' % parentrevid |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
447 transactions += [{b'type': b'summary', b'value': summary}, |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
448 {b'type': b'summary', b'value': b' '}] |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
449 |
33498
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
450 if actions: |
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
451 transactions += actions |
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
452 |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
453 # Parse commit message and update related fields. |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
454 desc = ctx.description() |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
455 info = callconduit(repo, b'differential.parsecommitmessage', |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
456 {b'corpus': desc}) |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
457 for k, v in info[r'fields'].items(): |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
458 if k in [b'title', b'summary', b'testPlan']: |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
459 transactions.append({b'type': k, b'value': v}) |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
460 |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
461 params = {b'transactions': transactions} |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
462 if revid is not None: |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
463 # Update an existing Differential Revision |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
464 params[b'objectIdentifier'] = revid |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
465 |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
466 revision = callconduit(repo, b'differential.revision.edit', params) |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
467 if not revision: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
468 raise error.Abort(_(b'cannot create revision for %s') % ctx) |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
469 |
33808
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
470 return revision, diff |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
471 |
33498
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
472 def userphids(repo, names): |
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
473 """convert user names to PHIDs""" |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
474 query = {b'constraints': {b'usernames': names}} |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
475 result = callconduit(repo, b'user.search', query) |
33498
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
476 # 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
|
477 # some names here. |
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
478 data = result[r'data'] |
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
479 resolved = set(entry[r'fields'][r'username'] for entry in data) |
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
480 unresolved = set(names) - resolved |
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
481 if unresolved: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
482 raise error.Abort(_(b'unknown username: %s') |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
483 % b' '.join(sorted(unresolved))) |
33498
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
484 return [entry[r'phid'] for entry in data] |
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
485 |
39666
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
486 @vcrcommand(b'phabsend', |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
487 [(b'r', b'rev', [], _(b'revisions to send'), _(b'REV')), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
488 (b'', b'amend', True, _(b'update commit messages')), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
489 (b'', b'reviewer', [], _(b'specify reviewers')), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
490 (b'', b'confirm', None, _(b'ask for confirmation before sending'))], |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
491 _(b'REV [OPTIONS]')) |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
492 def phabsend(ui, repo, *revs, **opts): |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
493 """upload changesets to Phabricator |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
494 |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
495 If there are multiple revisions specified, they will be send as a stack |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
496 with a linear dependencies relationship using the order specified by the |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
497 revset. |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
498 |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
499 For the first time uploading changesets, local tags will be created to |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
500 maintain the association. After the first time, phabsend will check |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
501 obsstore and tags information so it can figure out whether to update an |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
502 existing Differential Revision, or create a new one. |
33716
40cfe3197bc1
phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33601
diff
changeset
|
503 |
33808
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
504 If --amend is set, update commit messages so they have the |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
505 ``Differential Revision`` URL, remove related tags. This is similar to what |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
506 arcanist will do, and is more desired in author-push workflows. Otherwise, |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
507 use local tags to record the ``Differential Revision`` association. |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
508 |
33716
40cfe3197bc1
phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33601
diff
changeset
|
509 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
|
510 can also add following to your configuration file to make it default |
33992
45a8cd74de4e
phabsend: polish the docstring a bit
Jun Wu <quark@fb.com>
parents:
33855
diff
changeset
|
511 behaviour:: |
33716
40cfe3197bc1
phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33601
diff
changeset
|
512 |
33992
45a8cd74de4e
phabsend: polish the docstring a bit
Jun Wu <quark@fb.com>
parents:
33855
diff
changeset
|
513 [phabsend] |
45a8cd74de4e
phabsend: polish the docstring a bit
Jun Wu <quark@fb.com>
parents:
33855
diff
changeset
|
514 confirm = true |
33808
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
515 |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
516 phabsend will check obsstore and the above association to decide whether to |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
517 update an existing Differential Revision, or create a new one. |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
518 """ |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
519 revs = list(revs) + opts.get(b'rev', []) |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
520 revs = scmutil.revrange(repo, revs) |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
521 |
33266
5b2391b46906
phabricator: abort if phabsend gets empty revs
Jun Wu <quark@fb.com>
parents:
33265
diff
changeset
|
522 if not revs: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
523 raise error.Abort(_(b'phabsend requires at least one changeset')) |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
524 if opts.get(b'amend'): |
33808
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
525 cmdutil.checkunfinished(repo) |
33266
5b2391b46906
phabricator: abort if phabsend gets empty revs
Jun Wu <quark@fb.com>
parents:
33265
diff
changeset
|
526 |
33996
088598153aa2
phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents:
33995
diff
changeset
|
527 # {newnode: (oldnode, olddiff, olddrev} |
088598153aa2
phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents:
33995
diff
changeset
|
528 oldmap = getoldnodedrevmap(repo, [repo[r].node() for r in revs]) |
088598153aa2
phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents:
33995
diff
changeset
|
529 |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
530 confirm = ui.configbool(b'phabsend', b'confirm') |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
531 confirm |= bool(opts.get(b'confirm')) |
33716
40cfe3197bc1
phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33601
diff
changeset
|
532 if confirm: |
33996
088598153aa2
phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents:
33995
diff
changeset
|
533 confirmed = _confirmbeforesend(repo, revs, oldmap) |
33716
40cfe3197bc1
phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33601
diff
changeset
|
534 if not confirmed: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
535 raise error.Abort(_(b'phabsend cancelled')) |
33716
40cfe3197bc1
phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33601
diff
changeset
|
536 |
33498
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
537 actions = [] |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
538 reviewers = opts.get(b'reviewer', []) |
33498
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
539 if reviewers: |
b7a75b9a3386
phabricator: allow specifying reviewers on phabsend
Jun Wu <quark@fb.com>
parents:
33443
diff
changeset
|
540 phids = userphids(repo, reviewers) |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
541 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
|
542 |
33808
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
543 drevids = [] # [int] |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
544 diffmap = {} # {newnode: diff} |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
545 |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
546 # Send patches one by one so we know their Differential Revision IDs and |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
547 # can provide dependency relationship |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
548 lastrevid = None |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
549 for rev in revs: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
550 ui.debug(b'sending rev %d\n' % rev) |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
551 ctx = repo[rev] |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
552 |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
553 # Get Differential Revision ID |
33717
1664406a44d9
phabricator: use Phabricator's last node information
Jun Wu <quark@fb.com>
parents:
33716
diff
changeset
|
554 oldnode, olddiff, revid = oldmap.get(ctx.node(), (None, None, None)) |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
555 if oldnode != ctx.node() or opts.get(b'amend'): |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
556 # Create or update Differential Revision |
33808
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
557 revision, diff = createdifferentialrevision( |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
558 ctx, revid, lastrevid, oldnode, olddiff, actions) |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
559 diffmap[ctx.node()] = diff |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
560 newrevid = int(revision[r'object'][r'id']) |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
561 if revid: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
562 action = b'updated' |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
563 else: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
564 action = b'created' |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
565 |
33808
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
566 # Create a local tag to note the association, if commit message |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
567 # does not have it already |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
568 m = _differentialrevisiondescre.search(ctx.description()) |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
569 if not m or int(m.group(b'id')) != newrevid: |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
570 tagname = b'D%d' % newrevid |
33808
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
571 tags.tag(repo, tagname, ctx.node(), message=None, user=None, |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
572 date=None, local=True) |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
573 else: |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
574 # Nothing changed. But still set "newrevid" so the next revision |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
575 # could depend on this one. |
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
576 newrevid = revid |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
577 action = b'skipped' |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
578 |
34080 | 579 actiondesc = ui.label( |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
580 {b'created': _(b'created'), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
581 b'skipped': _(b'skipped'), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
582 b'updated': _(b'updated')}[action], |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
583 b'phabricator.action.%s' % action) |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
584 drevdesc = ui.label(b'D%s' % newrevid, b'phabricator.drev') |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
585 nodedesc = ui.label(bytes(ctx), b'phabricator.node') |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
586 desc = ui.label(ctx.description().split(b'\n')[0], b'phabricator.desc') |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
587 ui.write(_(b'%s - %s - %s: %s\n') % (drevdesc, actiondesc, nodedesc, |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
588 desc)) |
33808
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
589 drevids.append(newrevid) |
33201
228ad1e58a85
phabricator: add phabsend command to send a stack
Jun Wu <quark@fb.com>
parents:
33200
diff
changeset
|
590 lastrevid = newrevid |
33202
04cf9927f350
phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents:
33201
diff
changeset
|
591 |
33808
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
592 # Update commit messages and remove tags |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
593 if opts.get(b'amend'): |
33808
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
594 unfi = repo.unfiltered() |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
595 drevs = callconduit(repo, b'differential.query', {b'ids': drevids}) |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
596 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:
38342
diff
changeset
|
597 wnode = unfi[b'.'].node() |
33808
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
598 mapping = {} # {oldnode: [newnode]} |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
599 for i, rev in enumerate(revs): |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
600 old = unfi[rev] |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
601 drevid = drevids[i] |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
602 drev = [d for d in drevs if int(d[r'id']) == drevid][0] |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
603 newdesc = getdescfromdrev(drev) |
38983
0dce1297dd01
phabricator: convert description into local
C?dric Krier <ced@b2ck.com>
parents:
38429
diff
changeset
|
604 newdesc = encoding.unitolocal(newdesc) |
33808
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
605 # Make sure commit message contain "Differential Revision" |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
606 if old.description() != newdesc: |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
607 parents = [ |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
608 mapping.get(old.p1().node(), (old.p1(),))[0], |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
609 mapping.get(old.p2().node(), (old.p2(),))[0], |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
610 ] |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
611 new = context.metadataonlyctx( |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
612 repo, old, parents=parents, text=newdesc, |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
613 user=old.user(), date=old.date(), extra=old.extra()) |
38342
bb7e3c6ef592
phabricator: preserve the phase when amending in the Differential fields
Matt Harbison <matt_harbison@yahoo.com>
parents:
38075
diff
changeset
|
614 |
38429
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38398
diff
changeset
|
615 newnode = new.commit() |
38342
bb7e3c6ef592
phabricator: preserve the phase when amending in the Differential fields
Matt Harbison <matt_harbison@yahoo.com>
parents:
38075
diff
changeset
|
616 |
33808
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
617 mapping[old.node()] = [newnode] |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
618 # Update diff property |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
619 writediffproperties(unfi[newnode], diffmap[old.node()]) |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
620 # Remove local tags since it's no longer necessary |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
621 tagname = b'D%d' % drevid |
33808
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
622 if tagname in repo.tags(): |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
623 tags.tag(repo, tagname, nullid, message=None, user=None, |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
624 date=None, local=True) |
38429
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38398
diff
changeset
|
625 scmutil.cleanupnodes(repo, mapping, b'phabsend', fixphase=True) |
33808
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
626 if wnode in mapping: |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
627 unfi.setparents(mapping[wnode][0]) |
fa3aa6c98bb7
phabricator: add --amend option to phabsend
Jun Wu <quark@fb.com>
parents:
33806
diff
changeset
|
628 |
33264
266321579c68
phabricator: add node and p1 to hg:meta property
Jun Wu <quark@fb.com>
parents:
33263
diff
changeset
|
629 # 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
|
630 # consistent with "hg export" output. |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
631 _metanamemap = util.sortdict([(r'user', b'User'), (r'date', b'Date'), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
632 (r'node', b'Node ID'), (r'parent', b'Parent ')]) |
33264
266321579c68
phabricator: add node and p1 to hg:meta property
Jun Wu <quark@fb.com>
parents:
33263
diff
changeset
|
633 |
33996
088598153aa2
phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents:
33995
diff
changeset
|
634 def _confirmbeforesend(repo, revs, oldmap): |
33995
edeb8f28c031
phabsend: print the actual URL with --confirm
Jun Wu <quark@fb.com>
parents:
33994
diff
changeset
|
635 url, token = readurltoken(repo) |
33716
40cfe3197bc1
phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33601
diff
changeset
|
636 ui = repo.ui |
40cfe3197bc1
phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33601
diff
changeset
|
637 for rev in revs: |
40cfe3197bc1
phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33601
diff
changeset
|
638 ctx = repo[rev] |
40cfe3197bc1
phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33601
diff
changeset
|
639 desc = ctx.description().splitlines()[0] |
33996
088598153aa2
phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents:
33995
diff
changeset
|
640 oldnode, olddiff, drevid = oldmap.get(ctx.node(), (None, None, None)) |
088598153aa2
phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents:
33995
diff
changeset
|
641 if drevid: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
642 drevdesc = ui.label(b'D%s' % drevid, b'phabricator.drev') |
33996
088598153aa2
phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents:
33995
diff
changeset
|
643 else: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
644 drevdesc = ui.label(_(b'NEW'), b'phabricator.drev') |
33996
088598153aa2
phabsend: show associated Differential Revisions with --confirm
Jun Wu <quark@fb.com>
parents:
33995
diff
changeset
|
645 |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
646 ui.write(_(b'%s - %s: %s\n') |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
647 % (drevdesc, |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
648 ui.label(bytes(ctx), b'phabricator.node'), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
649 ui.label(desc, b'phabricator.desc'))) |
33716
40cfe3197bc1
phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33601
diff
changeset
|
650 |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
651 if ui.promptchoice(_(b'Send the above changes to %s (yn)?' |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
652 b'$$ &Yes $$ &No') % url): |
33716
40cfe3197bc1
phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33601
diff
changeset
|
653 return False |
40cfe3197bc1
phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33601
diff
changeset
|
654 |
40cfe3197bc1
phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33601
diff
changeset
|
655 return True |
40cfe3197bc1
phabricator: add --confirm option to phabsend command
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33601
diff
changeset
|
656 |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
657 _knownstatusnames = {b'accepted', b'needsreview', b'needsrevision', b'closed', |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
658 b'abandoned'} |
33854
fb59192b4981
phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents:
33853
diff
changeset
|
659 |
fb59192b4981
phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents:
33853
diff
changeset
|
660 def _getstatusname(drev): |
fb59192b4981
phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents:
33853
diff
changeset
|
661 """get normalized status name from a Differential Revision""" |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
662 return drev[r'statusName'].replace(b' ', b'').lower() |
33854
fb59192b4981
phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents:
33853
diff
changeset
|
663 |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
664 # Small language to specify differential revisions. Support symbols: (), :X, |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
665 # +, and -. |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
666 |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
667 _elements = { |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
668 # token-type: binding-strength, primary, prefix, infix, suffix |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
669 b'(': (12, None, (b'group', 1, b')'), None, None), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
670 b':': (8, None, (b'ancestors', 8), None, None), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
671 b'&': (5, None, None, (b'and_', 5), None), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
672 b'+': (4, None, None, (b'add', 4), None), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
673 b'-': (4, None, None, (b'sub', 4), None), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
674 b')': (0, None, None, None, None), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
675 b'symbol': (0, b'symbol', None, None, None), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
676 b'end': (0, None, None, None, None), |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
677 } |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
678 |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
679 def _tokenize(text): |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
680 view = memoryview(text) # zero-copy slice |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
681 special = b'():+-& ' |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
682 pos = 0 |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
683 length = len(text) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
684 while pos < length: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
685 symbol = b''.join(itertools.takewhile(lambda ch: ch not in special, |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
686 view[pos:])) |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
687 if symbol: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
688 yield (b'symbol', symbol, pos) |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
689 pos += len(symbol) |
33854
fb59192b4981
phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents:
33853
diff
changeset
|
690 else: # special char, ignore space |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
691 if text[pos] != b' ': |
33854
fb59192b4981
phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents:
33853
diff
changeset
|
692 yield (text[pos], None, pos) |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
693 pos += 1 |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
694 yield (b'end', None, pos) |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
695 |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
696 def _parse(text): |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
697 tree, pos = parser.parser(_elements).parse(_tokenize(text)) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
698 if pos != len(text): |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
699 raise error.ParseError(b'invalid token', pos) |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
700 return tree |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
701 |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
702 def _parsedrev(symbol): |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
703 """str -> int or None, ex. 'D45' -> 45; '12' -> 12; 'x' -> None""" |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
704 if symbol.startswith(b'D') and symbol[1:].isdigit(): |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
705 return int(symbol[1:]) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
706 if symbol.isdigit(): |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
707 return int(symbol) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
708 |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
709 def _prefetchdrevs(tree): |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
710 """return ({single-drev-id}, {ancestor-drev-id}) to prefetch""" |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
711 drevs = set() |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
712 ancestordrevs = set() |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
713 op = tree[0] |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
714 if op == b'symbol': |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
715 r = _parsedrev(tree[1]) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
716 if r: |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
717 drevs.add(r) |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
718 elif op == b'ancestors': |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
719 r, a = _prefetchdrevs(tree[1]) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
720 drevs.update(r) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
721 ancestordrevs.update(r) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
722 ancestordrevs.update(a) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
723 else: |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
724 for t in tree[1:]: |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
725 r, a = _prefetchdrevs(t) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
726 drevs.update(r) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
727 ancestordrevs.update(a) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
728 return drevs, ancestordrevs |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
729 |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
730 def querydrev(repo, spec): |
33267
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
731 """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
|
732 |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
733 spec is a string using a simple query language, see docstring in phabread |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
734 for details. |
33267
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
735 |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
736 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
|
737 |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
738 { |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
739 "id": "2", |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
740 "phid": "PHID-DREV-672qvysjcczopag46qty", |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
741 "title": "example", |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
742 "uri": "https://phab.example.com/D2", |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
743 "dateCreated": "1499181406", |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
744 "dateModified": "1499182103", |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
745 "authorPHID": "PHID-USER-tv3ohwc4v4jeu34otlye", |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
746 "status": "0", |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
747 "statusName": "Needs Review", |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
748 "properties": [], |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
749 "branch": null, |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
750 "summary": "", |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
751 "testPlan": "", |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
752 "lineCount": "2", |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
753 "activeDiffPHID": "PHID-DIFF-xoqnjkobbm6k4dk6hi72", |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
754 "diffs": [ |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
755 "3", |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
756 "4", |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
757 ], |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
758 "commits": [], |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
759 "reviewers": [], |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
760 "ccs": [], |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
761 "hashes": [], |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
762 "auxiliary": { |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
763 "phabricator:projects": [], |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
764 "phabricator:depends-on": [ |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
765 "PHID-DREV-gbapp366kutjebt7agcd" |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
766 ] |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
767 }, |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
768 "repositoryPHID": "PHID-REPO-hub2hx62ieuqeheznasv", |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
769 "sourcePath": null |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
770 } |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
771 """ |
33269
ead6749354e1
phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents:
33268
diff
changeset
|
772 def fetch(params): |
ead6749354e1
phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents:
33268
diff
changeset
|
773 """params -> single drev or None""" |
ead6749354e1
phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents:
33268
diff
changeset
|
774 key = (params.get(r'ids') or params.get(r'phids') or [None])[0] |
ead6749354e1
phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents:
33268
diff
changeset
|
775 if key in prefetched: |
ead6749354e1
phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents:
33268
diff
changeset
|
776 return prefetched[key] |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
777 drevs = callconduit(repo, b'differential.query', params) |
33269
ead6749354e1
phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents:
33268
diff
changeset
|
778 # Fill prefetched with the result |
ead6749354e1
phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents:
33268
diff
changeset
|
779 for drev in drevs: |
ead6749354e1
phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents:
33268
diff
changeset
|
780 prefetched[drev[r'phid']] = drev |
ead6749354e1
phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents:
33268
diff
changeset
|
781 prefetched[int(drev[r'id'])] = drev |
ead6749354e1
phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents:
33268
diff
changeset
|
782 if key not in prefetched: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
783 raise error.Abort(_(b'cannot get Differential Revision %r') |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
784 % params) |
33269
ead6749354e1
phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents:
33268
diff
changeset
|
785 return prefetched[key] |
ead6749354e1
phabricator: try to fetch differential revisions in batch
Jun Wu <quark@fb.com>
parents:
33268
diff
changeset
|
786 |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
787 def getstack(topdrevids): |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
788 """given a top, get a stack from the bottom, [id] -> [id]""" |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
789 visited = set() |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
790 result = [] |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
791 queue = [{r'ids': [i]} for i in topdrevids] |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
792 while queue: |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
793 params = queue.pop() |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
794 drev = fetch(params) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
795 if drev[r'id'] in visited: |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
796 continue |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
797 visited.add(drev[r'id']) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
798 result.append(int(drev[r'id'])) |
33267
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
799 auxiliary = drev.get(r'auxiliary', {}) |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
800 depends = auxiliary.get(r'phabricator:depends-on', []) |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
801 for phid in depends: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
802 queue.append({b'phids': [phid]}) |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
803 result.reverse() |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
804 return smartset.baseset(result) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
805 |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
806 # Initialize prefetch cache |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
807 prefetched = {} # {id or phid: drev} |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
808 |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
809 tree = _parse(spec) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
810 drevs, ancestordrevs = _prefetchdrevs(tree) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
811 |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
812 # developer config: phabricator.batchsize |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
813 batchsize = repo.ui.configint(b'phabricator', b'batchsize') |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
814 |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
815 # Prefetch Differential Revisions in batch |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
816 tofetch = set(drevs) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
817 for r in ancestordrevs: |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
818 tofetch.update(range(max(1, r - batchsize), r + 1)) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
819 if drevs: |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
820 fetch({r'ids': list(tofetch)}) |
33854
fb59192b4981
phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents:
33853
diff
changeset
|
821 validids = sorted(set(getstack(list(ancestordrevs))) | set(drevs)) |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
822 |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
823 # Walk through the tree, return smartsets |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
824 def walk(tree): |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
825 op = tree[0] |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
826 if op == b'symbol': |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
827 drev = _parsedrev(tree[1]) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
828 if drev: |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
829 return smartset.baseset([drev]) |
33854
fb59192b4981
phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents:
33853
diff
changeset
|
830 elif tree[1] in _knownstatusnames: |
fb59192b4981
phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents:
33853
diff
changeset
|
831 drevs = [r for r in validids |
fb59192b4981
phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents:
33853
diff
changeset
|
832 if _getstatusname(prefetched[r]) == tree[1]] |
fb59192b4981
phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents:
33853
diff
changeset
|
833 return smartset.baseset(drevs) |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
834 else: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
835 raise error.Abort(_(b'unknown symbol: %s') % tree[1]) |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
836 elif op in {b'and_', b'add', b'sub'}: |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
837 assert len(tree) == 3 |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
838 return getattr(operator, op)(walk(tree[1]), walk(tree[2])) |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
839 elif op == b'group': |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
840 return walk(tree[1]) |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
841 elif op == b'ancestors': |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
842 return getstack(walk(tree[1])) |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
843 else: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
844 raise error.ProgrammingError(b'illegal tree: %r' % tree) |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
845 |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
846 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
|
847 |
33268
85391b95961d
phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents:
33267
diff
changeset
|
848 def getdescfromdrev(drev): |
85391b95961d
phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents:
33267
diff
changeset
|
849 """get description (commit message) from "Differential Revision" |
85391b95961d
phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents:
33267
diff
changeset
|
850 |
85391b95961d
phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents:
33267
diff
changeset
|
851 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
|
852 about limited fields: title, summary, test plan, and URL. |
85391b95961d
phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents:
33267
diff
changeset
|
853 """ |
85391b95961d
phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents:
33267
diff
changeset
|
854 title = drev[r'title'] |
85391b95961d
phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents:
33267
diff
changeset
|
855 summary = drev[r'summary'].rstrip() |
85391b95961d
phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents:
33267
diff
changeset
|
856 testplan = drev[r'testPlan'].rstrip() |
85391b95961d
phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents:
33267
diff
changeset
|
857 if testplan: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
858 testplan = b'Test Plan:\n%s' % testplan |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
859 uri = b'Differential Revision: %s' % drev[r'uri'] |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
860 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
|
861 |
33441
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
862 def getdiffmeta(diff): |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
863 """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
|
864 |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
865 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
|
866 |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
867 "properties": { |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
868 "hg:meta": { |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
869 "date": "1499571514 25200", |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
870 "node": "98c08acae292b2faf60a279b4189beb6cff1414d", |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
871 "user": "Foo Bar <foo@example.com>", |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
872 "parent": "6d0abad76b30e4724a37ab8721d630394070fe16" |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
873 } |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
874 } |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
875 |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
876 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
|
877 |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
878 "properties": { |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
879 "local:commits": { |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
880 "98c08acae292b2faf60a279b4189beb6cff1414d": { |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
881 "author": "Foo Bar", |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
882 "time": 1499546314, |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
883 "branch": "default", |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
884 "tag": "", |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
885 "commit": "98c08acae292b2faf60a279b4189beb6cff1414d", |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
886 "rev": "98c08acae292b2faf60a279b4189beb6cff1414d", |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
887 "local": "1000", |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
888 "parents": ["6d0abad76b30e4724a37ab8721d630394070fe16"], |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
889 "summary": "...", |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
890 "message": "...", |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
891 "authorEmail": "foo@example.com" |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
892 } |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
893 } |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
894 } |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
895 |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
896 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
|
897 information. |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
898 """ |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
899 props = diff.get(r'properties') or {} |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
900 meta = props.get(r'hg:meta') |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
901 if not meta and props.get(r'local:commits'): |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
902 commit = sorted(props[r'local:commits'].values())[0] |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
903 meta = { |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
904 r'date': r'%d 0' % commit[r'time'], |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
905 r'node': commit[r'rev'], |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
906 r'user': r'%s <%s>' % (commit[r'author'], commit[r'authorEmail']), |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
907 } |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
908 if len(commit.get(r'parents', ())) >= 1: |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
909 meta[r'parent'] = commit[r'parents'][0] |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
910 return meta or {} |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
911 |
33852
75fdaf851e83
phabricator: change "readpatch" to be more flexible
Jun Wu <quark@fb.com>
parents:
33808
diff
changeset
|
912 def readpatch(repo, drevs, write): |
33202
04cf9927f350
phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents:
33201
diff
changeset
|
913 """generate plain-text patch readable by 'hg import' |
04cf9927f350
phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents:
33201
diff
changeset
|
914 |
33852
75fdaf851e83
phabricator: change "readpatch" to be more flexible
Jun Wu <quark@fb.com>
parents:
33808
diff
changeset
|
915 write is usually ui.write. drevs is what "querydrev" returns, results of |
75fdaf851e83
phabricator: change "readpatch" to be more flexible
Jun Wu <quark@fb.com>
parents:
33808
diff
changeset
|
916 "differential.query". |
33202
04cf9927f350
phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents:
33201
diff
changeset
|
917 """ |
33267
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
918 # Prefetch hg:meta property for all diffs |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
919 diffids = sorted(set(max(int(v) for v in drev[r'diffs']) for drev in drevs)) |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
920 diffs = callconduit(repo, b'differential.querydiffs', {b'ids': diffids}) |
33202
04cf9927f350
phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents:
33201
diff
changeset
|
921 |
33267
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
922 # 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
|
923 for drev in drevs: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
924 repo.ui.note(_(b'reading D%s\n') % drev[r'id']) |
33202
04cf9927f350
phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents:
33201
diff
changeset
|
925 |
33267
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
926 diffid = max(int(v) for v in drev[r'diffs']) |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
927 body = callconduit(repo, b'differential.getrawdiff', |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
928 {b'diffID': diffid}) |
33268
85391b95961d
phabricator: avoid calling differential.getcommitmessage
Jun Wu <quark@fb.com>
parents:
33267
diff
changeset
|
929 desc = getdescfromdrev(drev) |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
930 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
|
931 |
dba9f88659a3
phabricator: rework phabread to reduce memory usage and round-trips
Jun Wu <quark@fb.com>
parents:
33266
diff
changeset
|
932 # 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
|
933 # 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
|
934 # and extract in mercurial/patch.py for supported headers. |
33441
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
935 meta = getdiffmeta(diffs[str(diffid)]) |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
936 for k in _metanamemap.keys(): |
de7c6ec27d99
phabricator: respect metadata sent by arc
Jun Wu <quark@fb.com>
parents:
33271
diff
changeset
|
937 if k in meta: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
938 header += b'# %s %s\n' % (_metanamemap[k], meta[k]) |
33202
04cf9927f350
phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents:
33201
diff
changeset
|
939 |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
940 content = b'%s%s\n%s' % (header, desc, body) |
33601
850d2ec2cf6a
phabricator: convert unicode to binary when writing patches
Jun Wu <quark@fb.com>
parents:
33564
diff
changeset
|
941 write(encoding.unitolocal(content)) |
33202
04cf9927f350
phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents:
33201
diff
changeset
|
942 |
39666
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
943 @vcrcommand(b'phabread', |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
944 [(b'', b'stack', False, _(b'read dependencies'))], |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
945 _(b'DREVSPEC [OPTIONS]')) |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
946 def phabread(ui, repo, spec, **opts): |
33202
04cf9927f350
phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents:
33201
diff
changeset
|
947 """print patches from Phabricator suitable for importing |
04cf9927f350
phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents:
33201
diff
changeset
|
948 |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
949 DREVSPEC could be a Differential Revision identity, like ``D123``, or just |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
950 the number ``123``. It could also have common operators like ``+``, ``-``, |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
951 ``&``, ``(``, ``)`` for complex queries. Prefix ``:`` could be used to |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
952 select a stack. |
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
953 |
33854
fb59192b4981
phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents:
33853
diff
changeset
|
954 ``abandoned``, ``accepted``, ``closed``, ``needsreview``, ``needsrevision`` |
fb59192b4981
phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents:
33853
diff
changeset
|
955 could be used to filter patches by status. For performance reason, they |
fb59192b4981
phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents:
33853
diff
changeset
|
956 only represent a subset of non-status selections and cannot be used alone. |
fb59192b4981
phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents:
33853
diff
changeset
|
957 |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
958 For example, ``:D6+8-(2+D4)`` selects a stack up to D6, plus D8 and exclude |
33854
fb59192b4981
phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents:
33853
diff
changeset
|
959 D2 and D4. ``:D9 & needsreview`` selects "Needs Review" revisions in a |
fb59192b4981
phabricator: add status to revision query language
Jun Wu <quark@fb.com>
parents:
33853
diff
changeset
|
960 stack up to D9. |
33202
04cf9927f350
phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents:
33201
diff
changeset
|
961 |
04cf9927f350
phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents:
33201
diff
changeset
|
962 If --stack is given, follow dependencies information and read all patches. |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
963 It is equivalent to the ``:`` operator. |
33202
04cf9927f350
phabricator: add phabread command to read patches
Jun Wu <quark@fb.com>
parents:
33201
diff
changeset
|
964 """ |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
965 if opts.get(b'stack'): |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
966 spec = b':(%s)' % spec |
33853
539541779010
phabricator: add a small language to query Differential Revisions
Jun Wu <quark@fb.com>
parents:
33852
diff
changeset
|
967 drevs = querydrev(repo, spec) |
33852
75fdaf851e83
phabricator: change "readpatch" to be more flexible
Jun Wu <quark@fb.com>
parents:
33808
diff
changeset
|
968 readpatch(repo, drevs, ui.write) |
33855
6e666cd59879
phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents:
33854
diff
changeset
|
969 |
39666
d8f07b16abfc
phabricator: add support for using the vcr library to mock interactions
Augie Fackler <raf@durin42.com>
parents:
38983
diff
changeset
|
970 @vcrcommand(b'phabupdate', |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
971 [(b'', b'accept', False, _(b'accept revisions')), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
972 (b'', b'reject', False, _(b'reject revisions')), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
973 (b'', b'abandon', False, _(b'abandon revisions')), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
974 (b'', b'reclaim', False, _(b'reclaim revisions')), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
975 (b'm', b'comment', b'', _(b'comment on the last revision')), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
976 ], _(b'DREVSPEC [OPTIONS]')) |
33855
6e666cd59879
phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents:
33854
diff
changeset
|
977 def phabupdate(ui, repo, spec, **opts): |
6e666cd59879
phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents:
33854
diff
changeset
|
978 """update Differential Revision in batch |
6e666cd59879
phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents:
33854
diff
changeset
|
979 |
6e666cd59879
phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents:
33854
diff
changeset
|
980 DREVSPEC selects revisions. See :hg:`help phabread` for its usage. |
6e666cd59879
phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents:
33854
diff
changeset
|
981 """ |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
982 flags = [n for n in b'accept reject abandon reclaim'.split() if opts.get(n)] |
33855
6e666cd59879
phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents:
33854
diff
changeset
|
983 if len(flags) > 1: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
984 raise error.Abort(_(b'%s cannot be used together') % b', '.join(flags)) |
33855
6e666cd59879
phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents:
33854
diff
changeset
|
985 |
6e666cd59879
phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents:
33854
diff
changeset
|
986 actions = [] |
6e666cd59879
phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents:
33854
diff
changeset
|
987 for f in flags: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
988 actions.append({b'type': f, b'value': b'true'}) |
33855
6e666cd59879
phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents:
33854
diff
changeset
|
989 |
6e666cd59879
phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents:
33854
diff
changeset
|
990 drevs = querydrev(repo, spec) |
6e666cd59879
phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents:
33854
diff
changeset
|
991 for i, drev in enumerate(drevs): |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
992 if i + 1 == len(drevs) and opts.get(b'comment'): |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
993 actions.append({b'type': b'comment', b'value': opts[b'comment']}) |
33855
6e666cd59879
phabricator: add phabupdate command to update status in batch
Jun Wu <quark@fb.com>
parents:
33854
diff
changeset
|
994 if actions: |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
995 params = {b'objectIdentifier': drev[r'phid'], |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
996 b'transactions': actions} |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
997 callconduit(repo, 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
|
998 |
f18ba40d792f
phabricator: add a template item for linking to a differential review
Tom Prince <mozilla@hocat.ca>
parents:
35626
diff
changeset
|
999 templatekeyword = registrar.templatekeyword() |
f18ba40d792f
phabricator: add a template item for linking to a differential review
Tom Prince <mozilla@hocat.ca>
parents:
35626
diff
changeset
|
1000 |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
1001 @templatekeyword(b'phabreview', requires={b'ctx'}) |
36543
7b74afec6772
templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents:
35722
diff
changeset
|
1002 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
|
1003 """: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
|
1004 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
|
1005 """ |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
1006 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
|
1007 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
|
1008 if m: |
f18ba40d792f
phabricator: add a template item for linking to a differential review
Tom Prince <mozilla@hocat.ca>
parents:
35626
diff
changeset
|
1009 return { |
38398
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
1010 b'url': m.group(b'url'), |
81a4be7099fa
py3: byte-stringify literals in contrib/phabricator.py as example
Yuya Nishihara <yuya@tcha.org>
parents:
38342
diff
changeset
|
1011 b'id': b"D{}".format(m.group(b'id')), |
35722
f18ba40d792f
phabricator: add a template item for linking to a differential review
Tom Prince <mozilla@hocat.ca>
parents:
35626
diff
changeset
|
1012 } |