hgext/phabricator.py
changeset 44645 419fec8237b7
parent 44644 dbe9182c90f5
child 44646 5f9c917e3b50
equal deleted inserted replaced
44644:dbe9182c90f5 44645:419fec8237b7
  1012     }
  1012     }
  1013     callconduit(basectx.repo().ui, b'differential.setdiffproperty', params)
  1013     callconduit(basectx.repo().ui, b'differential.setdiffproperty', params)
  1014 
  1014 
  1015 
  1015 
  1016 def createdifferentialrevision(
  1016 def createdifferentialrevision(
  1017     ctx,
  1017     ctxs,
  1018     revid=None,
  1018     revid=None,
  1019     parentrevphid=None,
  1019     parentrevphid=None,
       
  1020     oldbasenode=None,
  1020     oldnode=None,
  1021     oldnode=None,
  1021     olddiff=None,
  1022     olddiff=None,
  1022     actions=None,
  1023     actions=None,
  1023     comment=None,
  1024     comment=None,
  1024 ):
  1025 ):
  1025     """create or update a Differential Revision
  1026     """create or update a Differential Revision
  1026 
  1027 
  1027     If revid is None, create a new Differential Revision, otherwise update
  1028     If revid is None, create a new Differential Revision, otherwise update
  1028     revid. If parentrevphid is not None, set it as a dependency.
  1029     revid. If parentrevphid is not None, set it as a dependency.
  1029 
  1030 
       
  1031     If there is a single commit for the new Differential Revision, ``ctxs`` will
       
  1032     be a list of that single context.  Otherwise, it is a list that covers the
       
  1033     range of changes for the differential, where ``ctxs[0]`` is the first change
       
  1034     to include and ``ctxs[-1]`` is the last.
       
  1035 
  1030     If oldnode is not None, check if the patch content (without commit message
  1036     If oldnode is not None, check if the patch content (without commit message
  1031     and metadata) has changed before creating another diff.
  1037     and metadata) has changed before creating another diff.  For a Revision with
       
  1038     a single commit, ``oldbasenode`` and ``oldnode`` have the same value.  For a
       
  1039     Revision covering multiple commits, ``oldbasenode`` corresponds to
       
  1040     ``ctxs[0]`` the previous time this Revision was posted, and ``oldnode``
       
  1041     corresponds to ``ctxs[-1]``.
  1032 
  1042 
  1033     If actions is not None, they will be appended to the transaction.
  1043     If actions is not None, they will be appended to the transaction.
  1034     """
  1044     """
  1035     basectx = ctx
  1045     ctx = ctxs[-1]
       
  1046     basectx = ctxs[0]
       
  1047 
  1036     repo = ctx.repo()
  1048     repo = ctx.repo()
  1037     if oldnode:
  1049     if oldnode:
  1038         diffopts = mdiff.diffopts(git=True, context=32767)
  1050         diffopts = mdiff.diffopts(git=True, context=32767)
  1039         oldctx = repo.unfiltered()[oldnode]
  1051         unfi = repo.unfiltered()
  1040         oldbasectx = oldctx
  1052         oldctx = unfi[oldnode]
       
  1053         oldbasectx = unfi[oldbasenode]
  1041         neednewdiff = getdiff(basectx, ctx, diffopts) != getdiff(
  1054         neednewdiff = getdiff(basectx, ctx, diffopts) != getdiff(
  1042             oldbasectx, oldctx, diffopts
  1055             oldbasectx, oldctx, diffopts
  1043         )
  1056         )
  1044     else:
  1057     else:
  1045         neednewdiff = True
  1058         neednewdiff = True
  1054         # Even if we don't need to upload a new diff because the patch content
  1067         # Even if we don't need to upload a new diff because the patch content
  1055         # does not change. We might still need to update its metadata so
  1068         # does not change. We might still need to update its metadata so
  1056         # pushers could know the correct node metadata.
  1069         # pushers could know the correct node metadata.
  1057         assert olddiff
  1070         assert olddiff
  1058         diff = olddiff
  1071         diff = olddiff
  1059     writediffproperties([ctx], diff)
  1072     writediffproperties(ctxs, diff)
  1060 
  1073 
  1061     # Set the parent Revision every time, so commit re-ordering is picked-up
  1074     # Set the parent Revision every time, so commit re-ordering is picked-up
  1062     if parentrevphid:
  1075     if parentrevphid:
  1063         transactions.append(
  1076         transactions.append(
  1064             {b'type': b'parents.set', b'value': [parentrevphid]}
  1077             {b'type': b'parents.set', b'value': [parentrevphid]}
  1074     # an empty line), and use that as the summary field.  Do the same here.
  1087     # an empty line), and use that as the summary field.  Do the same here.
  1075     # For commits with only a one line message, there is no summary field, as
  1088     # For commits with only a one line message, there is no summary field, as
  1076     # this gets assigned to the title.
  1089     # this gets assigned to the title.
  1077     fields = util.sortdict()  # sorted for stable wire protocol in tests
  1090     fields = util.sortdict()  # sorted for stable wire protocol in tests
  1078 
  1091 
  1079     for i, _ctx in enumerate([ctx]):
  1092     for i, _ctx in enumerate(ctxs):
  1080         # Parse commit message and update related fields.
  1093         # Parse commit message and update related fields.
  1081         desc = _ctx.description()
  1094         desc = _ctx.description()
  1082         info = callconduit(
  1095         info = callconduit(
  1083             repo.ui, b'differential.parsecommitmessage', {b'corpus': desc}
  1096             repo.ui, b'differential.parsecommitmessage', {b'corpus': desc}
  1084         )
  1097         )
  1109         # Update an existing Differential Revision
  1122         # Update an existing Differential Revision
  1110         params[b'objectIdentifier'] = revid
  1123         params[b'objectIdentifier'] = revid
  1111 
  1124 
  1112     revision = callconduit(repo.ui, b'differential.revision.edit', params)
  1125     revision = callconduit(repo.ui, b'differential.revision.edit', params)
  1113     if not revision:
  1126     if not revision:
  1114         raise error.Abort(_(b'cannot create revision for %s') % ctx)
  1127         if len(ctxs) == 1:
       
  1128             msg = _(b'cannot create revision for %s') % ctx
       
  1129         else:
       
  1130             msg = _(b'cannot create revision for %s::%s') % (basectx, ctx)
       
  1131         raise error.Abort(msg)
  1115 
  1132 
  1116     return revision, diff
  1133     return revision, diff
  1117 
  1134 
  1118 
  1135 
  1119 def userphids(ui, names):
  1136 def userphids(ui, names):
  1224         ui.debug(b'sending rev %d\n' % rev)
  1241         ui.debug(b'sending rev %d\n' % rev)
  1225         ctx = repo[rev]
  1242         ctx = repo[rev]
  1226 
  1243 
  1227         # Get Differential Revision ID
  1244         # Get Differential Revision ID
  1228         oldnode, olddiff, revid = oldmap.get(ctx.node(), (None, None, None))
  1245         oldnode, olddiff, revid = oldmap.get(ctx.node(), (None, None, None))
       
  1246         oldbasenode = oldnode
  1229         if oldnode != ctx.node() or opts.get(b'amend'):
  1247         if oldnode != ctx.node() or opts.get(b'amend'):
  1230             # Create or update Differential Revision
  1248             # Create or update Differential Revision
  1231             revision, diff = createdifferentialrevision(
  1249             revision, diff = createdifferentialrevision(
  1232                 ctx,
  1250                 [ctx],
  1233                 revid,
  1251                 revid,
  1234                 lastrevphid,
  1252                 lastrevphid,
       
  1253                 oldbasenode,
  1235                 oldnode,
  1254                 oldnode,
  1236                 olddiff,
  1255                 olddiff,
  1237                 actions,
  1256                 actions,
  1238                 opts.get(b'comment'),
  1257                 opts.get(b'comment'),
  1239             )
  1258             )