Mercurial > hg
annotate hgext/narrow/narrowcommands.py @ 41618:e834f6f6f221
patch: pass in context objects into diffhunks() (API)
It's a pretty low-level function and having the contexts in
patch.diff() makes future patches easier.
Differential Revision: https://phab.mercurial-scm.org/D5891
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 06 Feb 2019 17:27:43 -0800 |
parents | 8c366af085f4 |
children | ebbc4e70ebd1 |
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, |
36160
9fd8c2a3db5a
narrowspec: move module into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36154
diff
changeset
|
23 narrowspec, |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 node, |
36154
4a7ba3ac9163
narrowcommands: use pycompat.{bytes,str}kwargs
Augie Fackler <augie@google.com>
parents:
36100
diff
changeset
|
25 pycompat, |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
26 registrar, |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
27 repair, |
38835
a232e6744ba3
narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents:
38528
diff
changeset
|
28 repository, |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
29 repoview, |
39247
f4d4bd8c8911
narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
38835
diff
changeset
|
30 sparse, |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
31 util, |
40074
f7011b44d205
wireprotoserver: move narrow capabilities to wireprototypes.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40070
diff
changeset
|
32 wireprototypes, |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
33 ) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
34 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
35 table = {} |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
36 command = registrar.command(table) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
37 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
38 def setup(): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
39 """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
|
40 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
41 entry = extensions.wrapcommand(commands.table, 'clone', clonenarrowcmd) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
42 entry[1].append(('', 'narrow', None, |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
43 _("create a narrow clone of select files"))) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
44 entry[1].append(('', 'depth', '', |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
45 _("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
|
46 entry[1].append(('', 'narrowspec', '', |
f4d4bd8c8911
narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
38835
diff
changeset
|
47 _("read narrowspecs from file"))) |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
48 # 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
|
49 if 'sparse' not in extensions.enabled(): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
50 entry[1].append(('', 'include', [], |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
51 _("specifically fetch this file/directory"))) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
52 entry[1].append( |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
53 ('', 'exclude', [], |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
54 _("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
|
55 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
56 entry = extensions.wrapcommand(commands.table, 'pull', pullnarrowcmd) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
57 entry[1].append(('', 'depth', '', |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
58 _("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
|
59 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
60 extensions.wrapcommand(commands.table, 'archive', archivenarrowcmd) |
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 def clonenarrowcmd(orig, ui, repo, *args, **opts): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
63 """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
|
64 opts = pycompat.byteskwargs(opts) |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
65 wrappedextraprepare = util.nullcontextmanager() |
39247
f4d4bd8c8911
narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
38835
diff
changeset
|
66 narrowspecfile = opts['narrowspec'] |
f4d4bd8c8911
narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
38835
diff
changeset
|
67 |
f4d4bd8c8911
narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
38835
diff
changeset
|
68 if narrowspecfile: |
39818
24e493ec2229
py3: rename pycompat.getcwd() to encoding.getcwd() (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
39734
diff
changeset
|
69 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
|
70 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
|
71 try: |
39465
4062bbb1d10f
narrow: use util.readfile() and improve error message using --narrowspec
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39440
diff
changeset
|
72 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
|
73 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
|
74 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
|
75 (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
|
76 |
39465
4062bbb1d10f
narrow: use util.readfile() and improve error message using --narrowspec
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39440
diff
changeset
|
77 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
|
78 if profiles: |
f4d4bd8c8911
narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
38835
diff
changeset
|
79 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
|
80 " narrowspec")) |
f4d4bd8c8911
narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
38835
diff
changeset
|
81 |
39541
8301741e1f89
narrow: validate spec files are well-formed during clone (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39532
diff
changeset
|
82 narrowspec.validatepatterns(includes) |
8301741e1f89
narrow: validate spec files are well-formed during clone (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39532
diff
changeset
|
83 narrowspec.validatepatterns(excludes) |
8301741e1f89
narrow: validate spec files are well-formed during clone (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39532
diff
changeset
|
84 |
39247
f4d4bd8c8911
narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
38835
diff
changeset
|
85 # 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
|
86 opts['narrow'] = True |
39247
f4d4bd8c8911
narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
38835
diff
changeset
|
87 opts['include'].extend(includes) |
f4d4bd8c8911
narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
38835
diff
changeset
|
88 opts['exclude'].extend(excludes) |
f4d4bd8c8911
narrow: add a --narrowspec flag to clone command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
38835
diff
changeset
|
89 |
39545
4afd2af36456
narrow: set opts['narrow'] instead of local variable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39544
diff
changeset
|
90 if opts['narrow']: |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
91 def pullbundle2extraprepare_widen(orig, pullop, kwargs): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
92 orig(pullop, kwargs) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
93 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
94 if opts.get('depth'): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
95 kwargs['depth'] = opts['depth'] |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
96 wrappedextraprepare = extensions.wrappedfunction(exchange, |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
97 '_pullbundle2extraprepare', pullbundle2extraprepare_widen) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
98 |
39554
841c82d1a973
narrow: don't wrap exchange.pull() during clone
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39545
diff
changeset
|
99 with wrappedextraprepare: |
36154
4a7ba3ac9163
narrowcommands: use pycompat.{bytes,str}kwargs
Augie Fackler <augie@google.com>
parents:
36100
diff
changeset
|
100 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
|
101 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
102 def pullnarrowcmd(orig, ui, repo, *args, **opts): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
103 """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
|
104 wrappedextraprepare = util.nullcontextmanager() |
38835
a232e6744ba3
narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents:
38528
diff
changeset
|
105 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
|
106 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
107 def pullbundle2extraprepare_widen(orig, pullop, kwargs): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
108 orig(pullop, kwargs) |
36456
9ff5cbfbc26a
py3: fix more keyword arguments handling
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36352
diff
changeset
|
109 if opts.get(r'depth'): |
9ff5cbfbc26a
py3: fix more keyword arguments handling
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36352
diff
changeset
|
110 kwargs['depth'] = opts[r'depth'] |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
111 wrappedextraprepare = extensions.wrappedfunction(exchange, |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
112 '_pullbundle2extraprepare', pullbundle2extraprepare_widen) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
113 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
114 with wrappedextraprepare: |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
115 return orig(ui, repo, *args, **opts) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
116 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
117 def archivenarrowcmd(orig, ui, repo, *args, **opts): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
118 """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
|
119 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
|
120 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
|
121 includes = set(opts.get(r'include', [])) |
5dbeddbf164a
narrowcommands: add some missing strkwargs calls for py3
Augie Fackler <augie@google.com>
parents:
36166
diff
changeset
|
122 excludes = set(opts.get(r'exclude', [])) |
36100
8fd0a9e2d7e9
narrow: make restrictpatterns a little more idiomatic
Augie Fackler <augie@google.com>
parents:
36088
diff
changeset
|
123 includes, excludes, unused_invalid = narrowspec.restrictpatterns( |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
124 includes, excludes, repo_includes, repo_excludes) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
125 if includes: |
36352
5dbeddbf164a
narrowcommands: add some missing strkwargs calls for py3
Augie Fackler <augie@google.com>
parents:
36166
diff
changeset
|
126 opts[r'include'] = includes |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
127 if excludes: |
36352
5dbeddbf164a
narrowcommands: add some missing strkwargs calls for py3
Augie Fackler <augie@google.com>
parents:
36166
diff
changeset
|
128 opts[r'exclude'] = excludes |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
129 return orig(ui, repo, *args, **opts) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
130 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
131 def pullbundle2extraprepare(orig, pullop, kwargs): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
132 repo = pullop.repo |
38835
a232e6744ba3
narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents:
38528
diff
changeset
|
133 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
|
134 return orig(pullop, kwargs) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
135 |
40074
f7011b44d205
wireprotoserver: move narrow capabilities to wireprototypes.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40070
diff
changeset
|
136 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
|
137 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
|
138 orig(pullop, kwargs) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
139 kwargs['narrow'] = True |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
140 include, exclude = repo.narrowpats |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
141 kwargs['oldincludepats'] = include |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
142 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
|
143 if include: |
a2c4502e409b
narrow: only send includepats and excludepats if they are not empty
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40438
diff
changeset
|
144 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
|
145 if exclude: |
a2c4502e409b
narrow: only send includepats and excludepats if they are not empty
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40438
diff
changeset
|
146 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
|
147 # 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
|
148 # we have all the nodes |
40074
f7011b44d205
wireprotoserver: move narrow capabilities to wireprototypes.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40070
diff
changeset
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 # 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
|
155 # [''], 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
|
156 # 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
|
157 del kwargs['known'] |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
158 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
159 extensions.wrapfunction(exchange,'_pullbundle2extraprepare', |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
160 pullbundle2extraprepare) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
161 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
162 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
|
163 newincludes, newexcludes, force): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
164 oldmatch = narrowspec.match(repo.root, oldincludes, oldexcludes) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
165 newmatch = narrowspec.match(repo.root, newincludes, newexcludes) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
166 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
167 # 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
|
168 # 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
|
169 # 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
|
170 unfi = repo.unfiltered() |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
171 outgoing = discovery.findcommonoutgoing(unfi, remote, |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
172 commoninc=commoninc) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
173 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
|
174 localnodes = [] |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
175 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
|
176 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
|
177 localnodes.append(n) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
178 revstostrip = unfi.revs('descendants(%ln)', localnodes) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
179 hiddenrevs = repoview.filterrevs(repo, 'visible') |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
180 visibletostrip = list(repo.changelog.node(r) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
181 for r in (revstostrip - hiddenrevs)) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
182 if visibletostrip: |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
183 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
|
184 'local changes not on the remote:\n')) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
185 maxnodes = 10 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
186 if ui.verbose or len(visibletostrip) <= maxnodes: |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
187 for n in visibletostrip: |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
188 ui.status('%s\n' % node.short(n)) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
189 else: |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
190 for n in visibletostrip[:maxnodes]: |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
191 ui.status('%s\n' % node.short(n)) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
192 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
|
193 (len(visibletostrip) - maxnodes)) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
194 if not force: |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
195 raise error.Abort(_('local changes found'), |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
196 hint=_('use --force-delete-local-changes to ' |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
197 'ignore')) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
198 |
41076
8ecb17b7f432
procutil: correct spelling of uninterruptable -> uninterruptible
Kyle Lippincott <spectral@google.com>
parents:
41043
diff
changeset
|
199 with ui.uninterruptible(): |
38528
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
200 if revstostrip: |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
201 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
|
202 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
|
203 # 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
|
204 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
|
205 repo['.'].node(), visibletostrip)) |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
206 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
|
207 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
|
208 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
|
209 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
|
210 |
38528
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
211 todelete = [] |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
212 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
|
213 if f.startswith('data/'): |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
214 file = f[5:-2] |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
215 if not newmatch(file): |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
216 todelete.append(f) |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
217 elif f.startswith('meta/'): |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
218 dir = f[5:-13] |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
219 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
|
220 include = True |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
221 for d in dirs: |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
222 visit = newmatch.visitdir(d) |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
223 if not visit: |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
224 include = False |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
225 break |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
226 if visit == 'all': |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
227 break |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
228 if not include: |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
229 todelete.append(f) |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
230 |
38528
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
231 repo.destroying() |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
232 |
41238
8c366af085f4
narrow: reuse narrowspec.updateworkingcopy() when narrowing
Martin von Zweigbergk <martinvonz@google.com>
parents:
41237
diff
changeset
|
233 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
|
234 # 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
|
235 # 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
|
236 repo.setnarrowpats(newincludes, newexcludes) |
095a0a63ad88
narrow: when narrowing, write new narrowspec before removing revlogs
Martin von Zweigbergk <martinvonz@google.com>
parents:
41027
diff
changeset
|
237 |
38528
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
238 for f in todelete: |
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
239 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
|
240 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
|
241 repo.store.markremoved(f) |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
242 |
41238
8c366af085f4
narrow: reuse narrowspec.updateworkingcopy() when narrowing
Martin von Zweigbergk <martinvonz@google.com>
parents:
41237
diff
changeset
|
243 narrowspec.updateworkingcopy(repo, assumeclean=True) |
8c366af085f4
narrow: reuse narrowspec.updateworkingcopy() when narrowing
Martin von Zweigbergk <martinvonz@google.com>
parents:
41237
diff
changeset
|
244 narrowspec.copytoworkingcopy(repo) |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
245 |
38528
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
246 repo.destroyed() |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
247 |
39965
1a4c1a3cc3f5
narrow: pass old includes and excludes to _widen()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39964
diff
changeset
|
248 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
|
249 newincludes, newexcludes): |
39963
693dda764efe
narrow: don't do the dirstate dance if ellipses is not enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
250 # 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
|
251 # 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
|
252 # 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
|
253 # 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
|
254 # 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
|
255 # 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
|
256 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
|
257 |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
258 def pullbundle2extraprepare_widen(orig, pullop, kwargs): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
259 orig(pullop, kwargs) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
260 # 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
|
261 kwargs['includepats'] = newincludes |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
262 kwargs['excludepats'] = newexcludes |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
263 wrappedextraprepare = extensions.wrappedfunction(exchange, |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
264 '_pullbundle2extraprepare', pullbundle2extraprepare_widen) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
265 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
266 # define a function that narrowbundle2 can call after creating the |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
267 # backup bundle, but before applying the bundle from the server |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
268 def setnewnarrowpats(): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
269 repo.setnarrowpats(newincludes, newexcludes) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
270 repo.setnewnarrowpats = setnewnarrowpats |
39673
f1844a10ee19
narrow: don't send the changelog information when widening without ellipses
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39555
diff
changeset
|
271 # silence the devel-warning of applying an empty changegroup |
f1844a10ee19
narrow: don't send the changelog information when widening without ellipses
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39555
diff
changeset
|
272 overrides = {('devel', 'all-warnings'): False} |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
273 |
41076
8ecb17b7f432
procutil: correct spelling of uninterruptable -> uninterruptible
Kyle Lippincott <spectral@google.com>
parents:
41043
diff
changeset
|
274 with ui.uninterruptible(): |
38528
a1d5951efce7
narrow: mark the critical chunks of narrowing/widening as unsafe
Augie Fackler <augie@google.com>
parents:
36469
diff
changeset
|
275 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 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
|
286 else: |
40070
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39965
diff
changeset
|
287 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
|
288 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
|
289 'oldincludes': oldincludes, |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39965
diff
changeset
|
290 'oldexcludes': oldexcludes, |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39965
diff
changeset
|
291 'newincludes': newincludes, |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39965
diff
changeset
|
292 'newexcludes': newexcludes, |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39965
diff
changeset
|
293 'cgversion': '03', |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39965
diff
changeset
|
294 'commonheads': common, |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39965
diff
changeset
|
295 'known': [], |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39965
diff
changeset
|
296 'ellipses': False, |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39965
diff
changeset
|
297 }).result() |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39965
diff
changeset
|
298 |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39965
diff
changeset
|
299 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
|
300 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
|
301 tgetter = lambda: tr |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39965
diff
changeset
|
302 bundle2.processbundle(repo, bundle, |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39965
diff
changeset
|
303 transactiongetter=tgetter) |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
304 |
41237
ad9ab2523149
narrow: reuse narrowspec.updateworkingcopy() when widening
Martin von Zweigbergk <martinvonz@google.com>
parents:
41236
diff
changeset
|
305 with repo.transaction('widening'): |
ad9ab2523149
narrow: reuse narrowspec.updateworkingcopy() when widening
Martin von Zweigbergk <martinvonz@google.com>
parents:
41236
diff
changeset
|
306 repo.setnewnarrowpats() |
ad9ab2523149
narrow: reuse narrowspec.updateworkingcopy() when widening
Martin von Zweigbergk <martinvonz@google.com>
parents:
41236
diff
changeset
|
307 narrowspec.updateworkingcopy(repo) |
ad9ab2523149
narrow: reuse narrowspec.updateworkingcopy() when widening
Martin von Zweigbergk <martinvonz@google.com>
parents:
41236
diff
changeset
|
308 narrowspec.copytoworkingcopy(repo) |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
309 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
310 # 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
|
311 @command('tracked', |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
312 [('', 'addinclude', [], _('new paths to include')), |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
313 ('', 'removeinclude', [], _('old paths to no longer include')), |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
314 ('', '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
|
315 ('', '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
|
316 ('', 'removeexclude', [], _('old paths to no longer exclude')), |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
317 ('', '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
|
318 ('', 'force-delete-local-changes', False, |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
319 _('forces deletion of local changes when narrowing')), |
41043
ce0bc2952e2a
narrow: detect if narrowspec was changed in a different share
Martin von Zweigbergk <martinvonz@google.com>
parents:
41039
diff
changeset
|
320 ('', 'update-working-copy', False, |
ce0bc2952e2a
narrow: detect if narrowspec was changed in a different share
Martin von Zweigbergk <martinvonz@google.com>
parents:
41039
diff
changeset
|
321 _('update working copy when the store has changed')), |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
322 ] + commands.remoteopts, |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
323 _('[OPTIONS]... [REMOTE]'), |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
324 inferrepo=True) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
325 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
|
326 """show or change the current narrowspec |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
327 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
328 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
|
329 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
|
330 respectively. |
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 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
|
333 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
|
334 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
|
335 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
|
336 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
|
337 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
|
338 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
339 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
|
340 'hg help patterns'. |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
341 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
342 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
|
343 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
344 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
|
345 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
|
346 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
|
347 empty and will not match any files. |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
348 """ |
36166
ccf7ae119769
narrowcommands: more byteskwargs cleanup
Augie Fackler <augie@google.com>
parents:
36160
diff
changeset
|
349 opts = pycompat.byteskwargs(opts) |
38835
a232e6744ba3
narrow: move requirement constant from changegroup to repository
Martin von Zweigbergk <martinvonz@google.com>
parents:
38528
diff
changeset
|
350 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
|
351 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
|
352 'respositories cloned with --narrow')) |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
353 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
354 # 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
|
355 # tracking no paths or all paths. |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
356 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
|
357 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
|
358 |
39440
ab20ee07b82d
narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39357
diff
changeset
|
359 # import rules from a file |
ab20ee07b82d
narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39357
diff
changeset
|
360 newrules = opts.get('import_rules') |
ab20ee07b82d
narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39357
diff
changeset
|
361 if newrules: |
ab20ee07b82d
narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39357
diff
changeset
|
362 try: |
39818
24e493ec2229
py3: rename pycompat.getcwd() to encoding.getcwd() (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
39734
diff
changeset
|
363 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
|
364 fdata = util.readfile(filepath) |
ab20ee07b82d
narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39357
diff
changeset
|
365 except IOError as inst: |
ab20ee07b82d
narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39357
diff
changeset
|
366 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
|
367 (filepath, encoding.strtolocal(inst.strerror))) |
ab20ee07b82d
narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39357
diff
changeset
|
368 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
|
369 'narrow') |
ab20ee07b82d
narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39357
diff
changeset
|
370 if profiles: |
ab20ee07b82d
narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39357
diff
changeset
|
371 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
|
372 "is not supported in narrowspec")) |
ab20ee07b82d
narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39357
diff
changeset
|
373 opts['addinclude'].extend(includepats) |
ab20ee07b82d
narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39357
diff
changeset
|
374 opts['addexclude'].extend(excludepats) |
ab20ee07b82d
narrow: add '--import-rules' flag to tracked command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39357
diff
changeset
|
375 |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
376 addedincludes = narrowspec.parsepatterns(opts['addinclude']) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
377 removedincludes = narrowspec.parsepatterns(opts['removeinclude']) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
378 addedexcludes = narrowspec.parsepatterns(opts['addexclude']) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
379 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
|
380 |
41043
ce0bc2952e2a
narrow: detect if narrowspec was changed in a different share
Martin von Zweigbergk <martinvonz@google.com>
parents:
41039
diff
changeset
|
381 update_working_copy = opts['update_working_copy'] |
40436
30a7d3b6b281
narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40074
diff
changeset
|
382 only_show = not (addedincludes or removedincludes or addedexcludes or |
41043
ce0bc2952e2a
narrow: detect if narrowspec was changed in a different share
Martin von Zweigbergk <martinvonz@google.com>
parents:
41039
diff
changeset
|
383 removedexcludes or newrules or update_working_copy) |
40436
30a7d3b6b281
narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40074
diff
changeset
|
384 |
30a7d3b6b281
narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40074
diff
changeset
|
385 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
|
386 |
30a7d3b6b281
narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40074
diff
changeset
|
387 # 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
|
388 # 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
|
389 addedincludes -= oldincludes |
5d8f291405e5
narrow: replace filtering in list comprehension by set operations
Martin von Zweigbergk <martinvonz@google.com>
parents:
40436
diff
changeset
|
390 removedincludes &= oldincludes |
5d8f291405e5
narrow: replace filtering in list comprehension by set operations
Martin von Zweigbergk <martinvonz@google.com>
parents:
40436
diff
changeset
|
391 addedexcludes -= oldexcludes |
5d8f291405e5
narrow: replace filtering in list comprehension by set operations
Martin von Zweigbergk <martinvonz@google.com>
parents:
40436
diff
changeset
|
392 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
|
393 |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
394 widening = addedincludes or removedexcludes |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
395 narrowing = removedincludes or addedexcludes |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
396 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
397 # Only print the current narrowspec. |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
398 if only_show: |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
399 ui.pager('tracked') |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
400 fm = ui.formatter('narrow', opts) |
40766
773572e5cba2
narrowcommands: remove an unrequired `repo.narrowpats` call
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40493
diff
changeset
|
401 for i in sorted(oldincludes): |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
402 fm.startitem() |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
403 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
|
404 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
|
405 for i in sorted(oldexcludes): |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
406 fm.startitem() |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
407 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
|
408 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
|
409 fm.end() |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
410 return 0 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
411 |
41043
ce0bc2952e2a
narrow: detect if narrowspec was changed in a different share
Martin von Zweigbergk <martinvonz@google.com>
parents:
41039
diff
changeset
|
412 if update_working_copy: |
41229
50ca531f1f24
narrow: copy store narrowspec to working copy immediately
Martin von Zweigbergk <martinvonz@google.com>
parents:
41176
diff
changeset
|
413 with repo.wlock(), repo.lock(), repo.transaction('narrow-wc'): |
41176
4475322b7533
narrow: drop explicit dirstate write
Martin von Zweigbergk <martinvonz@google.com>
parents:
41076
diff
changeset
|
414 narrowspec.updateworkingcopy(repo) |
41229
50ca531f1f24
narrow: copy store narrowspec to working copy immediately
Martin von Zweigbergk <martinvonz@google.com>
parents:
41176
diff
changeset
|
415 narrowspec.copytoworkingcopy(repo) |
41043
ce0bc2952e2a
narrow: detect if narrowspec was changed in a different share
Martin von Zweigbergk <martinvonz@google.com>
parents:
41039
diff
changeset
|
416 return 0 |
ce0bc2952e2a
narrow: detect if narrowspec was changed in a different share
Martin von Zweigbergk <martinvonz@google.com>
parents:
41039
diff
changeset
|
417 |
40436
30a7d3b6b281
narrow: rework logic to check whether we need to widen and narrow
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40074
diff
changeset
|
418 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
|
419 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
|
420 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
|
421 |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
422 with repo.wlock(), repo.lock(): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
423 cmdutil.bailifchanged(repo) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
424 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
425 # 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
|
426 # 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
|
427 # 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
|
428 remotepath = ui.expandpath(remotepath or 'default') |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
429 url, branches = hg.parseurl(remotepath) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
430 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
|
431 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
|
432 |
06e75fbf9d6b
narrow: check for servers' narrow support before doing anything (BC)
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39963
diff
changeset
|
433 # 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
|
434 # 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
|
435 # server does not support ellipses |
40074
f7011b44d205
wireprotoserver: move narrow capabilities to wireprototypes.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40070
diff
changeset
|
436 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
|
437 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
|
438 |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
439 commoninc = discovery.findcommonincoming(repo, remote) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
440 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
441 if narrowing: |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
442 newincludes = oldincludes - removedincludes |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
443 newexcludes = oldexcludes | addedexcludes |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
444 _narrow(ui, repo, remote, commoninc, oldincludes, oldexcludes, |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
445 newincludes, newexcludes, |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
446 opts['force_delete_local_changes']) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
447 # _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
|
448 # 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
|
449 # 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
|
450 oldincludes = newincludes |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
451 oldexcludes = newexcludes |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
452 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
453 if widening: |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
454 newincludes = oldincludes | addedincludes |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
455 newexcludes = oldexcludes - removedexcludes |
39965
1a4c1a3cc3f5
narrow: pass old includes and excludes to _widen()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39964
diff
changeset
|
456 _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
|
457 newincludes, newexcludes) |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
458 |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
459 return 0 |