2015-12-10 21:31:47 +03:00
|
|
|
# pullcreatemarkers.py - create obsolescence markers on pull for better rebases
|
|
|
|
#
|
|
|
|
# Copyright 2015 Facebook, Inc.
|
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
#
|
|
|
|
# The goal of this extensions is to create obsolescence markers locally for
|
|
|
|
# commits previously landed.
|
|
|
|
# It uses the phabricator revision number in the commit message to detect the
|
|
|
|
# relationship between a draft commit and its landed counterpart.
|
|
|
|
# Thanks to these markers, less information is displayed and rebases can have
|
|
|
|
# less irrelevant conflicts.
|
|
|
|
|
|
|
|
from mercurial import commands
|
|
|
|
from mercurial import obsolete
|
|
|
|
from mercurial import phases
|
2016-03-22 04:08:04 +03:00
|
|
|
from mercurial import extensions
|
2018-01-10 19:39:19 +03:00
|
|
|
from hgext.extlib.phabricator import diffprops
|
2015-12-10 21:31:47 +03:00
|
|
|
|
|
|
|
def getdiff(rev):
|
2016-04-27 19:50:13 +03:00
|
|
|
phabrev = diffprops.parserevfromcommitmsg(rev.description())
|
|
|
|
return int(phabrev) if phabrev else None
|
2015-12-10 21:31:47 +03:00
|
|
|
|
|
|
|
def extsetup(ui):
|
2016-03-22 04:08:04 +03:00
|
|
|
extensions.wrapcommand(commands.table, 'pull', _pull)
|
2015-12-10 21:31:47 +03:00
|
|
|
|
|
|
|
def _pull(orig, ui, repo, *args, **opts):
|
|
|
|
if not obsolete.isenabled(repo, obsolete.createmarkersopt):
|
|
|
|
return orig(ui, repo, *args, **opts)
|
|
|
|
maxrevbeforepull = len(repo.changelog)
|
|
|
|
r = orig(ui, repo, *args, **opts)
|
|
|
|
maxrevafterpull = len(repo.changelog)
|
|
|
|
|
|
|
|
# Collect the diff number of the landed diffs
|
|
|
|
landeddiffs = {}
|
|
|
|
for rev in range(maxrevbeforepull, maxrevafterpull):
|
|
|
|
n = repo[rev]
|
|
|
|
if n.phase() == phases.public:
|
|
|
|
diff = getdiff(n)
|
|
|
|
if diff is not None:
|
|
|
|
landeddiffs[diff] = n
|
|
|
|
|
[pullcreatemarkers] fix issues creating obsolescence markers
Summary:
Use a transaction, to make sure commits get hidden properly. Currently it
fails to hide all commits if multiple commits on the same branch are all
obsoleted in the same pull. When creating obsolescence markers for some of the
earlier commits, it thinks they still have non-hidden successors, and doesn't
know that these successors are also going to be hidden by the same pull
operation.
Also avoid walking all draft commits if nothing new was landed in this pull.
Test Plan:
Updated the tests to exercise the case where a pull obsoletes multiple commits
all at the tip of a branch.
Reviewers: #sourcecontrol, lcharignon, ikostia, durham, ttung
Reviewed By: durham
Subscribers: durham, net-systems-diffs@, yogeshwer, mjpieters
Differential Revision: https://phabricator.fb.com/D3013783
Signature: t1:3013783:1457136740:cbcd0220e82d044d25a34692793e70f5be61d63e
2016-03-05 03:28:58 +03:00
|
|
|
if not landeddiffs:
|
|
|
|
return r
|
|
|
|
|
2015-12-10 21:31:47 +03:00
|
|
|
# Try to find match with the drafts
|
[pullcreatemarkers] fix issues creating obsolescence markers
Summary:
Use a transaction, to make sure commits get hidden properly. Currently it
fails to hide all commits if multiple commits on the same branch are all
obsoleted in the same pull. When creating obsolescence markers for some of the
earlier commits, it thinks they still have non-hidden successors, and doesn't
know that these successors are also going to be hidden by the same pull
operation.
Also avoid walking all draft commits if nothing new was landed in this pull.
Test Plan:
Updated the tests to exercise the case where a pull obsoletes multiple commits
all at the tip of a branch.
Reviewers: #sourcecontrol, lcharignon, ikostia, durham, ttung
Reviewed By: durham
Subscribers: durham, net-systems-diffs@, yogeshwer, mjpieters
Differential Revision: https://phabricator.fb.com/D3013783
Signature: t1:3013783:1457136740:cbcd0220e82d044d25a34692793e70f5be61d63e
2016-03-05 03:28:58 +03:00
|
|
|
tocreate = []
|
2016-03-22 04:08:04 +03:00
|
|
|
unfiltered = repo.unfiltered()
|
2017-07-11 01:45:31 +03:00
|
|
|
for rev in unfiltered.revs("draft() - obsolete()"):
|
2016-03-22 04:08:04 +03:00
|
|
|
n = unfiltered[rev]
|
2015-12-10 21:31:47 +03:00
|
|
|
diff = getdiff(n)
|
2017-07-11 01:45:31 +03:00
|
|
|
if diff in landeddiffs and landeddiffs[diff].rev() != n.rev():
|
[pullcreatemarkers] fix issues creating obsolescence markers
Summary:
Use a transaction, to make sure commits get hidden properly. Currently it
fails to hide all commits if multiple commits on the same branch are all
obsoleted in the same pull. When creating obsolescence markers for some of the
earlier commits, it thinks they still have non-hidden successors, and doesn't
know that these successors are also going to be hidden by the same pull
operation.
Also avoid walking all draft commits if nothing new was landed in this pull.
Test Plan:
Updated the tests to exercise the case where a pull obsoletes multiple commits
all at the tip of a branch.
Reviewers: #sourcecontrol, lcharignon, ikostia, durham, ttung
Reviewed By: durham
Subscribers: durham, net-systems-diffs@, yogeshwer, mjpieters
Differential Revision: https://phabricator.fb.com/D3013783
Signature: t1:3013783:1457136740:cbcd0220e82d044d25a34692793e70f5be61d63e
2016-03-05 03:28:58 +03:00
|
|
|
tocreate.append((n, (landeddiffs[diff],)))
|
|
|
|
|
|
|
|
if not tocreate:
|
|
|
|
return r
|
|
|
|
|
2017-07-17 22:02:08 +03:00
|
|
|
with unfiltered.lock(), unfiltered.transaction('pullcreatemarkers'):
|
|
|
|
obsolete.createmarkers(unfiltered, tocreate)
|
2015-12-10 21:31:47 +03:00
|
|
|
|
|
|
|
return r
|