hgext/narrow/__init__.py
author Martin von Zweigbergk <martinvonz@google.com>
Thu, 02 Aug 2018 14:57:20 -0700
changeset 38872 576eef1ab43d
parent 38835 a232e6744ba3
child 38890 d706c77449f9
permissions -rw-r--r--
narrow: move .hg/narrowspec to .hg/store/narrowspec (BC) The narrowspec is more closely related to the store than to the working copy. For example, if the narrowspec changes, the set of revlogs also needs to change (the working copy may change, but that depends on which commit is checked out). Also, when using the share extension, the narrowspec needs to be shared along with the store. This patch therefore moves the narrowspec into the store/ directory. This is clearly a breaking change, but I haven't bothered trying to fall back to reading the narrowspec from the old location (.hg/), because there are very few users of narrow out there. (We'll add a temporary hack to our Google-internal extension to handle the migration.) Differential Revision: https://phab.mercurial-scm.org/D4099
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
# __init__.py - narrowhg extension
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
'''create clones which fetch history data for subset of files (EXPERIMENTAL)'''
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     8
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     9
from __future__ import absolute_import
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
36085
4b843cb6eb8c narrow: remove old version-checking logic and declare internal
Augie Fackler <augie@google.com>
parents: 36080
diff changeset
    11
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
4b843cb6eb8c narrow: remove old version-checking logic and declare internal
Augie Fackler <augie@google.com>
parents: 36080
diff changeset
    12
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
4b843cb6eb8c narrow: remove old version-checking logic and declare internal
Augie Fackler <augie@google.com>
parents: 36080
diff changeset
    13
# be specifying the version(s) of Mercurial they are tested with, or
4b843cb6eb8c narrow: remove old version-checking logic and declare internal
Augie Fackler <augie@google.com>
parents: 36080
diff changeset
    14
# leave the attribute unspecified.
4b843cb6eb8c narrow: remove old version-checking logic and declare internal
Augie Fackler <augie@google.com>
parents: 36080
diff changeset
    15
testedwith = 'ships-with-hg-core'
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    16
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    17
from mercurial import (
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    18
    extensions,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
    localrepo,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    20
    registrar,
38835
a232e6744ba3 narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents: 38128
diff changeset
    21
    repository,
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
    verify as verifymod,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    23
)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    25
from . import (
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    26
    narrowbundle2,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    27
    narrowchangegroup,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    28
    narrowcommands,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    29
    narrowcopies,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    30
    narrowpatch,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    31
    narrowrepo,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    32
    narrowrevlog,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    33
    narrowtemplates,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    34
    narrowwirepeer,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    35
)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    36
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    37
configtable = {}
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    38
configitem = registrar.configitem(configtable)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    39
# Narrowhg *has* support for serving ellipsis nodes (which are used at
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    40
# least by Google's internal server), but that support is pretty
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    41
# fragile and has a lot of problems on real-world repositories that
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    42
# have complex graph topologies. This could probably be corrected, but
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    43
# absent someone needing the full support for ellipsis nodes in
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    44
# repositories with merges, it's unlikely this work will get done. As
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    45
# of this writining in late 2017, all repositories large enough for
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    46
# ellipsis nodes to be a hard requirement also enforce strictly linear
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    47
# history for other scaling reasons.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    48
configitem('experimental', 'narrowservebrokenellipses',
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    49
           default=False,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    50
           alias=[('narrow', 'serveellipses')],
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    51
)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    52
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    53
# Export the commands table for Mercurial to see.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    54
cmdtable = narrowcommands.table
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    55
37136
e2d386b8a38f narrow: use featuresetupfuncs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36472
diff changeset
    56
def featuresetup(ui, features):
38835
a232e6744ba3 narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents: 38128
diff changeset
    57
    features.add(repository.NARROW_REQUIREMENT)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    58
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    59
def uisetup(ui):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    60
    """Wraps user-facing mercurial commands with narrow-aware versions."""
37136
e2d386b8a38f narrow: use featuresetupfuncs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36472
diff changeset
    61
    localrepo.featuresetupfuncs.add(featuresetup)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    62
    narrowrevlog.setup()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    63
    narrowbundle2.setup()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    64
    narrowcommands.setup()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    65
    narrowchangegroup.setup()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    66
    narrowwirepeer.uisetup()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    67
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    68
def reposetup(ui, repo):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    69
    """Wraps local repositories with narrow repo support."""
37186
6d43b39fbaa0 narrow: use repo.local() instead of isinstance()
Martin von Zweigbergk <martinvonz@google.com>
parents: 37136
diff changeset
    70
    if not repo.local():
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    71
        return
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    72
38835
a232e6744ba3 narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents: 38128
diff changeset
    73
    if repository.NARROW_REQUIREMENT in repo.requirements:
38128
1cba497491be narrow: only wrap dirstate functions once, instead of per-reposetup
Kyle Lippincott <spectral@google.com>
parents: 38046
diff changeset
    74
        narrowrepo.wraprepo(repo)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    75
        narrowcopies.setup(repo)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    76
        narrowpatch.setup(repo)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    77
        narrowwirepeer.reposetup(repo)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    78
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    79
def _verifierinit(orig, self, repo, matcher=None):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    80
    # The verifier's matcher argument was desgined for narrowhg, so it should
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    81
    # be None from core. If another extension passes a matcher (unlikely),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    82
    # we'll have to fail until matchers can be composed more easily.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    83
    assert matcher is None
36472
d0d5eef57fb0 narrow: drop safehasattr() checks for always-present repo.narrowmatch
Martin von Zweigbergk <martinvonz@google.com>
parents: 36468
diff changeset
    84
    orig(self, repo, repo.narrowmatch())
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    85
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    86
def extsetup(ui):
36080
9dc28d8ea61e narrow: remove support for old match modules
Augie Fackler <augie@google.com>
parents: 36079
diff changeset
    87
    extensions.wrapfunction(verifymod.verifier, '__init__', _verifierinit)
36091
ea02be8665ef narrowtemplates: update to use registrar mechanism
Augie Fackler <augie@google.com>
parents: 36088
diff changeset
    88
ea02be8665ef narrowtemplates: update to use registrar mechanism
Augie Fackler <augie@google.com>
parents: 36088
diff changeset
    89
templatekeyword = narrowtemplates.templatekeyword
ea02be8665ef narrowtemplates: update to use registrar mechanism
Augie Fackler <augie@google.com>
parents: 36088
diff changeset
    90
revsetpredicate = narrowtemplates.revsetpredicate