annotate hgext/narrow/narrowcommands.py @ 41042:7db1619af061

tests: add test for narrow+share For how narrow+share is supposed to work, see https://www.mercurial-scm.org/wiki/NarrowSharePlan. Differential Revision: https://phab.mercurial-scm.org/D5276
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 13 Jul 2018 11:26:46 -0700
parents 54c3b4bd01f2
children ce0bc2952e2a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
1 # narrowcommands.py - command modifications for narrowhg extension
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
2 #
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
3 # Copyright 2017 Google, Inc.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
4 #
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
7 from __future__ import absolute_import
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
8
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
9 import itertools
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
10 import os
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
11
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
12 from mercurial.i18n import _
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
13 from mercurial import (
40070
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
14 bundle2,
36079
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,
39440
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
18 encoding,
36079
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,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
23 merge,
36160
9fd8c2a3db5a narrowspec: move module into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36154
diff changeset
24 narrowspec,
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
25 node,
36154
4a7ba3ac9163 narrowcommands: use pycompat.{bytes,str}kwargs
Augie Fackler <augie@google.com>
parents: 36100
diff changeset
26 pycompat,
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
27 registrar,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
28 repair,
38835
a232e6744ba3 narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents: 38528
diff changeset
29 repository,
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
30 repoview,
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
31 sparse,
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
32 util,
40074
f7011b44d205 wireprotoserver: move narrow capabilities to wireprototypes.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40070
diff changeset
33 wireprototypes,
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
34 )
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
35
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
36 table = {}
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
37 command = registrar.command(table)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
38
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
39 def setup():
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
40 """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
41
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
42 entry = extensions.wrapcommand(commands.table, 'clone', clonenarrowcmd)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
43 entry[1].append(('', 'narrow', None,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
44 _("create a narrow clone of select files")))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
45 entry[1].append(('', 'depth', '',
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
46 _("limit the history fetched by distance from heads")))
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
47 entry[1].append(('', 'narrowspec', '',
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
48 _("read narrowspecs from file")))
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
49 # 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
50 if 'sparse' not in extensions.enabled():
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
51 entry[1].append(('', 'include', [],
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
52 _("specifically fetch this file/directory")))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
53 entry[1].append(
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
54 ('', 'exclude', [],
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
55 _("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
56
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
57 entry = extensions.wrapcommand(commands.table, 'pull', pullnarrowcmd)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
58 entry[1].append(('', 'depth', '',
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
59 _("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
60
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
61 extensions.wrapcommand(commands.table, 'archive', archivenarrowcmd)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
62
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
63 def clonenarrowcmd(orig, ui, repo, *args, **opts):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
64 """Wraps clone command, so 'hg clone' first wraps localrepo.clone()."""
36154
4a7ba3ac9163 narrowcommands: use pycompat.{bytes,str}kwargs
Augie Fackler <augie@google.com>
parents: 36100
diff changeset
65 opts = pycompat.byteskwargs(opts)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
66 wrappedextraprepare = util.nullcontextmanager()
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
67 narrowspecfile = opts['narrowspec']
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
68
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
69 if narrowspecfile:
39818
24e493ec2229 py3: rename pycompat.getcwd() to encoding.getcwd() (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 39734
diff changeset
70 filepath = os.path.join(encoding.getcwd(), narrowspecfile)
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
71 ui.status(_("reading narrowspec from '%s'\n") % filepath)
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
72 try:
39465
4062bbb1d10f narrow: use util.readfile() and improve error message using --narrowspec
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39440
diff changeset
73 fdata = util.readfile(filepath)
4062bbb1d10f narrow: use util.readfile() and improve error message using --narrowspec
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39440
diff changeset
74 except IOError as inst:
4062bbb1d10f narrow: use util.readfile() and improve error message using --narrowspec
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39440
diff changeset
75 raise error.Abort(_("cannot read narrowspecs from '%s': %s") %
4062bbb1d10f narrow: use util.readfile() and improve error message using --narrowspec
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39440
diff changeset
76 (filepath, encoding.strtolocal(inst.strerror)))
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
77
39465
4062bbb1d10f narrow: use util.readfile() and improve error message using --narrowspec
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39440
diff changeset
78 includes, excludes, profiles = sparse.parseconfig(ui, fdata, 'narrow')
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
79 if profiles:
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
80 raise error.Abort(_("cannot specify other files using '%include' in"
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
81 " narrowspec"))
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
82
39541
8301741e1f89 narrow: validate spec files are well-formed during clone (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39532
diff changeset
83 narrowspec.validatepatterns(includes)
8301741e1f89 narrow: validate spec files are well-formed during clone (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39532
diff changeset
84 narrowspec.validatepatterns(excludes)
8301741e1f89 narrow: validate spec files are well-formed during clone (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39532
diff changeset
85
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
86 # narrowspec is passed so we should assume that user wants narrow clone
39545
4afd2af36456 narrow: set opts['narrow'] instead of local variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39544
diff changeset
87 opts['narrow'] = True
39247
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
88 opts['include'].extend(includes)
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
89 opts['exclude'].extend(excludes)
f4d4bd8c8911 narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38835
diff changeset
90
39545
4afd2af36456 narrow: set opts['narrow'] instead of local variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39544
diff changeset
91 if opts['narrow']:
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
92 def pullbundle2extraprepare_widen(orig, pullop, kwargs):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
93 orig(pullop, kwargs)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
94
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
95 if opts.get('depth'):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
96 kwargs['depth'] = opts['depth']
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
97 wrappedextraprepare = extensions.wrappedfunction(exchange,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
98 '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
99
39554
841c82d1a973 narrow: don't wrap exchange.pull() during clone
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39545
diff changeset
100 with wrappedextraprepare:
36154
4a7ba3ac9163 narrowcommands: use pycompat.{bytes,str}kwargs
Augie Fackler <augie@google.com>
parents: 36100
diff changeset
101 return orig(ui, repo, *args, **pycompat.strkwargs(opts))
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
102
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
103 def pullnarrowcmd(orig, ui, repo, *args, **opts):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
104 """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
105 wrappedextraprepare = util.nullcontextmanager()
38835
a232e6744ba3 narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents: 38528
diff changeset
106 if repository.NARROW_REQUIREMENT in repo.requirements:
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
107
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
108 def pullbundle2extraprepare_widen(orig, pullop, kwargs):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
109 orig(pullop, kwargs)
36456
9ff5cbfbc26a py3: fix more keyword arguments handling
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36352
diff changeset
110 if opts.get(r'depth'):
9ff5cbfbc26a py3: fix more keyword arguments handling
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36352
diff changeset
111 kwargs['depth'] = opts[r'depth']
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
112 wrappedextraprepare = extensions.wrappedfunction(exchange,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
113 '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
114
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
115 with wrappedextraprepare:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
116 return orig(ui, repo, *args, **opts)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
117
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
118 def archivenarrowcmd(orig, ui, repo, *args, **opts):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
119 """Wraps archive command to narrow the default includes."""
38835
a232e6744ba3 narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents: 38528
diff changeset
120 if repository.NARROW_REQUIREMENT in repo.requirements:
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
121 repo_includes, repo_excludes = repo.narrowpats
36352
5dbeddbf164a narrowcommands: add some missing strkwargs calls for py3
Augie Fackler <augie@google.com>
parents: 36166
diff changeset
122 includes = set(opts.get(r'include', []))
5dbeddbf164a narrowcommands: add some missing strkwargs calls for py3
Augie Fackler <augie@google.com>
parents: 36166
diff changeset
123 excludes = set(opts.get(r'exclude', []))
36100
8fd0a9e2d7e9 narrow: make restrictpatterns a little more idiomatic
Augie Fackler <augie@google.com>
parents: 36088
diff changeset
124 includes, excludes, unused_invalid = narrowspec.restrictpatterns(
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
125 includes, excludes, repo_includes, repo_excludes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
126 if includes:
36352
5dbeddbf164a narrowcommands: add some missing strkwargs calls for py3
Augie Fackler <augie@google.com>
parents: 36166
diff changeset
127 opts[r'include'] = includes
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
128 if excludes:
36352
5dbeddbf164a narrowcommands: add some missing strkwargs calls for py3
Augie Fackler <augie@google.com>
parents: 36166
diff changeset
129 opts[r'exclude'] = excludes
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
130 return orig(ui, repo, *args, **opts)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
131
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
132 def pullbundle2extraprepare(orig, pullop, kwargs):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
133 repo = pullop.repo
38835
a232e6744ba3 narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents: 38528
diff changeset
134 if repository.NARROW_REQUIREMENT not in repo.requirements:
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
135 return orig(pullop, kwargs)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
136
40074
f7011b44d205 wireprotoserver: move narrow capabilities to wireprototypes.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40070
diff changeset
137 if wireprototypes.NARROWCAP not in pullop.remote.capabilities():
39964
06e75fbf9d6b narrow: check for servers' narrow support before doing anything (BC)
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39963
diff changeset
138 raise error.Abort(_("server does not support narrow clones"))
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
139 orig(pullop, kwargs)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
140 kwargs['narrow'] = True
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
141 include, exclude = repo.narrowpats
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
142 kwargs['oldincludepats'] = include
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
143 kwargs['oldexcludepats'] = exclude
40493
a2c4502e409b narrow: only send includepats and excludepats if they are not empty
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40438
diff changeset
144 if include:
a2c4502e409b narrow: only send includepats and excludepats if they are not empty
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40438
diff changeset
145 kwargs['includepats'] = include
a2c4502e409b narrow: only send includepats and excludepats if they are not empty
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40438
diff changeset
146 if exclude:
a2c4502e409b narrow: only send includepats and excludepats if they are not empty
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40438
diff changeset
147 kwargs['excludepats'] = exclude
39524
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
148 # calculate known nodes only in ellipses cases because in non-ellipses cases
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
149 # we have all the nodes
40074
f7011b44d205 wireprotoserver: move narrow capabilities to wireprototypes.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40070
diff changeset
150 if wireprototypes.ELLIPSESCAP in pullop.remote.capabilities():
39524
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
151 kwargs['known'] = [node.hex(ctx.node()) for ctx in
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
152 repo.set('::%ln', pullop.common)
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
153 if ctx.node() != node.nullid]
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
154 if not kwargs['known']:
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
155 # Mercurial serializes an empty list as '' and deserializes it as
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
156 # [''], so delete it instead to avoid handling the empty string on
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
157 # the server.
294c571490f0 narrow: build the known set of nodes only when ellipses is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39465
diff changeset
158 del kwargs['known']
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
159
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
160 extensions.wrapfunction(exchange,'_pullbundle2extraprepare',
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
161 pullbundle2extraprepare)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
162
39734
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
163 # This is an extension point for filesystems that need to do something other
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
164 # than just blindly unlink the files. It's not clear what arguments would be
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
165 # useful, so we're passing in a fair number of them, some of them redundant.
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
166 def _narrowcleanupwdir(repo, oldincludes, oldexcludes, newincludes, newexcludes,
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
167 oldmatch, newmatch):
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
168 for f in repo.dirstate:
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
169 if not newmatch(f):
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
170 repo.dirstate.drop(f)
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
171 repo.wvfs.unlinkpath(f)
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
172
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
173 def _narrow(ui, repo, remote, commoninc, oldincludes, oldexcludes,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
174 newincludes, newexcludes, force):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
175 oldmatch = narrowspec.match(repo.root, oldincludes, oldexcludes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
176 newmatch = narrowspec.match(repo.root, newincludes, newexcludes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
177
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
178 # This is essentially doing "hg outgoing" to find all local-only
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
179 # commits. We will then check that the local-only commits don't
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
180 # have any changes to files that will be untracked.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
181 unfi = repo.unfiltered()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
182 outgoing = discovery.findcommonoutgoing(unfi, remote,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
183 commoninc=commoninc)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
184 ui.status(_('looking for local changes to affected paths\n'))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
185 localnodes = []
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
186 for n in itertools.chain(outgoing.missing, outgoing.excluded):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
187 if any(oldmatch(f) and not newmatch(f) for f in unfi[n].files()):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
188 localnodes.append(n)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
189 revstostrip = unfi.revs('descendants(%ln)', localnodes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
190 hiddenrevs = repoview.filterrevs(repo, 'visible')
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
191 visibletostrip = list(repo.changelog.node(r)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
192 for r in (revstostrip - hiddenrevs))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
193 if visibletostrip:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
194 ui.status(_('The following changeset(s) or their ancestors have '
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
195 'local changes not on the remote:\n'))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
196 maxnodes = 10
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
197 if ui.verbose or len(visibletostrip) <= maxnodes:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
198 for n in visibletostrip:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
199 ui.status('%s\n' % node.short(n))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
200 else:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
201 for n in visibletostrip[:maxnodes]:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
202 ui.status('%s\n' % node.short(n))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
203 ui.status(_('...and %d more, use --verbose to list all\n') %
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
204 (len(visibletostrip) - maxnodes))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
205 if not force:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
206 raise error.Abort(_('local changes found'),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
207 hint=_('use --force-delete-local-changes to '
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
208 'ignore'))
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
209
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
210 with ui.uninterruptable():
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
211 if revstostrip:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
212 tostrip = [unfi.changelog.node(r) for r in revstostrip]
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
213 if repo['.'].node() in tostrip:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
214 # stripping working copy, so move to a different commit first
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
215 urev = max(repo.revs('(::%n) - %ln + null',
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
216 repo['.'].node(), visibletostrip))
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
217 hg.clean(repo, urev)
40829
77173267878b narrow: don't resurrect old commits when narrowing (don't strip obsmarkers)
Martin von Zweigbergk <martinvonz@google.com>
parents: 40766
diff changeset
218 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: 40766
diff changeset
219 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: 40766
diff changeset
220 repair.strip(ui, unfi, tostrip, topic='narrow')
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
221
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
222 todelete = []
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
223 for f, f2, size in repo.store.datafiles():
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
224 if f.startswith('data/'):
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
225 file = f[5:-2]
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
226 if not newmatch(file):
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
227 todelete.append(f)
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
228 elif f.startswith('meta/'):
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
229 dir = f[5:-13]
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
230 dirs = ['.'] + sorted(util.dirs({dir})) + [dir]
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
231 include = True
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
232 for d in dirs:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
233 visit = newmatch.visitdir(d)
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
234 if not visit:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
235 include = False
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
236 break
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
237 if visit == 'all':
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
238 break
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
239 if not include:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
240 todelete.append(f)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
241
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
242 repo.destroying()
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
243
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
244 with repo.transaction("narrowing"):
41028
095a0a63ad88 narrow: when narrowing, write new narrowspec before removing revlogs
Martin von Zweigbergk <martinvonz@google.com>
parents: 41027
diff changeset
245 # 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: 41027
diff changeset
246 # corrupt in case of crash
095a0a63ad88 narrow: when narrowing, write new narrowspec before removing revlogs
Martin von Zweigbergk <martinvonz@google.com>
parents: 41027
diff changeset
247 repo.setnarrowpats(newincludes, newexcludes)
095a0a63ad88 narrow: when narrowing, write new narrowspec before removing revlogs
Martin von Zweigbergk <martinvonz@google.com>
parents: 41027
diff changeset
248
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
249 for f in todelete:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
250 ui.status(_('deleting %s\n') % f)
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
251 util.unlinkpath(repo.svfs.join(f))
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
252 repo.store.markremoved(f)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
253
39734
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
254 _narrowcleanupwdir(repo, oldincludes, oldexcludes, newincludes,
9d5c919b6dc3 narrow: extract wdir cleanup function to make it extensible
Kyle Lippincott <spectral@google.com>
parents: 39673
diff changeset
255 newexcludes, oldmatch, newmatch)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
256
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
257 repo.destroyed()
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
258
39965
1a4c1a3cc3f5 narrow: pass old includes and excludes to _widen()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39964
diff changeset
259 def _widen(ui, repo, remote, commoninc, oldincludes, oldexcludes,
1a4c1a3cc3f5 narrow: pass old includes and excludes to _widen()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39964
diff changeset
260 newincludes, newexcludes):
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
261 newmatch = narrowspec.match(repo.root, newincludes, newexcludes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
262
39963
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
263 # 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: 39934
diff changeset
264 # 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: 39934
diff changeset
265 # 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: 39934
diff changeset
266 # 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: 39934
diff changeset
267 # 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: 39934
diff changeset
268 # functionality from an ellipses enabled server
40074
f7011b44d205 wireprotoserver: move narrow capabilities to wireprototypes.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40070
diff changeset
269 ellipsesremote = wireprototypes.ELLIPSESCAP in remote.capabilities()
39963
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
270
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
271 def pullbundle2extraprepare_widen(orig, pullop, kwargs):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
272 orig(pullop, kwargs)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
273 # 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
274 kwargs['includepats'] = newincludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
275 kwargs['excludepats'] = newexcludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
276 wrappedextraprepare = extensions.wrappedfunction(exchange,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
277 '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
278
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
279 # 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
280 # 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
281 def setnewnarrowpats():
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
282 repo.setnarrowpats(newincludes, newexcludes)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
283 repo.setnewnarrowpats = setnewnarrowpats
39673
f1844a10ee19 narrow: don't send the changelog information when widening without ellipses
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39555
diff changeset
284 # silence the devel-warning of applying an empty changegroup
f1844a10ee19 narrow: don't send the changelog information when widening without ellipses
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39555
diff changeset
285 overrides = {('devel', 'all-warnings'): False}
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
286
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
287 with ui.uninterruptable():
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
288 common = commoninc[0]
39963
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
289 if ellipsesremote:
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
290 ds = repo.dirstate
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
291 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: 39934
diff changeset
292 with ds.parentchange():
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
293 ds.setparents(node.nullid, node.nullid)
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
294 with wrappedextraprepare,\
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
295 repo.ui.configoverride(overrides, 'widen'):
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
296 exchange.pull(repo, remote, heads=common)
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
297 with ds.parentchange():
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
298 ds.setparents(p1, p2)
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
299 else:
40070
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
300 with remote.commandexecutor() as e:
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
301 bundle = e.callcommand('narrow_widen', {
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
302 'oldincludes': oldincludes,
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
303 'oldexcludes': oldexcludes,
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
304 'newincludes': newincludes,
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
305 'newexcludes': newexcludes,
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
306 'cgversion': '03',
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
307 'commonheads': common,
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
308 'known': [],
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
309 'ellipses': False,
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
310 }).result()
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
311
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
312 with repo.transaction('widening') as tr,\
39963
693dda764efe narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
313 repo.ui.configoverride(overrides, 'widen'):
40070
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
314 tgetter = lambda: tr
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
315 bundle2.processbundle(repo, bundle,
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39965
diff changeset
316 transactiongetter=tgetter)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
317
39357
2b8adb7ca39a narrow: update the narrowspecs to new ones after pulling when widening
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39356
diff changeset
318 repo.setnewnarrowpats()
41039
54c3b4bd01f2 merge: extract helper for creating empty "actions" dict
Martin von Zweigbergk <martinvonz@google.com>
parents: 41028
diff changeset
319 actions = merge.emptyactions()
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
320 addgaction = actions['g'].append
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
321
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
322 mf = repo['.'].manifest().matches(newmatch)
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
323 for f, fn in mf.iteritems():
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
324 if f not in repo.dirstate:
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
325 addgaction((f, (mf.flags(f), False),
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
326 "add from widened narrow clone"))
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
327
38528
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
328 merge.applyupdates(repo, actions, wctx=repo[None],
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
329 mctx=repo['.'], overwrite=False)
a1d5951efce7 narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents: 36469
diff changeset
330 merge.recordupdates(repo, actions, branchmerge=False)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
331
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
332 # 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
333 @command('tracked',
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
334 [('', 'addinclude', [], _('new paths to include')),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
335 ('', 'removeinclude', [], _('old paths to no longer include')),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
336 ('', 'addexclude', [], _('new paths to exclude')),
39440
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
337 ('', 'import-rules', '', _('import narrowspecs from a file')),
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
338 ('', 'removeexclude', [], _('old paths to no longer exclude')),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
339 ('', '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
340 ('', 'force-delete-local-changes', False,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
341 _('forces deletion of local changes when narrowing')),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
342 ] + commands.remoteopts,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
343 _('[OPTIONS]... [REMOTE]'),
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
344 inferrepo=True)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
345 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
346 """show or change the current narrowspec
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
347
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
348 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
349 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
350 respectively.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
351
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
352 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
353 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
354 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
355 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
356 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
357 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
358
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
359 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
360 'hg help patterns'.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
361
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
362 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
363
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
364 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
365 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
366 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
367 empty and will not match any files.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
368 """
36166
ccf7ae119769 narrowcommands: more byteskwargs cleanup
Augie Fackler <augie@google.com>
parents: 36160
diff changeset
369 opts = pycompat.byteskwargs(opts)
38835
a232e6744ba3 narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents: 38528
diff changeset
370 if repository.NARROW_REQUIREMENT not in repo.requirements:
41027
74e023f5a922 narrow: replace "ui.warn(); return 1" by "raise error.Abort()"
Martin von Zweigbergk <martinvonz@google.com>
parents: 40829
diff changeset
371 raise error.Abort(_('the narrow command is only supported on '
74e023f5a922 narrow: replace "ui.warn(); return 1" by "raise error.Abort()"
Martin von Zweigbergk <martinvonz@google.com>
parents: 40829
diff changeset
372 'respositories cloned with --narrow'))
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
373
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
374 # 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
375 # tracking no paths or all paths.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
376 if opts['clear']:
41027
74e023f5a922 narrow: replace "ui.warn(); return 1" by "raise error.Abort()"
Martin von Zweigbergk <martinvonz@google.com>
parents: 40829
diff changeset
377 raise error.Abort(_('the --clear option is not yet supported'))
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
378
39440
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
379 # import rules from a file
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
380 newrules = opts.get('import_rules')
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
381 if newrules:
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
382 try:
39818
24e493ec2229 py3: rename pycompat.getcwd() to encoding.getcwd() (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 39734
diff changeset
383 filepath = os.path.join(encoding.getcwd(), newrules)
39440
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
384 fdata = util.readfile(filepath)
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
385 except IOError as inst:
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
386 raise error.Abort(_("cannot read narrowspecs from '%s': %s") %
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
387 (filepath, encoding.strtolocal(inst.strerror)))
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
388 includepats, excludepats, profiles = sparse.parseconfig(ui, fdata,
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
389 'narrow')
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
390 if profiles:
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
391 raise error.Abort(_("including other spec files using '%include' "
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
392 "is not supported in narrowspec"))
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
393 opts['addinclude'].extend(includepats)
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
394 opts['addexclude'].extend(excludepats)
ab20ee07b82d narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39357
diff changeset
395
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
396 addedincludes = narrowspec.parsepatterns(opts['addinclude'])
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
397 removedincludes = narrowspec.parsepatterns(opts['removeinclude'])
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
398 addedexcludes = narrowspec.parsepatterns(opts['addexclude'])
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
399 removedexcludes = narrowspec.parsepatterns(opts['removeexclude'])
40436
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40074
diff changeset
400
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40074
diff changeset
401 only_show = not (addedincludes or removedincludes or addedexcludes or
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40074
diff changeset
402 removedexcludes or newrules)
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40074
diff changeset
403
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40074
diff changeset
404 oldincludes, oldexcludes = repo.narrowpats
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40074
diff changeset
405
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40074
diff changeset
406 # 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: 40074
diff changeset
407 # deletions of excludes and includes
40438
5d8f291405e5 narrow: replace filtering in list comprehension by set operations
Martin von Zweigbergk <martinvonz@google.com>
parents: 40436
diff changeset
408 addedincludes -= oldincludes
5d8f291405e5 narrow: replace filtering in list comprehension by set operations
Martin von Zweigbergk <martinvonz@google.com>
parents: 40436
diff changeset
409 removedincludes &= oldincludes
5d8f291405e5 narrow: replace filtering in list comprehension by set operations
Martin von Zweigbergk <martinvonz@google.com>
parents: 40436
diff changeset
410 addedexcludes -= oldexcludes
5d8f291405e5 narrow: replace filtering in list comprehension by set operations
Martin von Zweigbergk <martinvonz@google.com>
parents: 40436
diff changeset
411 removedexcludes &= oldexcludes
40436
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40074
diff changeset
412
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
413 widening = addedincludes or removedexcludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
414 narrowing = removedincludes or addedexcludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
415
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
416 # Only print the current narrowspec.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
417 if only_show:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
418 ui.pager('tracked')
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
419 fm = ui.formatter('narrow', opts)
40766
773572e5cba2 narrowcommands: remove an unrequired `repo.narrowpats` call
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40493
diff changeset
420 for i in sorted(oldincludes):
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
421 fm.startitem()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
422 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
423 fm.write('pat', '%s\n', i, label='narrow.included')
40766
773572e5cba2 narrowcommands: remove an unrequired `repo.narrowpats` call
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40493
diff changeset
424 for i in sorted(oldexcludes):
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
425 fm.startitem()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
426 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
427 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
428 fm.end()
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
429 return 0
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
430
40436
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40074
diff changeset
431 if not widening and not narrowing:
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40074
diff changeset
432 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: 40074
diff changeset
433 return 0
30a7d3b6b281 narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40074
diff changeset
434
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
435 with repo.wlock(), repo.lock():
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
436 cmdutil.bailifchanged(repo)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
437
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
438 # 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
439 # 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
440 # 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
441 remotepath = ui.expandpath(remotepath or 'default')
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
442 url, branches = hg.parseurl(remotepath)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
443 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
444 remote = hg.peer(repo, opts, url)
39964
06e75fbf9d6b narrow: check for servers' narrow support before doing anything (BC)
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39963
diff changeset
445
06e75fbf9d6b narrow: check for servers' narrow support before doing anything (BC)
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39963
diff changeset
446 # 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: 39963
diff changeset
447 # 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: 39963
diff changeset
448 # server does not support ellipses
40074
f7011b44d205 wireprotoserver: move narrow capabilities to wireprototypes.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40070
diff changeset
449 if widening and wireprototypes.NARROWCAP not in remote.capabilities():
39964
06e75fbf9d6b narrow: check for servers' narrow support before doing anything (BC)
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39963
diff changeset
450 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: 39963
diff changeset
451
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
452 commoninc = discovery.findcommonincoming(repo, remote)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
453
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
454 if narrowing:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
455 newincludes = oldincludes - removedincludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
456 newexcludes = oldexcludes | addedexcludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
457 _narrow(ui, repo, remote, commoninc, oldincludes, oldexcludes,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
458 newincludes, newexcludes,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
459 opts['force_delete_local_changes'])
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
460 # _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
461 # 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
462 # 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
463 oldincludes = newincludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
464 oldexcludes = newexcludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
465
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
466 if widening:
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
467 newincludes = oldincludes | addedincludes
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
468 newexcludes = oldexcludes - removedexcludes
39965
1a4c1a3cc3f5 narrow: pass old includes and excludes to _widen()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39964
diff changeset
469 _widen(ui, repo, remote, commoninc, oldincludes, oldexcludes,
1a4c1a3cc3f5 narrow: pass old includes and excludes to _widen()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39964
diff changeset
470 newincludes, newexcludes)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
471
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
472 return 0