429 }, |
429 }, |
430 }), |
430 }), |
431 } |
431 } |
432 callconduit(ctx.repo().ui, b'differential.setdiffproperty', params) |
432 callconduit(ctx.repo().ui, b'differential.setdiffproperty', params) |
433 |
433 |
434 def createdifferentialrevision(ctx, revid=None, parentrevid=None, oldnode=None, |
434 def createdifferentialrevision(ctx, revid=None, parentrevphid=None, |
435 olddiff=None, actions=None, comment=None): |
435 oldnode=None, olddiff=None, actions=None, |
|
436 comment=None): |
436 """create or update a Differential Revision |
437 """create or update a Differential Revision |
437 |
438 |
438 If revid is None, create a new Differential Revision, otherwise update |
439 If revid is None, create a new Differential Revision, otherwise update |
439 revid. If parentrevid is not None, set it as a dependency. |
440 revid. If parentrevphid is not None, set it as a dependency. |
440 |
441 |
441 If oldnode is not None, check if the patch content (without commit message |
442 If oldnode is not None, check if the patch content (without commit message |
442 and metadata) has changed before creating another diff. |
443 and metadata) has changed before creating another diff. |
443 |
444 |
444 If actions is not None, they will be appended to the transaction. |
445 If actions is not None, they will be appended to the transaction. |
463 # pushers could know the correct node metadata. |
464 # pushers could know the correct node metadata. |
464 assert olddiff |
465 assert olddiff |
465 diff = olddiff |
466 diff = olddiff |
466 writediffproperties(ctx, diff) |
467 writediffproperties(ctx, diff) |
467 |
468 |
468 # Use a temporary summary to set dependency. There might be better ways but |
469 # Set the parent Revision every time, so commit re-ordering is picked-up |
469 # I cannot find them for now. But do not do that if we are updating an |
470 if parentrevphid: |
470 # existing revision (revid is not None) since that introduces visible |
471 transactions.append({b'type': b'parents.set', |
471 # churns (someone edited "Summary" twice) on the web page. |
472 b'value': [parentrevphid]}) |
472 if parentrevid and revid is None: |
|
473 summary = b'Depends on D%d' % parentrevid |
|
474 transactions += [{b'type': b'summary', b'value': summary}, |
|
475 {b'type': b'summary', b'value': b' '}] |
|
476 |
473 |
477 if actions: |
474 if actions: |
478 transactions += actions |
475 transactions += actions |
479 |
476 |
480 # Parse commit message and update related fields. |
477 # Parse commit message and update related fields. |
581 actions.append({b'type': b'reviewers.add', b'value': phids}) |
578 actions.append({b'type': b'reviewers.add', b'value': phids}) |
582 |
579 |
583 drevids = [] # [int] |
580 drevids = [] # [int] |
584 diffmap = {} # {newnode: diff} |
581 diffmap = {} # {newnode: diff} |
585 |
582 |
586 # Send patches one by one so we know their Differential Revision IDs and |
583 # Send patches one by one so we know their Differential Revision PHIDs and |
587 # can provide dependency relationship |
584 # can provide dependency relationship |
588 lastrevid = None |
585 lastrevphid = None |
589 for rev in revs: |
586 for rev in revs: |
590 ui.debug(b'sending rev %d\n' % rev) |
587 ui.debug(b'sending rev %d\n' % rev) |
591 ctx = repo[rev] |
588 ctx = repo[rev] |
592 |
589 |
593 # Get Differential Revision ID |
590 # Get Differential Revision ID |
594 oldnode, olddiff, revid = oldmap.get(ctx.node(), (None, None, None)) |
591 oldnode, olddiff, revid = oldmap.get(ctx.node(), (None, None, None)) |
595 if oldnode != ctx.node() or opts.get(b'amend'): |
592 if oldnode != ctx.node() or opts.get(b'amend'): |
596 # Create or update Differential Revision |
593 # Create or update Differential Revision |
597 revision, diff = createdifferentialrevision( |
594 revision, diff = createdifferentialrevision( |
598 ctx, revid, lastrevid, oldnode, olddiff, actions, |
595 ctx, revid, lastrevphid, oldnode, olddiff, actions, |
599 opts.get(b'comment')) |
596 opts.get(b'comment')) |
600 diffmap[ctx.node()] = diff |
597 diffmap[ctx.node()] = diff |
601 newrevid = int(revision[b'object'][b'id']) |
598 newrevid = int(revision[b'object'][b'id']) |
|
599 newrevphid = revision[b'object'][b'phid'] |
602 if revid: |
600 if revid: |
603 action = b'updated' |
601 action = b'updated' |
604 else: |
602 else: |
605 action = b'created' |
603 action = b'created' |
606 |
604 |
610 if not m or int(m.group(r'id')) != newrevid: |
608 if not m or int(m.group(r'id')) != newrevid: |
611 tagname = b'D%d' % newrevid |
609 tagname = b'D%d' % newrevid |
612 tags.tag(repo, tagname, ctx.node(), message=None, user=None, |
610 tags.tag(repo, tagname, ctx.node(), message=None, user=None, |
613 date=None, local=True) |
611 date=None, local=True) |
614 else: |
612 else: |
615 # Nothing changed. But still set "newrevid" so the next revision |
613 # Nothing changed. But still set "newrevphid" so the next revision |
616 # could depend on this one. |
614 # could depend on this one and "newrevid" for the summary line. |
|
615 newrevphid = querydrev(repo, str(revid))[0][b'phid'] |
617 newrevid = revid |
616 newrevid = revid |
618 action = b'skipped' |
617 action = b'skipped' |
619 |
618 |
620 actiondesc = ui.label( |
619 actiondesc = ui.label( |
621 {b'created': _(b'created'), |
620 {b'created': _(b'created'), |
626 nodedesc = ui.label(bytes(ctx), b'phabricator.node') |
625 nodedesc = ui.label(bytes(ctx), b'phabricator.node') |
627 desc = ui.label(ctx.description().split(b'\n')[0], b'phabricator.desc') |
626 desc = ui.label(ctx.description().split(b'\n')[0], b'phabricator.desc') |
628 ui.write(_(b'%s - %s - %s: %s\n') % (drevdesc, actiondesc, nodedesc, |
627 ui.write(_(b'%s - %s - %s: %s\n') % (drevdesc, actiondesc, nodedesc, |
629 desc)) |
628 desc)) |
630 drevids.append(newrevid) |
629 drevids.append(newrevid) |
631 lastrevid = newrevid |
630 lastrevphid = newrevphid |
632 |
631 |
633 # Update commit messages and remove tags |
632 # Update commit messages and remove tags |
634 if opts.get(b'amend'): |
633 if opts.get(b'amend'): |
635 unfi = repo.unfiltered() |
634 unfi = repo.unfiltered() |
636 drevs = callconduit(ui, b'differential.query', {b'ids': drevids}) |
635 drevs = callconduit(ui, b'differential.query', {b'ids': drevids}) |