hgext/narrow/narrowcommands.py
author Augie Fackler <augie@google.com>
Sat, 05 Oct 2019 10:47:28 -0400
changeset 43061 b61324854e93
parent 42949 40f78072fda9
child 43076 2372284d9457
permissions -rw-r--r--
contrib: allow trailing commas in lists black manages this for us, so we don't need to worry about this anymore. Differential Revision: https://phab.mercurial-scm.org/D6977
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36117
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
39275
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38874
diff changeset
    10
import os
36117
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 (
40071
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39966
diff changeset
    14
    bundle2,
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    15
    cmdutil,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    16
    commands,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    17
    discovery,
39459
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39384
diff changeset
    18
    encoding,
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
    error,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    20
    exchange,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    21
    extensions,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
    hg,
36198
9fd8c2a3db5a narrowspec: move module into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36192
diff changeset
    23
    narrowspec,
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
    node,
36192
4a7ba3ac9163 narrowcommands: use pycompat.{bytes,str}kwargs
Augie Fackler <augie@google.com>
parents: 36138
diff changeset
    25
    pycompat,
36117
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,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    28
    repoview,
39275
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38874
diff changeset
    29
    sparse,
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    30
    util,
40075
f7011b44d205 wireprotoserver: move narrow capabilities to wireprototypes.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40071
diff changeset
    31
    wireprototypes,
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    32
)
42823
268662aac075 interfaces: create a new folder for interfaces and move repository.py in it
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42822
diff changeset
    33
from mercurial.interfaces import (
268662aac075 interfaces: create a new folder for interfaces and move repository.py in it
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42822
diff changeset
    34
    repository,
268662aac075 interfaces: create a new folder for interfaces and move repository.py in it
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42822
diff changeset
    35
)
36117
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
table = {}
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    38
command = registrar.command(table)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    39
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    40
def setup():
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    41
    """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
    42
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    43
    entry = extensions.wrapcommand(commands.table, 'clone', clonenarrowcmd)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    44
    entry[1].append(('', 'narrow', None,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    45
                     _("create a narrow clone of select files")))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    46
    entry[1].append(('', 'depth', '',
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    47
                     _("limit the history fetched by distance from heads")))
39275
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38874
diff changeset
    48
    entry[1].append(('', 'narrowspec', '',
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38874
diff changeset
    49
                     _("read narrowspecs from file")))
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    50
    # 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
    51
    if 'sparse' not in extensions.enabled():
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    52
        entry[1].append(('', 'include', [],
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    53
                         _("specifically fetch this file/directory")))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    54
        entry[1].append(
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    55
            ('', 'exclude', [],
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    56
             _("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
    57
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    58
    entry = extensions.wrapcommand(commands.table, 'pull', pullnarrowcmd)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    59
    entry[1].append(('', 'depth', '',
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    60
                     _("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
    61
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    62
    extensions.wrapcommand(commands.table, 'archive', archivenarrowcmd)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    63
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    64
def clonenarrowcmd(orig, ui, repo, *args, **opts):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    65
    """Wraps clone command, so 'hg clone' first wraps localrepo.clone()."""
36192
4a7ba3ac9163 narrowcommands: use pycompat.{bytes,str}kwargs
Augie Fackler <augie@google.com>
parents: 36138
diff changeset
    66
    opts = pycompat.byteskwargs(opts)
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    67
    wrappedextraprepare = util.nullcontextmanager()
39275
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38874
diff changeset
    68
    narrowspecfile = opts['narrowspec']
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38874
diff changeset
    69
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38874
diff changeset
    70
    if narrowspecfile:
39823
24e493ec2229 py3: rename pycompat.getcwd() to encoding.getcwd() (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 39750
diff changeset
    71
        filepath = os.path.join(encoding.getcwd(), narrowspecfile)
39275
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38874
diff changeset
    72
        ui.status(_("reading narrowspec from '%s'\n") % filepath)
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38874
diff changeset
    73
        try:
39482
4062bbb1d10f narrow: use util.readfile() and improve error message using --narrowspec
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39459
diff changeset
    74
            fdata = util.readfile(filepath)
4062bbb1d10f narrow: use util.readfile() and improve error message using --narrowspec
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39459
diff changeset
    75
        except IOError as inst:
4062bbb1d10f narrow: use util.readfile() and improve error message using --narrowspec
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39459
diff changeset
    76
            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: 39459
diff changeset
    77
                              (filepath, encoding.strtolocal(inst.strerror)))
39275
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38874
diff changeset
    78
39482
4062bbb1d10f narrow: use util.readfile() and improve error message using --narrowspec
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39459
diff changeset
    79
        includes, excludes, profiles = sparse.parseconfig(ui, fdata, 'narrow')
39275
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38874
diff changeset
    80
        if profiles:
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38874
diff changeset
    81
            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: 38874
diff changeset
    82
                                " narrowspec"))
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38874
diff changeset
    83
39558
8301741e1f89 narrow: validate spec files are well-formed during clone (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
    84
        narrowspec.validatepatterns(includes)
8301741e1f89 narrow: validate spec files are well-formed during clone (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
    85
        narrowspec.validatepatterns(excludes)
8301741e1f89 narrow: validate spec files are well-formed during clone (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39549
diff changeset
    86
39275
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38874
diff changeset
    87
        # narrowspec is passed so we should assume that user wants narrow clone
39562
4afd2af36456 narrow: set opts['narrow'] instead of local variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39561
diff changeset
    88
        opts['narrow'] = True
39275
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38874
diff changeset
    89
        opts['include'].extend(includes)
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38874
diff changeset
    90
        opts['exclude'].extend(excludes)
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38874
diff changeset
    91
39562
4afd2af36456 narrow: set opts['narrow'] instead of local variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39561
diff changeset
    92
    if opts['narrow']:
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    93
        def pullbundle2extraprepare_widen(orig, pullop, kwargs):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    94
            orig(pullop, kwargs)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    95
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    96
            if opts.get('depth'):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    97
                kwargs['depth'] = opts['depth']
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    98
        wrappedextraprepare = extensions.wrappedfunction(exchange,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    99
            '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   100
39570
841c82d1a973 narrow: don't wrap exchange.pull() during clone
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39562
diff changeset
   101
    with wrappedextraprepare:
36192
4a7ba3ac9163 narrowcommands: use pycompat.{bytes,str}kwargs
Augie Fackler <augie@google.com>
parents: 36138
diff changeset
   102
        return orig(ui, repo, *args, **pycompat.strkwargs(opts))
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   103
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   104
def pullnarrowcmd(orig, ui, repo, *args, **opts):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   105
    """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
   106
    wrappedextraprepare = util.nullcontextmanager()
