comparison hgext/narrow/narrowcommands.py @ 38835:a232e6744ba3

narrow: move requirement constant from changegroup to repository As suggested by Gregory Szorc. Differential Revision: https://phab.mercurial-scm.org/D4094
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 03 Aug 2018 11:02:34 -0700
parents a1d5951efce7
children f4d4bd8c8911
comparison
equal deleted inserted replaced
38834:c83ad57627ae 38835:a232e6744ba3
8 8
9 import itertools 9 import itertools
10 10
11 from mercurial.i18n import _ 11 from mercurial.i18n import _
12 from mercurial import ( 12 from mercurial import (
13 changegroup,
14 cmdutil, 13 cmdutil,
15 commands, 14 commands,
16 discovery, 15 discovery,
17 error, 16 error,
18 exchange, 17 exchange,
22 narrowspec, 21 narrowspec,
23 node, 22 node,
24 pycompat, 23 pycompat,
25 registrar, 24 registrar,
26 repair, 25 repair,
26 repository,
27 repoview, 27 repoview,
28 util, 28 util,
29 ) 29 )
30 30
31 from . import ( 31 from . import (
99 wrappedextraprepare = extensions.wrappedfunction(exchange, 99 wrappedextraprepare = extensions.wrappedfunction(exchange,
100 '_pullbundle2extraprepare', pullbundle2extraprepare_widen) 100 '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
101 101
102 def pullnarrow(orig, repo, *args, **kwargs): 102 def pullnarrow(orig, repo, *args, **kwargs):
103 if opts_narrow: 103 if opts_narrow:
104 repo.requirements.add(changegroup.NARROW_REQUIREMENT) 104 repo.requirements.add(repository.NARROW_REQUIREMENT)
105 repo._writerequirements() 105 repo._writerequirements()
106 106
107 return orig(repo, *args, **kwargs) 107 return orig(repo, *args, **kwargs)
108 108
109 wrappedpull = extensions.wrappedfunction(exchange, 'pull', pullnarrow) 109 wrappedpull = extensions.wrappedfunction(exchange, 'pull', pullnarrow)
112 return orig(ui, repo, *args, **pycompat.strkwargs(opts)) 112 return orig(ui, repo, *args, **pycompat.strkwargs(opts))
113 113
114 def pullnarrowcmd(orig, ui, repo, *args, **opts): 114 def pullnarrowcmd(orig, ui, repo, *args, **opts):
115 """Wraps pull command to allow modifying narrow spec.""" 115 """Wraps pull command to allow modifying narrow spec."""
116 wrappedextraprepare = util.nullcontextmanager() 116 wrappedextraprepare = util.nullcontextmanager()
117 if changegroup.NARROW_REQUIREMENT in repo.requirements: 117 if repository.NARROW_REQUIREMENT in repo.requirements:
118 118
119 def pullbundle2extraprepare_widen(orig, pullop, kwargs): 119 def pullbundle2extraprepare_widen(orig, pullop, kwargs):
120 orig(pullop, kwargs) 120 orig(pullop, kwargs)
121 if opts.get(r'depth'): 121 if opts.get(r'depth'):
122 kwargs['depth'] = opts[r'depth'] 122 kwargs['depth'] = opts[r'depth']
126 with wrappedextraprepare: 126 with wrappedextraprepare:
127 return orig(ui, repo, *args, **opts) 127 return orig(ui, repo, *args, **opts)
128 128
129 def archivenarrowcmd(orig, ui, repo, *args, **opts): 129 def archivenarrowcmd(orig, ui, repo, *args, **opts):
130 """Wraps archive command to narrow the default includes.""" 130 """Wraps archive command to narrow the default includes."""
131 if changegroup.NARROW_REQUIREMENT in repo.requirements: 131 if repository.NARROW_REQUIREMENT in repo.requirements:
132 repo_includes, repo_excludes = repo.narrowpats 132 repo_includes, repo_excludes = repo.narrowpats
133 includes = set(opts.get(r'include', [])) 133 includes = set(opts.get(r'include', []))
134 excludes = set(opts.get(r'exclude', [])) 134 excludes = set(opts.get(r'exclude', []))
135 includes, excludes, unused_invalid = narrowspec.restrictpatterns( 135 includes, excludes, unused_invalid = narrowspec.restrictpatterns(
136 includes, excludes, repo_includes, repo_excludes) 136 includes, excludes, repo_includes, repo_excludes)
140 opts[r'exclude'] = excludes 140 opts[r'exclude'] = excludes
141 return orig(ui, repo, *args, **opts) 141 return orig(ui, repo, *args, **opts)
142 142
143 def pullbundle2extraprepare(orig, pullop, kwargs): 143 def pullbundle2extraprepare(orig, pullop, kwargs):
144 repo = pullop.repo 144 repo = pullop.repo
145 if changegroup.NARROW_REQUIREMENT not in repo.requirements: 145 if repository.NARROW_REQUIREMENT not in repo.requirements:
146 return orig(pullop, kwargs) 146 return orig(pullop, kwargs)
147 147
148 if narrowbundle2.NARROWCAP not in pullop.remotebundle2caps: 148 if narrowbundle2.NARROWCAP not in pullop.remotebundle2caps:
149 raise error.Abort(_("server doesn't support narrow clones")) 149 raise error.Abort(_("server doesn't support narrow clones"))
150 orig(pullop, kwargs) 150 orig(pullop, kwargs)
329 and replaced by the new ones specified to --addinclude and --addexclude. 329 and replaced by the new ones specified to --addinclude and --addexclude.
330 If --clear is specified without any further options, the narrowspec will be 330 If --clear is specified without any further options, the narrowspec will be
331 empty and will not match any files. 331 empty and will not match any files.
332 """ 332 """
333 opts = pycompat.byteskwargs(opts) 333 opts = pycompat.byteskwargs(opts)
334 if changegroup.NARROW_REQUIREMENT not in repo.requirements: 334 if repository.NARROW_REQUIREMENT not in repo.requirements:
335 ui.warn(_('The narrow command is only supported on respositories cloned' 335 ui.warn(_('The narrow command is only supported on respositories cloned'
336 ' with --narrow.\n')) 336 ' with --narrow.\n'))
337 return 1 337 return 1
338 338
339 # Before supporting, decide whether it "hg tracked --clear" should mean 339 # Before supporting, decide whether it "hg tracked --clear" should mean