| 1 |
# narrowtemplates.py - added template keywords for narrow clones |
| 2 |
# |
| 3 |
# Copyright 2017 Google, Inc. |
| 4 |
# |
| 5 |
# This software may be used and distributed according to the terms of the |
| 6 |
# GNU General Public License version 2 or any later version. |
| 7 |
|
| 8 |
from __future__ import annotations |
| 9 |
|
| 10 |
from mercurial import ( |
| 11 |
registrar, |
| 12 |
revlog, |
| 13 |
) |
| 14 |
|
| 15 |
keywords = {} |
| 16 |
templatekeyword = registrar.templatekeyword(keywords) |
| 17 |
revsetpredicate = registrar.revsetpredicate() |
| 18 |
|
| 19 |
|
| 20 |
def _isellipsis(repo, rev): |
| 21 |
if repo.changelog.flags(rev) & revlog.REVIDX_ELLIPSIS: |
| 22 |
return True |
| 23 |
return False |
| 24 |
|
| 25 |
|
| 26 |
@templatekeyword(b'ellipsis', requires={b'repo', b'ctx'}) |
| 27 |
def ellipsis(context, mapping): |
| 28 |
"""String. 'ellipsis' if the change is an ellipsis node, else ''.""" |
| 29 |
repo = context.resource(mapping, b'repo') |
| 30 |
ctx = context.resource(mapping, b'ctx') |
| 31 |
if _isellipsis(repo, ctx.rev()): |
| 32 |
return b'ellipsis' |
| 33 |
return b'' |
| 34 |
|
| 35 |
|
| 36 |
@templatekeyword(b'outsidenarrow', requires={b'repo', b'ctx'}) |
| 37 |
def outsidenarrow(context, mapping): |
| 38 |
"""String. 'outsidenarrow' if the change affects no tracked files, |
| 39 |
else ''.""" |
| 40 |
repo = context.resource(mapping, b'repo') |
| 41 |
ctx = context.resource(mapping, b'ctx') |
| 42 |
m = repo.narrowmatch() |
| 43 |
if ctx.files() and not m.always(): |
| 44 |
if not any(m(f) for f in ctx.files()): |
| 45 |
return b'outsidenarrow' |
| 46 |
return b'' |
| 47 |
|
| 48 |
|
| 49 |
@revsetpredicate(b'ellipsis()') |
| 50 |
def ellipsisrevset(repo, subset, x): |
| 51 |
"""Changesets that are ellipsis nodes.""" |
| 52 |
return subset.filter(lambda r: _isellipsis(repo, r)) |