38874
a232e6744ba3 narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents: 38530
diff changeset
   107
    if repository.NARROW_REQUIREMENT in repo.requirements:
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   108
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   109
        def pullbundle2extraprepare_widen(orig, pullop, kwargs):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   110
            orig(pullop, kwargs)
36486
9ff5cbfbc26a py3: fix more keyword arguments handling
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36385
diff changeset
   111
            if opts.get(r'depth'):
9ff5cbfbc26a py3: fix more keyword arguments handling
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36385
diff changeset
   112
                kwargs['depth'] = opts[r'depth']
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   113
        wrappedextraprepare = extensions.wrappedfunction(exchange,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   114
            '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   115
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   116
    with wrappedextraprepare:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   117
        return orig(ui, repo, *args, **opts)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   118
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   119
def archivenarrowcmd(orig, ui, repo, *args, **opts):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   120
    """Wraps archive command to narrow the default includes."""
38874
a232e6744ba3 narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents: 38530
diff changeset
   121
    if repository.NARROW_REQUIREMENT in repo.requirements:
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   122
        repo_includes, repo_excludes = repo.narrowpats
36385
5dbeddbf164a narrowcommands: add some missing strkwargs calls for py3
Augie Fackler <augie@google.com>
parents: 36204
diff changeset
   123
        includes = set(opts.get(r'include', []))
5dbeddbf164a narrowcommands: add some missing strkwargs calls for py3
Augie Fackler <augie@google.com>
parents: 36204
diff changeset
   124
        excludes = set(opts.get(r'exclude', []))
36138
8fd0a9e2d7e9 narrow: make restrictpatterns a little more idiomatic
Augie Fackler <augie@google.com>
parents: 36126
diff changeset
   125
        includes, excludes, unused_invalid = narrowspec.restrictpatterns(
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   126
            includes, excludes, repo_includes, repo_excludes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   127
        if includes:
36385
5dbeddbf164a narrowcommands: add some missing strkwargs calls for py3
Augie Fackler <augie@google.com>
parents: 36204
diff changeset
   128
            opts[r'include'] = includes
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   129
        if excludes:
36385
5dbeddbf164a narrowcommands: add some missing strkwargs calls for py3
Augie Fackler <augie@google.com>
parents: 36204
diff changeset
   130
            opts[r'exclude'] = excludes
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   131
    return orig(ui, repo, *args, **opts)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   132
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   133
def pullbundle2extraprepare(orig, pullop, kwargs):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   134
    repo = pullop.repo
38874
a232e6744ba3 narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents: 38530
diff changeset
   135
    if repository.NARROW_REQUIREMENT not in repo.requirements:
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   136
        return orig(pullop, kwargs)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   137
40075
f7011b44d205 wireprotoserver: move narrow capabilities to wireprototypes.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40071
diff changeset
   138
    if wireprototypes.NARROWCAP not in pullop.remote.capabilities():
39965
06e75fbf9d6b narrow: check for servers' narrow support before doing anything (BC)
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39964
diff changeset
   139
        raise error.Abort(_("server does not support narrow clones"))
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   140
    orig(pullop, kwargs)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   141
    kwargs['narrow'] = True
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   142
    include, exclude = repo.narrowpats
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   143
    kwargs['oldincludepats'] = include
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   144
    kwargs['oldexcludepats'] = exclude
40543
a2c4502e409b narrow: only send includepats and excludepats if they are not empty
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40503
diff changeset
   145
    if include:
a2c4502e409b narrow: only send includepats and excludepats if they are not empty
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40503
diff changeset
   146
        kwargs['includepats'] = include
a2c4502e409b narrow: only send includepats and excludepats if they are not empty
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40503
diff changeset
   147
    if exclude:
a2c4502e409b narrow: only send includepats and excludepats if they are not empty
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40503
diff changeset
   148
        kwargs['excludepats'] = exclude
39541
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39482
diff changeset
   149
    # 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: 39482
diff changeset
   150
    # we have all the nodes
42432
c767e655ffda narrow: use narrow_widen wireproto command to widen in case of ellipses
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42367
diff changeset
   151
    if wireprototypes.ELLIPSESCAP1 in pullop.remote.capabilities():
39541
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39482
diff changeset
   152
        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: 39482
diff changeset
   153
                           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: 39482
diff changeset
   154
                           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: 39482
diff changeset
   155
        if not kwargs['known']:
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39482
diff changeset
   156
            # 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: 39482
diff changeset
   157
            # [''], 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: 39482
diff changeset
   158
            # the server.
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39482
diff changeset
   159
            del kwargs['known']
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   160
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   161
extensions.wrapfunction(exchange,'_pullbundle2extraprepare',
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   162
                        pullbundle2extraprepare)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   163
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   164
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
   165
            newincludes, newexcludes, force):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   166
    oldmatch = narrowspec.match(repo.root, oldincludes, oldexcludes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   167
    newmatch = narrowspec.match(repo.root, newincludes, newexcludes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   168
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   169
    # 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
   170
    # 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
   171
    # 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
   172
    unfi = repo.unfiltered()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   173
    outgoing = discovery.findcommonoutgoing(unfi, remote,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   174
                                            commoninc=commoninc)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   175
    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
   176
    localnodes = []
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   177
    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
   178
        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
   179
            localnodes.append(n)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   180
    revstostrip = unfi.revs('descendants(%ln)', localnodes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   181
    hiddenrevs = repoview.filterrevs(repo, 'visible')
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   182
    visibletostrip = list(repo.changelog.node(r)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   183
                          for r in (revstostrip - hiddenrevs))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   184
    if visibletostrip:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   185
        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
   186
                    'local changes not on the remote:\n'))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   187
        maxnodes = 10
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   188
        if ui.verbose or len(visibletostrip) <= maxnodes:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   189
            for n in visibletostrip:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   190
                ui.status('%s\n' % node.short(n))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   191
        else:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   192
            for n in visibletostrip[:maxnodes]:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   193
                ui.status('%s\n' % node.short(n))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   194
            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
   195
                      (len(visibletostrip) - maxnodes))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   196
        if not force:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   197
            raise error.Abort(_('local changes found'),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   198
                              hint=_('use --force-delete-local-changes to '
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   199
                                     'ignore'))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   200
41079
8ecb17b7f432 procutil: correct spelling of uninterruptable -> uninterruptible
Kyle Lippincott <spectral@google.com>
parents: 41046
diff changeset
   201
    with ui.uninterruptible():
38530
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   202
        if revstostrip:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   203
            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: 36499
diff changeset
   204
            if repo['.'].node() in tostrip:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   205
                # 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: 36499
diff changeset
   206
                urev = max(repo.revs('(::%n) - %ln + null',
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   207
                                     repo['.'].node(), visibletostrip))
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   208
                hg.clean(repo, urev)
40847
77173267878b narrow: don't resurrect old commits when narrowing (don't strip obsmarkers)
Martin von Zweigbergk <martinvonz@google.com>
parents: 40800
diff changeset
   209
            overrides = {('devel', 'strip-obsmarkers'): False}
