##// END OF EJS Templates
phases: avoid a potentially costly dictionary interation in some case...
phases: avoid a potentially costly dictionary interation in some case If we retract for the draft phase, there is not non-public item to be retracted and we can skip this part. This part is was apparently super costly thanks to Python. On mozilla-try-2019-02-18, a perf::unbundle call with a 10 000 changesets bundle gives give use the following timing. e57d4b868a3e: 4.6 seconds ac1c75188440: 102.5 seconds this-changeset: 30.0 seconds So we recovered about ⅔ of the regression, the next changeset will give us the rest back.

File last commit:

r49730:6000f5b2 default
r52409:e0f92bd9 stable
Show More
enforce_draft_commits.py
44 lines | 1.3 KiB | text/x-python | PythonLexer
/ hgext / hooklib / enforce_draft_commits.py
# Copyright 2020 Joerg Sonnenberger <joerg@bec.de>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
"""enforce_draft_commits us a hook to ensure that all new changesets are
in the draft phase. This allows enforcing policies for work-in-progress
changes in overlay repositories, i.e. a shared hidden repositories with
different views for work-in-progress code and public history.
Usage:
[hooks]
pretxnclose-phase.enforce_draft_commits = \
python:hgext.hooklib.enforce_draft_commits.hook
"""
from mercurial.i18n import _
from mercurial import (
error,
pycompat,
)
def hook(ui, repo, hooktype, node=None, **kwargs):
if hooktype != b"pretxnclose-phase":
raise error.Abort(
_(b'Unsupported hook type %r') % pycompat.bytestr(hooktype)
)
ctx = repo.unfiltered()[node]
if kwargs['oldphase']:
raise error.Abort(
_(b'Phase change from %r to %r for %s rejected')
% (
pycompat.bytestr(kwargs['oldphase']),
pycompat.bytestr(kwargs['phase']),
ctx,
)
)
elif kwargs['phase'] != b'draft':
raise error.Abort(
_(b'New changeset %s in phase %r rejected')
% (ctx, pycompat.bytestr(kwargs['phase']))
)