# HG changeset patch # User Jun Wu # Date 2017-07-04 23:36:48 # Node ID 95f658b558a3626bd01cd5cf4e4c2a5cdec9f8fe # Parent 266321579c68a3a315406ca9fe381b21b9bf5b35 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. diff --git a/contrib/phabricator.py b/contrib/phabricator.py --- a/contrib/phabricator.py +++ b/contrib/phabricator.py @@ -202,17 +202,28 @@ def writediffproperties(ctx, diff): } callconduit(ctx.repo(), 'differential.setdiffproperty', params) -def createdifferentialrevision(ctx, revid=None, parentrevid=None): +def createdifferentialrevision(ctx, revid=None, parentrevid=None, oldnode=None): """create or update a Differential Revision If revid is None, create a new Differential Revision, otherwise update revid. If parentrevid is not None, set it as a dependency. + + If oldnode is not None, check if the patch content (without commit message + and metadata) has changed before creating another diff. """ repo = ctx.repo() - diff = creatediff(ctx) - writediffproperties(ctx, diff) + if oldnode: + diffopts = mdiff.diffopts(git=True, context=1) + oldctx = repo.unfiltered()[oldnode] + neednewdiff = (getdiff(ctx, diffopts) != getdiff(oldctx, diffopts)) + else: + neednewdiff = True - transactions = [{'type': 'update', 'value': diff[r'phid']}] + transactions = [] + if neednewdiff: + diff = creatediff(ctx) + writediffproperties(ctx, diff) + transactions.append({'type': 'update', 'value': diff[r'phid']}) # Use a temporary summary to set dependency. There might be better ways but # I cannot find them for now. But do not do that if we are updating an @@ -271,7 +282,8 @@ def phabsend(ui, repo, *revs, **opts): oldnode, revid = getmapping(ctx) if oldnode != ctx.node(): # Create or update Differential Revision - revision = createdifferentialrevision(ctx, revid, lastrevid) + revision = createdifferentialrevision(ctx, revid, lastrevid, + oldnode) newrevid = int(revision[r'object'][r'id']) if revid: action = _('updated')