hgext/narrow/narrowtemplates.py
author Gregory Szorc <gregory.szorc@gmail.com>
Wed, 19 Sep 2018 11:17:28 -0700
changeset 39842 97986c9c69d3
parent 38964 05ded838c997
child 42358 45c18f7345c1
permissions -rw-r--r--
verify: start to abstract file verification Currently, the file storage interface has a handful of attributes that are exclusively or near-exclusively used by repo verification code. In order to support verification on non-revlog/alternate storage backends, we'll need to abstract verification so it can be performed in a storage-agnostic way. This commit starts that process. We establish a new verifyintegrity() method on revlogs and expose it to the file storage interface. Most of verify.verifier.checklog() has been ported to this new method. We need a way to represent verification problems. So we invent an interface to represent a verification problem, invent a revlog type to implement that interface, and use it. The arguments to verifyintegrity() will almost certainly change in the future, once more functionality is ported from the verify code. And the "revlogv1" version check is very hacky. (The code in verify is actually buggy because it is comparing the full 32-bit header integer instead of just the revlog version short. I'll likely fix this in a subsequent commit.) Differential Revision: https://phab.mercurial-scm.org/D4701
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
# narrowtemplates.py - added template keywords for narrow clones
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
#
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     3
# Copyright 2017 Google, Inc.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     4
#
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     7
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     8
from __future__ import absolute_import
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     9
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
from mercurial import (
36091
ea02be8665ef narrowtemplates: update to use registrar mechanism
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
    11
    registrar,
36090
9445a3141501 narrow: move from ELLIPSIS_NODE_FLAG to revlog.REVIDX_ELLIPSIS
Augie Fackler <augie@google.com>
parents: 36079
diff changeset
    12
    revlog,
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    13
)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
36091
ea02be8665ef narrowtemplates: update to use registrar mechanism
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
    15
keywords = {}
ea02be8665ef narrowtemplates: update to use registrar mechanism
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
    16
templatekeyword = registrar.templatekeyword(keywords)
ea02be8665ef narrowtemplates: update to use registrar mechanism
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
    17
revsetpredicate = registrar.revsetpredicate()
ea02be8665ef narrowtemplates: update to use registrar mechanism
Augie Fackler <augie@google.com>
parents: 36090
diff changeset
    18
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
def _isellipsis(repo, rev):
36090
9445a3141501 narrow: move from ELLIPSIS_NODE_FLAG to revlog.REVIDX_ELLIPSIS
Augie Fackler <augie@google.com>
parents: 36079
diff changeset
    20
    if repo.changelog.flags(rev) & revlog.REVIDX_ELLIPSIS:
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    21
        return True
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
    return False
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    23
36514
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36472
diff changeset
    24
@templatekeyword('ellipsis', requires={'repo', 'ctx'})
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36472
diff changeset
    25
def ellipsis(context, mapping):
36439
02cd2fb6de72 narrow: drop redundant templatekw/revset names from help text
Yuya Nishihara <yuya@tcha.org>
parents: 36091
diff changeset
    26
    """String. 'ellipsis' if the change is an ellipsis node, else ''."""
36514
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36472
diff changeset
    27
    repo = context.resource(mapping, 'repo')
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36472
diff changeset
    28
    ctx = context.resource(mapping, 'ctx')
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    29
    if _isellipsis(repo, ctx.rev()):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    30
        return 'ellipsis'
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    31
    return ''
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    32
36514
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36472
diff changeset
    33
@templatekeyword('outsidenarrow', requires={'repo', 'ctx'})
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36472
diff changeset
    34
def outsidenarrow(context, mapping):
36439
02cd2fb6de72 narrow: drop redundant templatekw/revset names from help text
Yuya Nishihara <yuya@tcha.org>
parents: 36091
diff changeset
    35
    """String. 'outsidenarrow' if the change affects no tracked files,
02cd2fb6de72 narrow: drop redundant templatekw/revset names from help text
Yuya Nishihara <yuya@tcha.org>
parents: 36091
diff changeset
    36
    else ''."""
36514
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36472
diff changeset
    37
    repo = context.resource(mapping, 'repo')
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36472
diff changeset
    38
    ctx = context.resource(mapping, 'ctx')
36472
d0d5eef57fb0 narrow: drop safehasattr() checks for always-present repo.narrowmatch
Martin von Zweigbergk <martinvonz@google.com>
parents: 36439
diff changeset
    39
    m = repo.narrowmatch()
d0d5eef57fb0 narrow: drop safehasattr() checks for always-present repo.narrowmatch
Martin von Zweigbergk <martinvonz@google.com>
parents: 36439
diff changeset
    40
    if not m.always():
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    41
        if not any(m(f) for f in ctx.files()):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    42
            return 'outsidenarrow'
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    43
    return ''
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    44
38964
05ded838c997 narrow: add '()' to ellipsis in the revset help
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 36514
diff changeset
    45
@revsetpredicate('ellipsis()')
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    46
def ellipsisrevset(repo, subset, x):
36439
02cd2fb6de72 narrow: drop redundant templatekw/revset names from help text
Yuya Nishihara <yuya@tcha.org>
parents: 36091
diff changeset
    47
    """Changesets that are ellipsis nodes."""
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    48
    return subset.filter(lambda r: _isellipsis(repo, r))