77173267878b narrow: don't resurrect old commits when narrowing (don't strip obsmarkers)
Martin von Zweigbergk <martinvonz@google.com>
parents: 40800
diff changeset
   210
            with ui.configoverride(overrides, 'narrow'):
77173267878b narrow: don't resurrect old commits when narrowing (don't strip obsmarkers)
Martin von Zweigbergk <martinvonz@google.com>
parents: 40800
diff changeset
   211
                repair.strip(ui, unfi, tostrip, topic='narrow')
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   212
38530
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   213
        todelete = []
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   214
        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: 36499
diff changeset
   215
            if f.startswith('data/'):
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   216
                file = f[5:-2]
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   217
                if not newmatch(file):
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   218
                    todelete.append(f)
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   219
            elif f.startswith('meta/'):
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   220
                dir = f[5:-13]
42367
7d4ee14ff92d narrowcommands: drop unnecessary adding of '' for root directory
Martin von Zweigbergk <martinvonz@google.com>
parents: 42363
diff changeset
   221
                dirs = sorted(util.dirs({dir})) + [dir]
38530
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   222
                include = True
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   223
                for d in dirs:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   224
                    visit = newmatch.visitdir(d)
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   225
                    if not visit:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   226
                        include = False
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   227
                        break
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   228
                    if visit == 'all':
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   229
                        break
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   230
                if not include:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   231
                    todelete.append(f)
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   232
38530
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   233
        repo.destroying()
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   234
41238
8c366af085f4 narrow: reuse narrowspec.updateworkingcopy() when narrowing
Martin von Zweigbergk <martinvonz@google.com>
parents: 41237
diff changeset
   235
        with repo.transaction('narrowing'):
