mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 09:17:30 +03:00
285b5a92e6
This is the result of running a codemod script: python ~/hg/contrib/codemod/codemod_nestedwith.py **/*.py Plus a manual cleanup that removes the comment in `absorb/__init.py`. See D76 for the codemod script. Differential Revision: https://phab.mercurial-scm.org/D78
63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
# 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
|
|
from mercurial import extensions
|
|
from phabricator import diffprops
|
|
|
|
def getdiff(rev):
|
|
phabrev = diffprops.parserevfromcommitmsg(rev.description())
|
|
return int(phabrev) if phabrev else None
|
|
|
|
def extsetup(ui):
|
|
extensions.wrapcommand(commands.table, 'pull', _pull)
|
|
|
|
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
|
|
|
|
if not landeddiffs:
|
|
return r
|
|
|
|
# Try to find match with the drafts
|
|
tocreate = []
|
|
unfiltered = repo.unfiltered()
|
|
for rev in unfiltered.revs("draft() - obsolete()"):
|
|
n = unfiltered[rev]
|
|
diff = getdiff(n)
|
|
if diff in landeddiffs and landeddiffs[diff].rev() != n.rev():
|
|
tocreate.append((n, (landeddiffs[diff],)))
|
|
|
|
if not tocreate:
|
|
return r
|
|
|
|
with unfiltered.lock(), unfiltered.transaction('pullcreatemarkers'):
|
|
obsolete.createmarkers(unfiltered, tocreate)
|
|
|
|
return r
|