comparison hgext/phabricator.py @ 42188:289d82a070e9

phabricator: use templatefilters.json in writediffproperties Instead of json.dumps, since it makes the code simpler and more readable. This would have been the better option for 8fd19a7b4ed6 but I wasn't aware of it at the time. Differential Revision: https://phab.mercurial-scm.org/D6295
author Ian Moody <moz-ian@perix.co.uk>
date Mon, 22 Apr 2019 17:46:01 +0100
parents 99e00e5c4746
children c0e30c9ee5ba
comparison
equal deleted inserted replaced
42187:90d48c1c6224 42188:289d82a070e9
63 pycompat, 63 pycompat,
64 registrar, 64 registrar,
65 scmutil, 65 scmutil,
66 smartset, 66 smartset,
67 tags, 67 tags,
68 templatefilters,
68 templateutil, 69 templateutil,
69 url as urlmod, 70 url as urlmod,
70 util, 71 util,
71 ) 72 )
72 from mercurial.utils import ( 73 from mercurial.utils import (
378 def writediffproperties(ctx, diff): 379 def writediffproperties(ctx, diff):
379 """write metadata to diff so patches could be applied losslessly""" 380 """write metadata to diff so patches could be applied losslessly"""
380 params = { 381 params = {
381 b'diff_id': diff[b'id'], 382 b'diff_id': diff[b'id'],
382 b'name': b'hg:meta', 383 b'name': b'hg:meta',
383 b'data': json.dumps({ 384 b'data': templatefilters.json({
384 u'user': encoding.unifromlocal(ctx.user()), 385 b'user': ctx.user(),
385 u'date': u'{:.0f} {}'.format(*ctx.date()), 386 b'date': b'%d %d' % ctx.date(),
386 u'node': encoding.unifromlocal(ctx.hex()), 387 b'node': ctx.hex(),
387 u'parent': encoding.unifromlocal(ctx.p1().hex()), 388 b'parent': ctx.p1().hex(),
388 }), 389 }),
389 } 390 }
390 callconduit(ctx.repo(), b'differential.setdiffproperty', params) 391 callconduit(ctx.repo(), b'differential.setdiffproperty', params)
391 392
392 params = { 393 params = {
393 b'diff_id': diff[b'id'], 394 b'diff_id': diff[b'id'],
394 b'name': b'local:commits', 395 b'name': b'local:commits',
395 b'data': json.dumps({ 396 b'data': templatefilters.json({
396 encoding.unifromlocal(ctx.hex()): { 397 ctx.hex(): {
397 u'author': encoding.unifromlocal(stringutil.person(ctx.user())), 398 b'author': stringutil.person(ctx.user()),
398 u'authorEmail': encoding.unifromlocal( 399 b'authorEmail': stringutil.email(ctx.user()),
399 stringutil.email(ctx.user())), 400 b'time': b'%d' % ctx.date()[0],
400 u'time': u'{:.0f}'.format(ctx.date()[0]),
401 }, 401 },
402 }), 402 }),
403 } 403 }
404 callconduit(ctx.repo(), b'differential.setdiffproperty', params) 404 callconduit(ctx.repo(), b'differential.setdiffproperty', params)
405 405