Show More
@@ -210,15 +210,15 b' def readurltoken(ui):' | |||||
210 |
|
210 | |||
211 | return url, token |
|
211 | return url, token | |
212 |
|
212 | |||
213 |
def callconduit( |
|
213 | def callconduit(ui, name, params): | |
214 | """call Conduit API, params is a dict. return json.loads result, or None""" |
|
214 | """call Conduit API, params is a dict. return json.loads result, or None""" | |
215 |
host, token = readurltoken( |
|
215 | host, token = readurltoken(ui) | |
216 | url, authinfo = util.url(b'/'.join([host, b'api', name])).authinfo() |
|
216 | url, authinfo = util.url(b'/'.join([host, b'api', name])).authinfo() | |
217 |
|
|
217 | ui.debug(b'Conduit Call: %s %s\n' % (url, pycompat.byterepr(params))) | |
218 | params = params.copy() |
|
218 | params = params.copy() | |
219 | params[b'api.token'] = token |
|
219 | params[b'api.token'] = token | |
220 | data = urlencodenested(params) |
|
220 | data = urlencodenested(params) | |
221 |
curlcmd = |
|
221 | curlcmd = ui.config(b'phabricator', b'curlcmd') | |
222 | if curlcmd: |
|
222 | if curlcmd: | |
223 | sin, sout = procutil.popen2(b'%s -d @- %s' |
|
223 | sin, sout = procutil.popen2(b'%s -d @- %s' | |
224 | % (curlcmd, procutil.shellquote(url))) |
|
224 | % (curlcmd, procutil.shellquote(url))) | |
@@ -226,11 +226,11 b' def callconduit(repo, name, params):' | |||||
226 | sin.close() |
|
226 | sin.close() | |
227 | body = sout.read() |
|
227 | body = sout.read() | |
228 | else: |
|
228 | else: | |
229 |
urlopener = urlmod.opener( |
|
229 | urlopener = urlmod.opener(ui, authinfo) | |
230 | request = util.urlreq.request(pycompat.strurl(url), data=data) |
|
230 | request = util.urlreq.request(pycompat.strurl(url), data=data) | |
231 | with contextlib.closing(urlopener.open(request)) as rsp: |
|
231 | with contextlib.closing(urlopener.open(request)) as rsp: | |
232 | body = rsp.read() |
|
232 | body = rsp.read() | |
233 |
|
|
233 | ui.debug(b'Conduit Response: %s\n' % body) | |
234 | parsed = pycompat.rapply( |
|
234 | parsed = pycompat.rapply( | |
235 | lambda x: encoding.unitolocal(x) if isinstance(x, pycompat.unicode) |
|
235 | lambda x: encoding.unitolocal(x) if isinstance(x, pycompat.unicode) | |
236 | else x, |
|
236 | else x, | |
@@ -259,7 +259,7 b' def debugcallconduit(ui, repo, name):' | |||||
259 | # json.dumps only accepts unicode strings |
|
259 | # json.dumps only accepts unicode strings | |
260 | result = pycompat.rapply(lambda x: |
|
260 | result = pycompat.rapply(lambda x: | |
261 | encoding.unifromlocal(x) if isinstance(x, bytes) else x, |
|
261 | encoding.unifromlocal(x) if isinstance(x, bytes) else x, | |
262 |
callconduit( |
|
262 | callconduit(ui, name, params) | |
263 | ) |
|
263 | ) | |
264 | s = json.dumps(result, sort_keys=True, indent=2, separators=(u',', u': ')) |
|
264 | s = json.dumps(result, sort_keys=True, indent=2, separators=(u',', u': ')) | |
265 | ui.write(b'%s\n' % encoding.unitolocal(s)) |
|
265 | ui.write(b'%s\n' % encoding.unitolocal(s)) | |
@@ -273,7 +273,7 b' def getrepophid(repo):' | |||||
273 | callsign = repo.ui.config(b'phabricator', b'callsign') |
|
273 | callsign = repo.ui.config(b'phabricator', b'callsign') | |
274 | if not callsign: |
|
274 | if not callsign: | |
275 | return None |
|
275 | return None | |
276 | query = callconduit(repo, b'diffusion.repository.search', |
|
276 | query = callconduit(repo.ui, b'diffusion.repository.search', | |
277 | {b'constraints': {b'callsigns': [callsign]}}) |
|
277 | {b'constraints': {b'callsigns': [callsign]}}) | |
278 | if len(query[b'data']) == 0: |
|
278 | if len(query[b'data']) == 0: | |
279 | return None |
|
279 | return None | |
@@ -329,7 +329,7 b' def getoldnodedrevmap(repo, nodelist):' | |||||
329 | # Phabricator, and expect precursors overlap with it. |
|
329 | # Phabricator, and expect precursors overlap with it. | |
330 | if toconfirm: |
|
330 | if toconfirm: | |
331 | drevs = [drev for force, precs, drev in toconfirm.values()] |
|
331 | drevs = [drev for force, precs, drev in toconfirm.values()] | |
332 | alldiffs = callconduit(unfi, b'differential.querydiffs', |
|
332 | alldiffs = callconduit(unfi.ui, b'differential.querydiffs', | |
333 | {b'revisionIDs': drevs}) |
|
333 | {b'revisionIDs': drevs}) | |
334 | getnode = lambda d: bin( |
|
334 | getnode = lambda d: bin( | |
335 | getdiffmeta(d).get(b'node', b'')) or None |
|
335 | getdiffmeta(d).get(b'node', b'')) or None | |
@@ -379,7 +379,7 b' def creatediff(ctx):' | |||||
379 | params = {b'diff': getdiff(ctx, mdiff.diffopts(git=True, context=32767))} |
|
379 | params = {b'diff': getdiff(ctx, mdiff.diffopts(git=True, context=32767))} | |
380 | if repophid: |
|
380 | if repophid: | |
381 | params[b'repositoryPHID'] = repophid |
|
381 | params[b'repositoryPHID'] = repophid | |
382 | diff = callconduit(repo, b'differential.createrawdiff', params) |
|
382 | diff = callconduit(repo.ui, b'differential.createrawdiff', params) | |
383 | if not diff: |
|
383 | if not diff: | |
384 | raise error.Abort(_(b'cannot create diff for %s') % ctx) |
|
384 | raise error.Abort(_(b'cannot create diff for %s') % ctx) | |
385 | return diff |
|
385 | return diff | |
@@ -397,7 +397,7 b' def writediffproperties(ctx, diff):' | |||||
397 | b'parent': ctx.p1().hex(), |
|
397 | b'parent': ctx.p1().hex(), | |
398 | }), |
|
398 | }), | |
399 | } |
|
399 | } | |
400 | callconduit(ctx.repo(), b'differential.setdiffproperty', params) |
|
400 | callconduit(ctx.repo().ui, b'differential.setdiffproperty', params) | |
401 |
|
401 | |||
402 | params = { |
|
402 | params = { | |
403 | b'diff_id': diff[b'id'], |
|
403 | b'diff_id': diff[b'id'], | |
@@ -413,7 +413,7 b' def writediffproperties(ctx, diff):' | |||||
413 | }, |
|
413 | }, | |
414 | }), |
|
414 | }), | |
415 | } |
|
415 | } | |
416 | callconduit(ctx.repo(), b'differential.setdiffproperty', params) |
|
416 | callconduit(ctx.repo().ui, b'differential.setdiffproperty', params) | |
417 |
|
417 | |||
418 | def createdifferentialrevision(ctx, revid=None, parentrevid=None, oldnode=None, |
|
418 | def createdifferentialrevision(ctx, revid=None, parentrevid=None, oldnode=None, | |
419 | olddiff=None, actions=None, comment=None): |
|
419 | olddiff=None, actions=None, comment=None): | |
@@ -463,7 +463,7 b' def createdifferentialrevision(ctx, revi' | |||||
463 |
|
463 | |||
464 | # Parse commit message and update related fields. |
|
464 | # Parse commit message and update related fields. | |
465 | desc = ctx.description() |
|
465 | desc = ctx.description() | |
466 | info = callconduit(repo, b'differential.parsecommitmessage', |
|
466 | info = callconduit(repo.ui, b'differential.parsecommitmessage', | |
467 | {b'corpus': desc}) |
|
467 | {b'corpus': desc}) | |
468 | for k, v in info[b'fields'].items(): |
|
468 | for k, v in info[b'fields'].items(): | |
469 | if k in [b'title', b'summary', b'testPlan']: |
|
469 | if k in [b'title', b'summary', b'testPlan']: | |
@@ -474,7 +474,7 b' def createdifferentialrevision(ctx, revi' | |||||
474 | # Update an existing Differential Revision |
|
474 | # Update an existing Differential Revision | |
475 | params[b'objectIdentifier'] = revid |
|
475 | params[b'objectIdentifier'] = revid | |
476 |
|
476 | |||
477 | revision = callconduit(repo, b'differential.revision.edit', params) |
|
477 | revision = callconduit(repo.ui, b'differential.revision.edit', params) | |
478 | if not revision: |
|
478 | if not revision: | |
479 | raise error.Abort(_(b'cannot create revision for %s') % ctx) |
|
479 | raise error.Abort(_(b'cannot create revision for %s') % ctx) | |
480 |
|
480 | |||
@@ -484,7 +484,7 b' def userphids(repo, names):' | |||||
484 | """convert user names to PHIDs""" |
|
484 | """convert user names to PHIDs""" | |
485 | names = [name.lower() for name in names] |
|
485 | names = [name.lower() for name in names] | |
486 | query = {b'constraints': {b'usernames': names}} |
|
486 | query = {b'constraints': {b'usernames': names}} | |
487 | result = callconduit(repo, b'user.search', query) |
|
487 | result = callconduit(repo.ui, b'user.search', query) | |
488 | # username not found is not an error of the API. So check if we have missed |
|
488 | # username not found is not an error of the API. So check if we have missed | |
489 | # some names here. |
|
489 | # some names here. | |
490 | data = result[b'data'] |
|
490 | data = result[b'data'] | |
@@ -609,7 +609,7 b' def phabsend(ui, repo, *revs, **opts):' | |||||
609 | # Update commit messages and remove tags |
|
609 | # Update commit messages and remove tags | |
610 | if opts.get(b'amend'): |
|
610 | if opts.get(b'amend'): | |
611 | unfi = repo.unfiltered() |
|
611 | unfi = repo.unfiltered() | |
612 |
drevs = callconduit( |
|
612 | drevs = callconduit(ui, b'differential.query', {b'ids': drevids}) | |
613 | with repo.wlock(), repo.lock(), repo.transaction(b'phabsend'): |
|
613 | with repo.wlock(), repo.lock(), repo.transaction(b'phabsend'): | |
614 | wnode = unfi[b'.'].node() |
|
614 | wnode = unfi[b'.'].node() | |
615 | mapping = {} # {oldnode: [newnode]} |
|
615 | mapping = {} # {oldnode: [newnode]} | |
@@ -795,7 +795,7 b' def querydrev(repo, spec):' | |||||
795 | key = (params.get(b'ids') or params.get(b'phids') or [None])[0] |
|
795 | key = (params.get(b'ids') or params.get(b'phids') or [None])[0] | |
796 | if key in prefetched: |
|
796 | if key in prefetched: | |
797 | return prefetched[key] |
|
797 | return prefetched[key] | |
798 | drevs = callconduit(repo, b'differential.query', params) |
|
798 | drevs = callconduit(repo.ui, b'differential.query', params) | |
799 | # Fill prefetched with the result |
|
799 | # Fill prefetched with the result | |
800 | for drev in drevs: |
|
800 | for drev in drevs: | |
801 | prefetched[drev[b'phid']] = drev |
|
801 | prefetched[drev[b'phid']] = drev | |
@@ -953,14 +953,14 b' def readpatch(repo, drevs, write):' | |||||
953 | """ |
|
953 | """ | |
954 | # Prefetch hg:meta property for all diffs |
|
954 | # Prefetch hg:meta property for all diffs | |
955 | diffids = sorted(set(max(int(v) for v in drev[b'diffs']) for drev in drevs)) |
|
955 | diffids = sorted(set(max(int(v) for v in drev[b'diffs']) for drev in drevs)) | |
956 | diffs = callconduit(repo, b'differential.querydiffs', {b'ids': diffids}) |
|
956 | diffs = callconduit(repo.ui, b'differential.querydiffs', {b'ids': diffids}) | |
957 |
|
957 | |||
958 | # Generate patch for each drev |
|
958 | # Generate patch for each drev | |
959 | for drev in drevs: |
|
959 | for drev in drevs: | |
960 | repo.ui.note(_(b'reading D%s\n') % drev[b'id']) |
|
960 | repo.ui.note(_(b'reading D%s\n') % drev[b'id']) | |
961 |
|
961 | |||
962 | diffid = max(int(v) for v in drev[b'diffs']) |
|
962 | diffid = max(int(v) for v in drev[b'diffs']) | |
963 | body = callconduit(repo, b'differential.getrawdiff', |
|
963 | body = callconduit(repo.ui, b'differential.getrawdiff', | |
964 | {b'diffID': diffid}) |
|
964 | {b'diffID': diffid}) | |
965 | desc = getdescfromdrev(drev) |
|
965 | desc = getdescfromdrev(drev) | |
966 | header = b'# HG changeset patch\n' |
|
966 | header = b'# HG changeset patch\n' | |
@@ -1034,7 +1034,7 b' def phabupdate(ui, repo, spec, **opts):' | |||||
1034 | if actions: |
|
1034 | if actions: | |
1035 | params = {b'objectIdentifier': drev[b'phid'], |
|
1035 | params = {b'objectIdentifier': drev[b'phid'], | |
1036 | b'transactions': actions} |
|
1036 | b'transactions': actions} | |
1037 |
callconduit( |
|
1037 | callconduit(ui, b'differential.revision.edit', params) | |
1038 |
|
1038 | |||
1039 | templatekeyword = registrar.templatekeyword() |
|
1039 | templatekeyword = registrar.templatekeyword() | |
1040 |
|
1040 |
General Comments 0
You need to be logged in to leave comments.
Login now