comparison contrib/phabricator.py @ 33265:95f658b558a3

phabricator: do not upload new diff if nothing changes Previously, `phabsend` uploads new diffs as long as the commit hash changes. That's suboptimal because sometimes the diff is exactly the same as before, the commit hash change is caused by a parent hash change, or commit message change which do not affect diff content. This patch adds a check examining actual diff contents to skip uploading new diffs in that case.
author Jun Wu <quark@fb.com>
date Tue, 04 Jul 2017 16:36:48 -0700
parents 266321579c68
children 5b2391b46906
comparison
equal deleted inserted replaced
33264:266321579c68 33265:95f658b558a3
200 'parent': ctx.p1().hex(), 200 'parent': ctx.p1().hex(),
201 }), 201 }),
202 } 202 }
203 callconduit(ctx.repo(), 'differential.setdiffproperty', params) 203 callconduit(ctx.repo(), 'differential.setdiffproperty', params)
204 204
205 def createdifferentialrevision(ctx, revid=None, parentrevid=None): 205 def createdifferentialrevision(ctx, revid=None, parentrevid=None, oldnode=None):
206 """create or update a Differential Revision 206 """create or update a Differential Revision
207 207
208 If revid is None, create a new Differential Revision, otherwise update 208 If revid is None, create a new Differential Revision, otherwise update
209 revid. If parentrevid is not None, set it as a dependency. 209 revid. If parentrevid is not None, set it as a dependency.
210
211 If oldnode is not None, check if the patch content (without commit message
212 and metadata) has changed before creating another diff.
210 """ 213 """
211 repo = ctx.repo() 214 repo = ctx.repo()
212 diff = creatediff(ctx) 215 if oldnode:
213 writediffproperties(ctx, diff) 216 diffopts = mdiff.diffopts(git=True, context=1)
214 217 oldctx = repo.unfiltered()[oldnode]
215 transactions = [{'type': 'update', 'value': diff[r'phid']}] 218 neednewdiff = (getdiff(ctx, diffopts) != getdiff(oldctx, diffopts))
219 else:
220 neednewdiff = True
221
222 transactions = []
223 if neednewdiff:
224 diff = creatediff(ctx)
225 writediffproperties(ctx, diff)
226 transactions.append({'type': 'update', 'value': diff[r'phid']})
216 227
217 # Use a temporary summary to set dependency. There might be better ways but 228 # Use a temporary summary to set dependency. There might be better ways but
218 # I cannot find them for now. But do not do that if we are updating an 229 # I cannot find them for now. But do not do that if we are updating an
219 # existing revision (revid is not None) since that introduces visible 230 # existing revision (revid is not None) since that introduces visible
220 # churns (someone edited "Summary" twice) on the web page. 231 # churns (someone edited "Summary" twice) on the web page.
269 280
270 # Get Differential Revision ID 281 # Get Differential Revision ID
271 oldnode, revid = getmapping(ctx) 282 oldnode, revid = getmapping(ctx)
272 if oldnode != ctx.node(): 283 if oldnode != ctx.node():
273 # Create or update Differential Revision 284 # Create or update Differential Revision
274 revision = createdifferentialrevision(ctx, revid, lastrevid) 285 revision = createdifferentialrevision(ctx, revid, lastrevid,
286 oldnode)
275 newrevid = int(revision[r'object'][r'id']) 287 newrevid = int(revision[r'object'][r'id'])
276 if revid: 288 if revid:
277 action = _('updated') 289 action = _('updated')
278 else: 290 else:
279 action = _('created') 291 action = _('created')