comparison contrib/phabricator.py @ 33441:de7c6ec27d99

phabricator: respect metadata sent by arc Previously we only respect hg:meta sent by phabsend. This patch makes it respect local:commits sent by arc as well. This avoids issues where phabread could lose the author information. Test Plan: Commit using a customized user, send the patch using arc to a test Phabricator instance, and then read the patch using phabread. Make sure it preserves the user information. Differential Revision: https://phab.mercurial-scm.org/D33
author Jun Wu <quark@fb.com>
date Mon, 10 Jul 2017 22:37:33 -0700
parents 02299a28ba34
children 3ab0d5767b54
comparison
equal deleted inserted replaced
33440:ec306bc6915b 33441:de7c6ec27d99
411 if testplan: 411 if testplan:
412 testplan = 'Test Plan:\n%s' % testplan 412 testplan = 'Test Plan:\n%s' % testplan
413 uri = 'Differential Revision: %s' % drev[r'uri'] 413 uri = 'Differential Revision: %s' % drev[r'uri']
414 return '\n\n'.join(filter(None, [title, summary, testplan, uri])) 414 return '\n\n'.join(filter(None, [title, summary, testplan, uri]))
415 415
416 def getdiffmeta(diff):
417 """get commit metadata (date, node, user, p1) from a diff object
418
419 The metadata could be "hg:meta", sent by phabsend, like:
420
421 "properties": {
422 "hg:meta": {
423 "date": "1499571514 25200",
424 "node": "98c08acae292b2faf60a279b4189beb6cff1414d",
425 "user": "Foo Bar <foo@example.com>",
426 "parent": "6d0abad76b30e4724a37ab8721d630394070fe16"
427 }
428 }
429
430 Or converted from "local:commits", sent by "arc", like:
431
432 "properties": {
433 "local:commits": {
434 "98c08acae292b2faf60a279b4189beb6cff1414d": {
435 "author": "Foo Bar",
436 "time": 1499546314,
437 "branch": "default",
438 "tag": "",
439 "commit": "98c08acae292b2faf60a279b4189beb6cff1414d",
440 "rev": "98c08acae292b2faf60a279b4189beb6cff1414d",
441 "local": "1000",
442 "parents": ["6d0abad76b30e4724a37ab8721d630394070fe16"],
443 "summary": "...",
444 "message": "...",
445 "authorEmail": "foo@example.com"
446 }
447 }
448 }
449
450 Note: metadata extracted from "local:commits" will lose time zone
451 information.
452 """
453 props = diff.get(r'properties') or {}
454 meta = props.get(r'hg:meta')
455 if not meta and props.get(r'local:commits'):
456 commit = sorted(props[r'local:commits'].values())[0]
457 meta = {
458 r'date': r'%d 0' % commit[r'time'],
459 r'node': commit[r'rev'],
460 r'user': r'%s <%s>' % (commit[r'author'], commit[r'authorEmail']),
461 }
462 if len(commit.get(r'parents', ())) >= 1:
463 meta[r'parent'] = commit[r'parents'][0]
464 return meta or {}
465
416 def readpatch(repo, params, write, stack=False): 466 def readpatch(repo, params, write, stack=False):
417 """generate plain-text patch readable by 'hg import' 467 """generate plain-text patch readable by 'hg import'
418 468
419 write is usually ui.write. params is passed to "differential.query". If 469 write is usually ui.write. params is passed to "differential.query". If
420 stack is True, also write dependent patches. 470 stack is True, also write dependent patches.
436 header = '# HG changeset patch\n' 486 header = '# HG changeset patch\n'
437 487
438 # Try to preserve metadata from hg:meta property. Write hg patch 488 # Try to preserve metadata from hg:meta property. Write hg patch
439 # headers that can be read by the "import" command. See patchheadermap 489 # headers that can be read by the "import" command. See patchheadermap
440 # and extract in mercurial/patch.py for supported headers. 490 # and extract in mercurial/patch.py for supported headers.
441 props = diffs[str(diffid)][r'properties'] # could be empty list or dict 491 meta = getdiffmeta(diffs[str(diffid)])
442 if props and r'hg:meta' in props: 492 for k in _metanamemap.keys():
443 meta = props[r'hg:meta'] 493 if k in meta:
444 for k in _metanamemap.keys(): 494 header += '# %s %s\n' % (_metanamemap[k], meta[k])
445 if k in meta:
446 header += '# %s %s\n' % (_metanamemap[k], meta[k])
447 495
448 write(('%s%s\n%s') % (header, desc, body)) 496 write(('%s%s\n%s') % (header, desc, body))
449 497
450 @command('phabread', 498 @command('phabread',
451 [('', 'stack', False, _('read dependencies'))], 499 [('', 'stack', False, _('read dependencies'))],