hgext/narrow/narrowcommands.py
author Gregory Szorc <gregory.szorc@gmail.com>
Wed, 19 Sep 2018 11:17:28 -0700
changeset 39842 97986c9c69d3
parent 39818 24e493ec2229
child 39933 d5498db5f86a
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
# narrowcommands.py - command modifications for 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
from __future__ import absolute_import
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
import itertools
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    10
import os
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    11
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    12
from mercurial.i18n import _
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    13
from mercurial import (
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
    cmdutil,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    15
    commands,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    16
    discovery,
39440
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
    17
    encoding,
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    18
    error,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
    exchange,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    20
    extensions,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    21
    hg,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
    merge,
36160
9fd8c2a3db5a narrowspec: move module into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36154
diff changeset
    23
    narrowspec,
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
    node,
36154
4a7ba3ac9163 narrowcommands: use pycompat.{bytes,str}kwargs
Augie Fackler <augie@google.com>
parents: 36100
diff changeset
    25
    pycompat,
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    26
    registrar,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    27
    repair,
38835
a232e6744ba3 narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents: 38528
diff changeset
    28
    repository,
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    29
    repoview,
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    30
    sparse,
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    31
    util,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    32
)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    33
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    34
from . import (
39529
e82da0fcc7c5 narrow: move wire proto capabilities to narrowwirepeer
Martin von Zweigbergk <martinvonz@google.com>
parents: 39528
diff changeset
    35
    narrowwirepeer,
36079
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
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    38
table = {}
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    39
command = registrar.command(table)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    40
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    41
def setup():
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    42
    """Wraps user-facing mercurial commands with narrow-aware versions."""
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    43
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    44
    entry = extensions.wrapcommand(commands.table, 'clone', clonenarrowcmd)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    45
    entry[1].append(('', 'narrow', None,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    46
                     _("create a narrow clone of select files")))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    47
    entry[1].append(('', 'depth', '',
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    48
                     _("limit the history fetched by distance from heads")))
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    49
    entry[1].append(('', 'narrowspec', '',
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    50
                     _("read narrowspecs from file")))
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    51
    # TODO(durin42): unify sparse/narrow --include/--exclude logic a bit
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    52
    if 'sparse' not in extensions.enabled():
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    53
        entry[1].append(('', 'include', [],
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    54
                         _("specifically fetch this file/directory")))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    55
        entry[1].append(
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    56
            ('', 'exclude', [],
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    57
             _("do not fetch this file/directory, even if included")))
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
    entry = extensions.wrapcommand(commands.table, 'pull', pullnarrowcmd)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    60
    entry[1].append(('', 'depth', '',
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    61
                     _("limit the history fetched by distance from heads")))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    62
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    63
    extensions.wrapcommand(commands.table, 'archive', archivenarrowcmd)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    64
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    65
def clonenarrowcmd(orig, ui, repo, *args, **opts):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    66
    """Wraps clone command, so 'hg clone' first wraps localrepo.clone()."""
36154
4a7ba3ac9163 narrowcommands: use pycompat.{bytes,str}kwargs
Augie Fackler <augie@google.com>
parents: 36100
diff changeset
    67
    opts = pycompat.byteskwargs(opts)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    68
    wrappedextraprepare = util.nullcontextmanager()
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    69
    narrowspecfile = opts['narrowspec']
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    70
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    71
    if narrowspecfile:
39818
24e493ec2229 py3: rename pycompat.getcwd() to encoding.getcwd() (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 39734
diff changeset
    72
        filepath = os.path.join(encoding.getcwd(), narrowspecfile)
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    73
        ui.status(_("reading narrowspec from '%s'\n") % filepath)
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    74
        try:
39465
4062bbb1d10f narrow: use util.readfile() and improve error message using --narrowspec
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39440
diff changeset
    75
            fdata = util.readfile(filepath)
4062bbb1d10f narrow: use util.readfile() and improve error message using --narrowspec
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39440
diff changeset
    76
        except IOError as inst:
4062bbb1d10f narrow: use util.readfile() and improve error message using --narrowspec
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39440
diff changeset
    77
            raise error.Abort(_("cannot read narrowspecs from '%s': %s") %
4062bbb1d10f narrow: use util.readfile() and improve error message using --narrowspec
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39440
diff changeset
    78
                              (filepath, encoding.strtolocal(inst.strerror)))
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    79
39465
4062bbb1d10f narrow: use util.readfile() and improve error message using --narrowspec
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39440
diff changeset
    80
        includes, excludes, profiles = sparse.parseconfig(ui, fdata, 'narrow')
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    81
        if profiles:
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    82
            raise error.Abort(_("cannot specify other files using '%include' in"
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    83
                                " narrowspec"))
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    84
39541
8301741e1f89 narrow: validate spec files are well-formed during clone (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39532
diff changeset
    85
        narrowspec.validatepatterns(includes)
8301741e1f89 narrow: validate spec files are well-formed during clone (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39532
diff changeset
    86
        narrowspec.validatepatterns(excludes)
8301741e1f89 narrow: validate spec files are well-formed during clone (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39532
diff changeset
    87
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    88
        # narrowspec is passed so we should assume that user wants narrow clone
39545
4afd2af36456 narrow: set opts['narrow'] instead of local variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39544
diff changeset
    89
        opts['narrow'] = True
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    90
        opts['include'].extend(includes)
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    91
        opts['exclude'].extend(excludes)
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
    92
39545
4afd2af36456 narrow: set opts['narrow'] instead of local variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39544
diff changeset
    93
    if opts['narrow']:
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    94
        def pullbundle2extraprepare_widen(orig, pullop, kwargs):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    95
            orig(pullop, kwargs)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    96
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    97
            if opts.get('depth'):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    98
                kwargs['depth'] = opts['depth']
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    99
        wrappedextraprepare = extensions.wrappedfunction(exchange,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   100
            '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   101
39554
841c82d1a973 narrow: don't wrap exchange.pull() during clone
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39545
diff changeset
   102
    with wrappedextraprepare:
36154
4a7ba3ac9163 narrowcommands: use pycompat.{bytes,str}kwargs
Augie Fackler <augie@google.com>
parents: 36100
diff changeset
   103
        return orig(ui, repo, *args, **pycompat.strkwargs(opts))
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   104
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   105
def pullnarrowcmd(orig, ui, repo, *args, **opts):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   106
    """Wraps pull command to allow modifying narrow spec."""
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   107
    wrappedextraprepare = util.nullcontextmanager()
38835
a232e6744ba3 narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents: 38528
diff changeset
   108
    if repository.NARROW_REQUIREMENT in repo.requirements:
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   109
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   110
        def pullbundle2extraprepare_widen(orig, pullop, kwargs):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   111
            orig(pullop, kwargs)
36456
9ff5cbfbc26a py3: fix more keyword arguments handling
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36352
diff changeset
   112
            if opts.get(r'depth'):
9ff5cbfbc26a py3: fix more keyword arguments handling
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36352
diff changeset
   113
                kwargs['depth'] = opts[r'depth']
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   114
        wrappedextraprepare = extensions.wrappedfunction(exchange,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   115
            '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   116
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   117
    with wrappedextraprepare:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   118
        return orig(ui, repo, *args, **opts)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   119
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   120
def archivenarrowcmd(orig, ui, repo, *args, **opts):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   121
    """Wraps archive command to narrow the default includes."""
38835
a232e6744ba3 narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents: 38528
diff changeset
   122
    if repository.NARROW_REQUIREMENT in repo.requirements:
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   123
        repo_includes, repo_excludes = repo.narrowpats
36352
5dbeddbf164a narrowcommands: add some missing strkwargs calls for py3
Augie Fackler <augie@google.com>
parents: 36166
diff changeset
   124
        includes = set(opts.get(r'include', []))
5dbeddbf164a narrowcommands: add some missing strkwargs calls for py3
Augie Fackler <augie@google.com>
parents: 36166
diff changeset
   125
        excludes = set(opts.get(r'exclude', []))
36100
8fd0a9e2d7e9 narrow: make restrictpatterns a little more idiomatic
Augie Fackler <augie@google.com>
parents: 36088
diff changeset
   126
        includes, excludes, unused_invalid = narrowspec.restrictpatterns(
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   127
            includes, excludes, repo_includes, repo_excludes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   128
        if includes:
36352
5dbeddbf164a narrowcommands: add some missing strkwargs calls for py3
Augie Fackler <augie@google.com>
parents: 36166
diff changeset
   129
            opts[r'include'] = includes
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   130
        if excludes:
36352
5dbeddbf164a narrowcommands: add some missing strkwargs calls for py3
Augie Fackler <augie@google.com>
parents: 36166
diff changeset
   131
            opts[r'exclude'] = excludes
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   132
    return orig(ui, repo, *args, **opts)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   133
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   134
def pullbundle2extraprepare(orig, pullop, kwargs):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   135
    repo = pullop.repo
38835
a232e6744ba3 narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents: 38528
diff changeset
   136
    if repository.NARROW_REQUIREMENT not in repo.requirements:
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   137
        return orig(pullop, kwargs)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   138
39529
e82da0fcc7c5 narrow: move wire proto capabilities to narrowwirepeer
Martin von Zweigbergk <martinvonz@google.com>
parents: 39528
diff changeset
   139
    if narrowwirepeer.NARROWCAP not in pullop.remote.capabilities():
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   140
        raise error.Abort(_("server doesn't support narrow clones"))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   141
    orig(pullop, kwargs)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   142
    kwargs['narrow'] = True
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   143
    include, exclude = repo.narrowpats
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   144
    kwargs['oldincludepats'] = include
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   145
    kwargs['oldexcludepats'] = exclude
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   146
    kwargs['includepats'] = include
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   147
    kwargs['excludepats'] = exclude
39524
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
   148
    # calculate known nodes only in ellipses cases because in non-ellipses cases
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
   149
    # we have all the nodes
39529
e82da0fcc7c5 narrow: move wire proto capabilities to narrowwirepeer
Martin von Zweigbergk <martinvonz@google.com>
parents: 39528
diff changeset
   150
    if narrowwirepeer.ELLIPSESCAP in pullop.remote.capabilities():
39524
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
   151
        kwargs['known'] = [node.hex(ctx.node()) for ctx in
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
   152
                           repo.set('::%ln', pullop.common)
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
   153
                           if ctx.node() != node.nullid]
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
   154
        if not kwargs['known']:
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
   155
            # Mercurial serializes an empty list as '' and deserializes it as
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
   156
            # [''], so delete it instead to avoid handling the empty string on
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
   157
            # the server.
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
   158
            del kwargs['known']
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   159
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   160
extensions.wrapfunction(exchange,'_pullbundle2extraprepare',
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   161
                        pullbundle2extraprepare)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   162
39734
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
   163
# This is an extension point for filesystems that need to do something other
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
   164
# than just blindly unlink the files. It's not clear what arguments would be
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
   165
# useful, so we're passing in a fair number of them, some of them redundant.
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
   166
def _narrowcleanupwdir(repo, oldincludes, oldexcludes, newincludes, newexcludes,
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
   167
                       oldmatch, newmatch):
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
   168
    for f in repo.dirstate:
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
   169
        if not newmatch(f):
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
   170
            repo.dirstate.drop(f)
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
   171
            repo.wvfs.unlinkpath(f)
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
   172
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   173
def _narrow(ui, repo, remote, commoninc, oldincludes, oldexcludes,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   174
            newincludes, newexcludes, force):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   175
    oldmatch = narrowspec.match(repo.root, oldincludes, oldexcludes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   176
    newmatch = narrowspec.match(repo.root, newincludes, newexcludes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   177
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   178
    # This is essentially doing "hg outgoing" to find all local-only
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   179
    # commits. We will then check that the local-only commits don't
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   180
    # have any changes to files that will be untracked.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   181
    unfi = repo.unfiltered()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   182
    outgoing = discovery.findcommonoutgoing(unfi, remote,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   183
                                            commoninc=commoninc)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   184
    ui.status(_('looking for local changes to affected paths\n'))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   185
    localnodes = []
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   186
    for n in itertools.chain(outgoing.missing, outgoing.excluded):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   187
        if any(oldmatch(f) and not newmatch(f) for f in unfi[n].files()):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   188
            localnodes.append(n)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   189
    revstostrip = unfi.revs('descendants(%ln)', localnodes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   190
    hiddenrevs = repoview.filterrevs(repo, 'visible')
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   191
    visibletostrip = list(repo.changelog.node(r)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   192
                          for r in (revstostrip - hiddenrevs))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   193
    if visibletostrip:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   194
        ui.status(_('The following changeset(s) or their ancestors have '
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   195
                    'local changes not on the remote:\n'))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   196
        maxnodes = 10
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   197
        if ui.verbose or len(visibletostrip) <= maxnodes:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   198
            for n in visibletostrip:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   199
                ui.status('%s\n' % node.short(n))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   200
        else:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   201
            for n in visibletostrip[:maxnodes]:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   202
                ui.status('%s\n' % node.short(n))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   203
            ui.status(_('...and %d more, use --verbose to list all\n') %
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   204
                      (len(visibletostrip) - maxnodes))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   205
        if not force:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   206
            raise error.Abort(_('local changes found'),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   207
                              hint=_('use --force-delete-local-changes to '
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   208
                                     'ignore'))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   209
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   210
    with ui.uninterruptable():
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   211
        if revstostrip:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   212
            tostrip = [unfi.changelog.node(r) for r in revstostrip]
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   213
            if repo['.'].node() in tostrip:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   214
                # stripping working copy, so move to a different commit first
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   215
                urev = max(repo.revs('(::%n) - %ln + null',
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   216
                                     repo['.'].node(), visibletostrip))
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   217
                hg.clean(repo, urev)
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   218
            repair.strip(ui, unfi, tostrip, topic='narrow')
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   219
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   220
        todelete = []
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   221
        for f, f2, size in repo.store.datafiles():
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   222
            if f.startswith('data/'):
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   223
                file = f[5:-2]
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   224
                if not newmatch(file):
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   225
                    todelete.append(f)
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   226
            elif f.startswith('meta/'):
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   227
                dir = f[5:-13]
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   228
                dirs = ['.'] + sorted(util.dirs({dir})) + [dir]
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   229
                include = True
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   230
                for d in dirs:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   231
                    visit = newmatch.visitdir(d)
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   232
                    if not visit:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   233
                        include = False
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   234
                        break
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   235
                    if visit == 'all':
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   236
                        break
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   237
                if not include:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   238
                    todelete.append(f)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   239
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   240
        repo.destroying()
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   241
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   242
        with repo.transaction("narrowing"):
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   243
            for f in todelete:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   244
                ui.status(_('deleting %s\n') % f)
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   245
                util.unlinkpath(repo.svfs.join(f))
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   246
                repo.store.markremoved(f)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   247
39734
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
   248
            _narrowcleanupwdir(repo, oldincludes, oldexcludes, newincludes,
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
   249
                               newexcludes, oldmatch, newmatch)
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   250
            repo.setnarrowpats(newincludes, newexcludes)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   251
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   252
        repo.destroyed()
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   253
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   254
def _widen(ui, repo, remote, commoninc, newincludes, newexcludes):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   255
    newmatch = narrowspec.match(repo.root, newincludes, newexcludes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   256
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   257
    def pullbundle2extraprepare_widen(orig, pullop, kwargs):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   258
        orig(pullop, kwargs)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   259
        # The old{in,ex}cludepats have already been set by orig()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   260
        kwargs['includepats'] = newincludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   261
        kwargs['excludepats'] = newexcludes
39356
c8e4eae84808 narrow: add server logic to send cg while widening without ellipsis
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39247
diff changeset
   262
        kwargs['widen'] = True
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   263
    wrappedextraprepare = extensions.wrappedfunction(exchange,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   264
        '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   265
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   266
    # define a function that narrowbundle2 can call after creating the
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   267
    # backup bundle, but before applying the bundle from the server
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   268
    def setnewnarrowpats():
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   269
        repo.setnarrowpats(newincludes, newexcludes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   270
    repo.setnewnarrowpats = setnewnarrowpats
39673
f1844a10ee19 narrow: don't send the changelog information when widening without ellipses
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39555
diff changeset
   271
    # silence the devel-warning of applying an empty changegroup
f1844a10ee19 narrow: don't send the changelog information when widening without ellipses
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39555
diff changeset
   272
    overrides = {('devel', 'all-warnings'): False}
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   273
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   274
    with ui.uninterruptable():
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   275
        ds = repo.dirstate
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   276
        p1, p2 = ds.p1(), ds.p2()
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   277
        with ds.parentchange():
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   278
            ds.setparents(node.nullid, node.nullid)
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   279
        common = commoninc[0]
39673
f1844a10ee19 narrow: don't send the changelog information when widening without ellipses
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39555
diff changeset
   280
        with wrappedextraprepare, repo.ui.configoverride(overrides, 'widen'):
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   281
            exchange.pull(repo, remote, heads=common)
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   282
        with ds.parentchange():
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   283
            ds.setparents(p1, p2)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   284
39357
2b8adb7ca39a narrow: update the narrowspecs to new ones after pulling when widening
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39356
diff changeset
   285
        repo.setnewnarrowpats()
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   286
        actions = {k: [] for k in 'a am f g cd dc r dm dg m e k p pr'.split()}
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   287
        addgaction = actions['g'].append
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   288
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   289
        mf = repo['.'].manifest().matches(newmatch)
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   290
        for f, fn in mf.iteritems():
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   291
            if f not in repo.dirstate:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   292
                addgaction((f, (mf.flags(f), False),
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   293
                            "add from widened narrow clone"))
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   294
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   295
        merge.applyupdates(repo, actions, wctx=repo[None],
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   296
                           mctx=repo['.'], overwrite=False)
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
   297
        merge.recordupdates(repo, actions, branchmerge=False)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   298
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   299
# TODO(rdamazio): Make new matcher format and update description
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   300
@command('tracked',
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   301
    [('', 'addinclude', [], _('new paths to include')),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   302
     ('', 'removeinclude', [], _('old paths to no longer include')),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   303
     ('', 'addexclude', [], _('new paths to exclude')),
39440
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
   304
     ('', 'import-rules', '', _('import narrowspecs from a file')),
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   305
     ('', 'removeexclude', [], _('old paths to no longer exclude')),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   306
     ('', 'clear', False, _('whether to replace the existing narrowspec')),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   307
     ('', 'force-delete-local-changes', False,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   308
       _('forces deletion of local changes when narrowing')),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   309
    ] + commands.remoteopts,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   310
    _('[OPTIONS]... [REMOTE]'),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   311
    inferrepo=True)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   312
def trackedcmd(ui, repo, remotepath=None, *pats, **opts):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   313
    """show or change the current narrowspec
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   314
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   315
    With no argument, shows the current narrowspec entries, one per line. Each
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   316
    line will be prefixed with 'I' or 'X' for included or excluded patterns,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   317
    respectively.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   318
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   319
    The narrowspec is comprised of expressions to match remote files and/or
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   320
    directories that should be pulled into your client.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   321
    The narrowspec has *include* and *exclude* expressions, with excludes always
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   322
    trumping includes: that is, if a file matches an exclude expression, it will
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   323
    be excluded even if it also matches an include expression.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   324
    Excluding files that were never included has no effect.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   325
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   326
    Each included or excluded entry is in the format described by
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   327
    'hg help patterns'.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   328
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   329
    The options allow you to add or remove included and excluded expressions.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   330
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   331
    If --clear is specified, then all previous includes and excludes are DROPPED
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   332
    and replaced by the new ones specified to --addinclude and --addexclude.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   333
    If --clear is specified without any further options, the narrowspec will be
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   334
    empty and will not match any files.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   335
    """
36166
ccf7ae119769 narrowcommands: more byteskwargs cleanup
Augie Fackler <augie@google.com>
parents: 36160
diff changeset
   336
    opts = pycompat.byteskwargs(opts)
38835
a232e6744ba3 narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents: 38528
diff changeset
   337
    if repository.NARROW_REQUIREMENT not in repo.requirements:
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   338
        ui.warn(_('The narrow command is only supported on respositories cloned'
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   339
                  ' with --narrow.\n'))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   340
        return 1
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   341
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   342
    # Before supporting, decide whether it "hg tracked --clear" should mean
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   343
    # tracking no paths or all paths.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   344
    if opts['clear']:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   345
        ui.warn(_('The --clear option is not yet supported.\n'))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   346
        return 1
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   347
39440
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
   348
    # import rules from a file
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
   349
    newrules = opts.get('import_rules')
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
   350
    if newrules:
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
   351
        try:
39818
24e493ec2229 py3: rename pycompat.getcwd() to encoding.getcwd() (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 39734
diff changeset
   352
            filepath = os.path.join(encoding.getcwd(), newrules)
39440
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
   353
            fdata = util.readfile(filepath)
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
   354
        except IOError as inst:
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
   355
            raise error.Abort(_("cannot read narrowspecs from '%s': %s") %
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
   356
                              (filepath, encoding.strtolocal(inst.strerror)))
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
   357
        includepats, excludepats, profiles = sparse.parseconfig(ui, fdata,
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
   358
                                                                'narrow')
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
   359
        if profiles:
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
   360
            raise error.Abort(_("including other spec files using '%include' "
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
   361
                                "is not supported in narrowspec"))
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
   362
        opts['addinclude'].extend(includepats)
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
   363
        opts['addexclude'].extend(excludepats)
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
   364
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   365
    addedincludes = narrowspec.parsepatterns(opts['addinclude'])
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   366
    removedincludes = narrowspec.parsepatterns(opts['removeinclude'])
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   367
    addedexcludes = narrowspec.parsepatterns(opts['addexclude'])
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   368
    removedexcludes = narrowspec.parsepatterns(opts['removeexclude'])
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   369
    widening = addedincludes or removedexcludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   370
    narrowing = removedincludes or addedexcludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   371
    only_show = not widening and not narrowing
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   372
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   373
    # Only print the current narrowspec.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   374
    if only_show:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   375
        include, exclude = repo.narrowpats
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   376
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   377
        ui.pager('tracked')
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   378
        fm = ui.formatter('narrow', opts)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   379
        for i in sorted(include):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   380
            fm.startitem()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   381
            fm.write('status', '%s ', 'I', label='narrow.included')
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   382
            fm.write('pat', '%s\n', i, label='narrow.included')
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   383
        for i in sorted(exclude):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   384
            fm.startitem()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   385
            fm.write('status', '%s ', 'X', label='narrow.excluded')
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   386
            fm.write('pat', '%s\n', i, label='narrow.excluded')
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   387
        fm.end()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   388
        return 0
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   389
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   390
    with repo.wlock(), repo.lock():
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   391
        cmdutil.bailifchanged(repo)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   392
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   393
        # Find the revisions we have in common with the remote. These will
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   394
        # be used for finding local-only changes for narrowing. They will
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   395
        # also define the set of revisions to update for widening.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   396
        remotepath = ui.expandpath(remotepath or 'default')
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   397
        url, branches = hg.parseurl(remotepath)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   398
        ui.status(_('comparing with %s\n') % util.hidepassword(url))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   399
        remote = hg.peer(repo, opts, url)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   400
        commoninc = discovery.findcommonincoming(repo, remote)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   401
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   402
        oldincludes, oldexcludes = repo.narrowpats
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   403
        if narrowing:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   404
            newincludes = oldincludes - removedincludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   405
            newexcludes = oldexcludes | addedexcludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   406
            _narrow(ui, repo, remote, commoninc, oldincludes, oldexcludes,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   407
                    newincludes, newexcludes,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   408
                    opts['force_delete_local_changes'])
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   409
            # _narrow() updated the narrowspec and _widen() below needs to
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   410
            # use the updated values as its base (otherwise removed includes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   411
            # and addedexcludes will be lost in the resulting narrowspec)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   412
            oldincludes = newincludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   413
            oldexcludes = newexcludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   414
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   415
        if widening:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   416
            newincludes = oldincludes | addedincludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   417
            newexcludes = oldexcludes - removedexcludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   418
            _widen(ui, repo, remote, commoninc, newincludes, newexcludes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   419
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   420
    return 0