41031
095a0a63ad88 narrow: when narrowing, write new narrowspec before removing revlogs
Martin von Zweigbergk <martinvonz@google.com>
parents: 41030
diff changeset
   236
            # Update narrowspec before removing revlogs, so repo won't be
095a0a63ad88 narrow: when narrowing, write new narrowspec before removing revlogs
Martin von Zweigbergk <martinvonz@google.com>
parents: 41030
diff changeset
   237
            # corrupt in case of crash
095a0a63ad88 narrow: when narrowing, write new narrowspec before removing revlogs
Martin von Zweigbergk <martinvonz@google.com>
parents: 41030
diff changeset
   238
            repo.setnarrowpats(newincludes, newexcludes)
095a0a63ad88 narrow: when narrowing, write new narrowspec before removing revlogs
Martin von Zweigbergk <martinvonz@google.com>
parents: 41030
diff changeset
   239
38530
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   240
            for f in todelete:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   241
                ui.status(_('deleting %s\n') % f)
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   242
                util.unlinkpath(repo.svfs.join(f))
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   243
                repo.store.markremoved(f)
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   244
41238
8c366af085f4 narrow: reuse narrowspec.updateworkingcopy() when narrowing
Martin von Zweigbergk <martinvonz@google.com>
parents: 41237
diff changeset
   245
            narrowspec.updateworkingcopy(repo, assumeclean=True)
8c366af085f4 narrow: reuse narrowspec.updateworkingcopy() when narrowing
Martin von Zweigbergk <martinvonz@google.com>
parents: 41237
diff changeset
   246
            narrowspec.copytoworkingcopy(repo)
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   247
38530
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36499
diff changeset
   248
        repo.destroyed()
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   249
39966
1a4c1a3cc3f5 narrow: pass old includes and excludes to _widen()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
   250
def _widen(ui, repo, remote, commoninc, oldincludes, oldexcludes,
1a4c1a3cc3f5 narrow: pass old includes and excludes to _widen()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
   251
           newincludes, newexcludes):
39964
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39939
diff changeset
   252
    # for now we assume that if a server has ellipses enabled, we will be
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39939
diff changeset
   253
    # exchanging ellipses nodes. In future we should add ellipses as a client
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39939
diff changeset
   254
    # side requirement (maybe) to distinguish a client is shallow or not and
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39939
diff changeset
   255
    # then send that information to server whether we want ellipses or not.
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39939
diff changeset
   256
    # Theoretically a non-ellipses repo should be able to use narrow
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39939
diff changeset
   257
    # functionality from an ellipses enabled server
42432
c767e655ffda narrow: use narrow_widen wireproto command to widen in case of ellipses
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42367
diff changeset
   258
    remotecap = remote.capabilities()
c767e655ffda narrow: use narrow_widen wireproto command to widen in case of ellipses
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42367
diff changeset
   259
    ellipsesremote = any(cap in remotecap
c767e655ffda narrow: use narrow_widen wireproto command to widen in case of ellipses
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42367
diff changeset
   260
                         for cap in wireprototypes.SUPPORTED_ELLIPSESCAP)
c767e655ffda narrow: use narrow_widen wireproto command to widen in case of ellipses
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42367
diff changeset
   261
c767e655ffda narrow: use narrow_widen wireproto command to widen in case of ellipses
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42367
diff changeset
   262
    # check whether we are talking to a server which supports old version of
c767e655ffda narrow: use narrow_widen wireproto command to widen in case of ellipses
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42367
diff changeset
   263
    # ellipses capabilities
c767e655ffda narrow: use narrow_widen wireproto command to widen in case of ellipses
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42367
diff changeset
   264
    isoldellipses = (ellipsesremote and wireprototypes.ELLIPSESCAP1 in
c767e655ffda narrow: use narrow_widen wireproto command to widen in case of ellipses
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42367
diff changeset
   265
                     remotecap and wireprototypes.ELLIPSESCAP not in remotecap)
39964
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39939
diff changeset
   266
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   267
    def pullbundle2extraprepare_widen(orig, pullop, kwargs):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   268
        orig(pullop, kwargs)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   269
        # 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
   270
        kwargs['includepats'] = newincludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   271
        kwargs['excludepats'] = newexcludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   272
    wrappedextraprepare = extensions.wrappedfunction(exchange,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   273
        '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   274
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   275
    # 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
   276
    # 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
   277
    def setnewnarrowpats():
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   278
        repo.setnarrowpats(newincludes, newexcludes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   279
    repo.setnewnarrowpats = setnewnarrowpats
39689
f1844a10ee19 narrow: don't send the changelog information when widening without ellipses
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39571
diff changeset
   280
    # 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: 39571
diff changeset
   281
    overrides = {('devel', 'all-warnings'): False}
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   282
42433
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   283
    common = commoninc[0]
41079
8ecb17b7f432 procutil: correct spelling of uninterruptable -> uninterruptible
Kyle Lippincott <spectral@google.com>
parents: 41046
diff changeset
   284
    with ui.uninterruptible():
39964
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39939
diff changeset
   285
        if ellipsesremote:
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39939
diff changeset
   286
            ds = repo.dirstate
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39939
diff changeset
   287
            p1, p2 = ds.p1(), ds.p2()
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39939
diff changeset
   288
            with ds.parentchange():
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39939
diff changeset
   289
                ds.setparents(node.nullid, node.nullid)
42433
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   290
        if isoldellipses:
41769
1eb2fc21da12 cleanup: prefer nested context managers to \-continuations
Augie Fackler <augie@google.com>
parents: 41734
diff changeset
   291
            with wrappedextraprepare:
42433
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   292
                exchange.pull(repo, remote, heads=common)
39964
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39939
diff changeset
   293
        else:
42433
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   294
            known = []
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   295
            if ellipsesremote:
42948
c2676b5a9f59 narrow: don't hexify paths and double-hexify known nodes on wire (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 42823
diff changeset
   296
                known = [ctx.node() for ctx in
42433
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   297
                         repo.set('::%ln', common)
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   298
                         if ctx.node() != node.nullid]
40071
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39966
diff changeset
   299
            with remote.commandexecutor() as e:
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39966
diff changeset
   300
                bundle = e.callcommand('narrow_widen', {
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39966
diff changeset
   301
                    'oldincludes': oldincludes,
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39966
diff changeset
   302
                    'oldexcludes': oldexcludes,
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39966
diff changeset
   303
                    'newincludes': newincludes,
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39966
diff changeset
   304
                    'newexcludes': newexcludes,
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39966
diff changeset
   305
                    'cgversion': '03',
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39966
diff changeset
   306
                    'commonheads': common,
42433
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   307
                    'known': known,
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   308
                    'ellipses': ellipsesremote,
40071
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39966
diff changeset
   309
                }).result()
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39966
diff changeset
   310
42433
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   311
            trmanager = exchange.transactionmanager(repo, 'widen', remote.url())
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   312
            with trmanager, repo.ui.configoverride(overrides, 'widen'):
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   313
                op = bundle2.bundleoperation(repo, trmanager.transaction,
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   314
                                             source='widen')
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   315
                # TODO: we should catch error.Abort here
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   316
                bundle2.processbundle(repo, bundle, op=op)
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   317
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   318
        if ellipsesremote:
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   319
            with ds.parentchange():
8381b7067f17 narrow: refactor code around widening complicated by previous patch
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42432
diff changeset
   320
                ds.setparents(p1, p2)
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   321
41237
ad9ab2523149 narrow: reuse narrowspec.updateworkingcopy() when widening
Martin von Zweigbergk <martinvonz@google.com>
parents: 41236
diff changeset
   322
        with repo.transaction('widening'):
ad9ab2523149 narrow: reuse narrowspec.updateworkingcopy() when widening
Martin von Zweigbergk <martinvonz@google.com>
parents: 41236
diff changeset
   323
            repo.setnewnarrowpats()
ad9ab2523149 narrow: reuse narrowspec.updateworkingcopy() when widening
Martin von Zweigbergk <martinvonz@google.com>
parents: 41236
diff changeset
   324
            narrowspec.updateworkingcopy(repo)
ad9ab2523149 narrow: reuse narrowspec.updateworkingcopy() when widening
Martin von Zweigbergk <martinvonz@google.com>
parents: 41236
diff changeset
   325
            narrowspec.copytoworkingcopy(repo)
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   326
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   327
# 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
   328
@command('tracked',
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   329
    [('', 'addinclude', [], _('new paths to include')),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   330
     ('', 'removeinclude', [], _('old paths to no longer include')),
42949
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   331
     ('', 'auto-remove-includes', False,
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   332
      _('automatically choose unused includes to remove')),
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   333
     ('', 'addexclude', [], _('new paths to exclude')),
39459
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39384
diff changeset
   334
     ('', 'import-rules', '', _('import narrowspecs from a file')),
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   335
     ('', 'removeexclude', [], _('old paths to no longer exclude')),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   336
     ('', '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
   337
     ('', 'force-delete-local-changes', False,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   338
       _('forces deletion of local changes when narrowing')),
41046
ce0bc2952e2a narrow: detect if narrowspec was changed in a different share
Martin von Zweigbergk <martinvonz@google.com>
parents: 41042
diff changeset
   339
     ('', 'update-working-copy', False,
ce0bc2952e2a narrow: detect if narrowspec was changed in a different share
Martin von Zweigbergk <martinvonz@google.com>
parents: 41042
diff changeset
   340
      _('update working copy when the store has changed')),
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   341
    ] + commands.remoteopts,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   342
    _('[OPTIONS]... [REMOTE]'),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   343
    inferrepo=True)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   344
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
   345
    """show or change the current narrowspec
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   346
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   347
    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
   348
    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
   349
    respectively.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   350
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   351
    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
   352
    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
   353
    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
   354
    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
   355
    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
   356
    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
   357
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   358
    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
   359
    'hg help patterns'.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   360
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   361
    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
   362
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   363
    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
   364
    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
   365
    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
   366
    empty and will not match any files.
41982
6cad258e1348 tracked: add documentation about `--import-rules` flag
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41769
diff changeset
   367
42949
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   368
    If --auto-remove-includes is specified, then those includes that don't match
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   369
    any files modified by currently visible local commits (those not shared by
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   370
    the remote) will be added to the set of explicitly specified includes to
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   371
    remove.
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   372
41982
6cad258e1348 tracked: add documentation about `--import-rules` flag
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41769
diff changeset
   373
    --import-rules accepts a path to a file containing rules, allowing you to
6cad258e1348 tracked: add documentation about `--import-rules` flag
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41769
diff changeset
   374
    add --addinclude, --addexclude rules in bulk. Like the other include and
6cad258e1348 tracked: add documentation about `--import-rules` flag
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41769
diff changeset
   375
    exclude switches, the changes are applied immediately.
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   376
    """
36204
ccf7ae119769 narrowcommands: more byteskwargs cleanup
Augie Fackler <augie@google.com>
parents: 36198
diff changeset
   377
    opts = pycompat.byteskwargs(opts)
38874
a232e6744ba3 narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents: 38530
diff changeset
   378
    if repository.NARROW_REQUIREMENT not in repo.requirements:
41734
ebbc4e70ebd1 narrow: fix command name in error messsage
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41238
diff changeset
   379
        raise error.Abort(_('the tracked command is only supported on '
42822
383fdfa6bba9 narrow: fix typo "respositories"
Martin von Zweigbergk <martinvonz@google.com>
parents: 42433
diff changeset
   380
                            'repositories cloned with --narrow'))
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   381
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   382
    # 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
   383
    # tracking no paths or all paths.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   384
    if opts['clear']:
41030
74e023f5a922 narrow: replace "ui.warn(); return 1" by "raise error.Abort()"
Martin von Zweigbergk <martinvonz@google.com>
parents: 40847
diff changeset
   385
        raise error.Abort(_('the --clear option is not yet supported'))
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   386
39459
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39384
diff changeset
   387
    # import rules from a file
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39384
diff changeset
   388
    newrules = opts.get('import_rules')
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39384
diff changeset
   389
    if newrules:
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39384
diff changeset
   390
        try:
39823
24e493ec2229 py3: rename pycompat.getcwd() to encoding.getcwd() (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 39750
diff changeset
   391
            filepath = os.path.join(encoding.getcwd(), newrules)
39459
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39384
diff changeset
   392
            fdata = util.readfile(filepath)
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39384
diff changeset
   393
        except IOError as inst:
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39384
diff changeset
   394
            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: 39384
diff changeset
   395
                              (filepath, encoding.strtolocal(inst.strerror)))
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39384
diff changeset
   396
        includepats, excludepats, profiles = sparse.parseconfig(ui, fdata,
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39384
diff changeset
   397
                                                                'narrow')
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39384
diff changeset
   398
        if profiles:
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39384
diff changeset
   399
            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: 39384
diff changeset
   400
                                "is not supported in narrowspec"))
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39384
diff changeset
   401
        opts['addinclude'].extend(includepats)
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39384
diff changeset
   402
        opts['addexclude'].extend(excludepats)
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39384
diff changeset
   403
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   404
    addedincludes = narrowspec.parsepatterns(opts['addinclude'])
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   405
    removedincludes = narrowspec.parsepatterns(opts['removeinclude'])
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   406
    addedexcludes = narrowspec.parsepatterns(opts['addexclude'])
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   407
    removedexcludes = narrowspec.parsepatterns(opts['removeexclude'])
42949
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   408
    autoremoveincludes = opts['auto_remove_includes']
40501
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40075
diff changeset
   409
41046
ce0bc2952e2a narrow: detect if narrowspec was changed in a different share
Martin von Zweigbergk <martinvonz@google.com>
parents: 41042
diff changeset
   410
    update_working_copy = opts['update_working_copy']
40501
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40075
diff changeset
   411
    only_show = not (addedincludes or removedincludes or addedexcludes or
42949
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   412
                     removedexcludes or newrules or autoremoveincludes or
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   413
                     update_working_copy)
40501
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40075
diff changeset
   414
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40075
diff changeset
   415
    oldincludes, oldexcludes = repo.narrowpats
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40075
diff changeset
   416
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40075
diff changeset
   417
    # filter the user passed additions and deletions into actual additions and
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40075
diff changeset
   418
    # deletions of excludes and includes
40503
5d8f291405e5 narrow: replace filtering in list comprehension by set operations
Martin von Zweigbergk <martinvonz@google.com>
parents: 40501
diff changeset
   419
    addedincludes -= oldincludes
5d8f291405e5 narrow: replace filtering in list comprehension by set operations
Martin von Zweigbergk <martinvonz@google.com>
parents: 40501
diff changeset
   420
    removedincludes &= oldincludes
5d8f291405e5 narrow: replace filtering in list comprehension by set operations
Martin von Zweigbergk <martinvonz@google.com>
parents: 40501
diff changeset
   421
    addedexcludes -= oldexcludes
5d8f291405e5 narrow: replace filtering in list comprehension by set operations
Martin von Zweigbergk <martinvonz@google.com>
parents: 40501
diff changeset
   422
    removedexcludes &= oldexcludes
40501
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40075
diff changeset
   423
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   424
    widening = addedincludes or removedexcludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   425
    narrowing = removedincludes or addedexcludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   426
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   427
    # Only print the current narrowspec.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   428
    if only_show:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   429
        ui.pager('tracked')
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   430
        fm = ui.formatter('narrow', opts)
40800
773572e5cba2 narrowcommands: remove an unrequired `repo.narrowpats` call
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40543
diff changeset
   431
        for i in sorted(oldincludes):
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   432
            fm.startitem()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   433
            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
   434
            fm.write('pat', '%s\n', i, label='narrow.included')
40800
773572e5cba2 narrowcommands: remove an unrequired `repo.narrowpats` call
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40543
diff changeset
   435
        for i in sorted(oldexcludes):
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   436
            fm.startitem()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   437
            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
   438
            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
   439
        fm.end()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   440
        return 0
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   441
41046
ce0bc2952e2a narrow: detect if narrowspec was changed in a different share
Martin von Zweigbergk <martinvonz@google.com>
parents: 41042
diff changeset
   442
    if update_working_copy:
41229
50ca531f1f24 narrow: copy store narrowspec to working copy immediately
Martin von Zweigbergk <martinvonz@google.com>
parents: 41176
diff changeset
   443
        with repo.wlock(), repo.lock(), repo.transaction('narrow-wc'):
41176
4475322b7533 narrow: drop explicit dirstate write
Martin von Zweigbergk <martinvonz@google.com>
parents: 41079
diff changeset
   444
            narrowspec.updateworkingcopy(repo)
41229
50ca531f1f24 narrow: copy store narrowspec to working copy immediately
Martin von Zweigbergk <martinvonz@google.com>
parents: 41176
diff changeset
   445
            narrowspec.copytoworkingcopy(repo)
41046
ce0bc2952e2a narrow: detect if narrowspec was changed in a different share
Martin von Zweigbergk <martinvonz@google.com>
parents: 41042
diff changeset
   446
        return 0
ce0bc2952e2a narrow: detect if narrowspec was changed in a different share
Martin von Zweigbergk <martinvonz@google.com>
parents: 41042
diff changeset
   447
42949
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   448
    if not (widening or narrowing or autoremoveincludes):
40501
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40075
diff changeset
   449
        ui.status(_("nothing to widen or narrow\n"))
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40075
diff changeset
   450
        return 0
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40075
diff changeset
   451
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   452
    with repo.wlock(), repo.lock():
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   453
        cmdutil.bailifchanged(repo)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   454
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   455
        # 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
   456
        # 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
   457
        # 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
   458
        remotepath = ui.expandpath(remotepath or 'default')
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   459
        url, branches = hg.parseurl(remotepath)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   460
        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
   461
        remote = hg.peer(repo, opts, url)
39965
06e75fbf9d6b narrow: check for servers' narrow support before doing anything (BC)
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39964
diff changeset
   462
06e75fbf9d6b narrow: check for servers' narrow support before doing anything (BC)
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39964
diff changeset
   463
        # check narrow support before doing anything if widening needs to be
06e75fbf9d6b narrow: check for servers' narrow support before doing anything (BC)
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39964
diff changeset
   464
        # performed. In future we should also abort if client is ellipses and
06e75fbf9d6b narrow: check for servers' narrow support before doing anything (BC)
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39964
diff changeset
   465
        # server does not support ellipses
40075
f7011b44d205 wireprotoserver: move narrow capabilities to wireprototypes.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40071
diff changeset
   466
        if widening and wireprototypes.NARROWCAP not in remote.capabilities():
39965
06e75fbf9d6b narrow: check for servers' narrow support before doing anything (BC)
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39964
diff changeset
   467
            raise error.Abort(_("server does not support narrow clones"))
06e75fbf9d6b narrow: check for servers' narrow support before doing anything (BC)
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39964
diff changeset
   468
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   469
        commoninc = discovery.findcommonincoming(repo, remote)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   470
42949
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   471
        if autoremoveincludes:
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   472
            outgoing = discovery.findcommonoutgoing(repo, remote,
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   473
                                                    commoninc=commoninc)
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   474
            ui.status(_('looking for unused includes to remove\n'))
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   475
            localfiles = set()
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   476
            for n in itertools.chain(outgoing.missing, outgoing.excluded):
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   477
                localfiles.update(repo[n].files())
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   478
            suggestedremovals = []
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   479
            for include in sorted(oldincludes):
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   480
                match = narrowspec.match(repo.root, [include], oldexcludes)
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   481
                if not any(match(f) for f in localfiles):
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   482
                    suggestedremovals.append(include)
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   483
            if suggestedremovals:
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   484
                for s in suggestedremovals:
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   485
                    ui.status('%s\n' % s)
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   486
                if (ui.promptchoice(_('remove these unused includes (yn)?'
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   487
                                      '$$ &Yes $$ &No')) == 0):
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   488
                    removedincludes.update(suggestedremovals)
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   489
                    narrowing = True
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   490
            else:
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   491
                ui.status(_('found no unused includes\n'))
40f78072fda9 narrow: add option for automatically removing unused includes
Martin von Zweigbergk <martinvonz@google.com>
parents: 42948
diff changeset
   492
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   493
        if narrowing:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   494
            newincludes = oldincludes - removedincludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   495
            newexcludes = oldexcludes | addedexcludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   496
            _narrow(ui, repo, remote, commoninc, oldincludes, oldexcludes,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   497
                    newincludes, newexcludes,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   498
                    opts['force_delete_local_changes'])
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   499
            # _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
   500
            # 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
   501
            # 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
   502
            oldincludes = newincludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   503
            oldexcludes = newexcludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   504
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   505
        if widening:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   506
            newincludes = oldincludes | addedincludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   507
            newexcludes = oldexcludes - removedexcludes
39966
1a4c1a3cc3f5 narrow: pass old includes and excludes to _widen()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
   508
            _widen(ui, repo, remote, commoninc, oldincludes, oldexcludes,
1a4c1a3cc3f5 narrow: pass old includes and excludes to _widen()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
   509
                    newincludes, newexcludes)
36117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   510
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
   511
    return 0