comparison hgext/narrow/narrowcommands.py @ 39545:4afd2af36456

narrow: set opts['narrow'] instead of local variable This will allow the command function in core to infer the presence of the option without duplicating logic. Differential Revision: https://phab.mercurial-scm.org/D4532
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 11 Sep 2018 15:40:33 -0700
parents 10a8472f6662
children 841c82d1a973
comparison
equal deleted inserted replaced
39544:10a8472f6662 39545:4afd2af36456
64 64
65 def clonenarrowcmd(orig, ui, repo, *args, **opts): 65 def clonenarrowcmd(orig, ui, repo, *args, **opts):
66 """Wraps clone command, so 'hg clone' first wraps localrepo.clone().""" 66 """Wraps clone command, so 'hg clone' first wraps localrepo.clone()."""
67 opts = pycompat.byteskwargs(opts) 67 opts = pycompat.byteskwargs(opts)
68 wrappedextraprepare = util.nullcontextmanager() 68 wrappedextraprepare = util.nullcontextmanager()
69 opts_narrow = opts['narrow']
70 narrowspecfile = opts['narrowspec'] 69 narrowspecfile = opts['narrowspec']
71 70
72 if narrowspecfile: 71 if narrowspecfile:
73 filepath = os.path.join(pycompat.getcwd(), narrowspecfile) 72 filepath = os.path.join(pycompat.getcwd(), narrowspecfile)
74 ui.status(_("reading narrowspec from '%s'\n") % filepath) 73 ui.status(_("reading narrowspec from '%s'\n") % filepath)
85 84
86 narrowspec.validatepatterns(includes) 85 narrowspec.validatepatterns(includes)
87 narrowspec.validatepatterns(excludes) 86 narrowspec.validatepatterns(excludes)
88 87
89 # narrowspec is passed so we should assume that user wants narrow clone 88 # narrowspec is passed so we should assume that user wants narrow clone
90 opts_narrow = True 89 opts['narrow'] = True
91 opts['include'].extend(includes) 90 opts['include'].extend(includes)
92 opts['exclude'].extend(excludes) 91 opts['exclude'].extend(excludes)
93 92
94 if opts_narrow: 93 if opts['narrow']:
95 def pullbundle2extraprepare_widen(orig, pullop, kwargs): 94 def pullbundle2extraprepare_widen(orig, pullop, kwargs):
96 # Create narrow spec patterns from clone flags 95 # Create narrow spec patterns from clone flags
97 includepats = narrowspec.parsepatterns(opts['include']) 96 includepats = narrowspec.parsepatterns(opts['include'])
98 excludepats = narrowspec.parsepatterns(opts['exclude']) 97 excludepats = narrowspec.parsepatterns(opts['exclude'])
99 98
112 kwargs['depth'] = opts['depth'] 111 kwargs['depth'] = opts['depth']
113 wrappedextraprepare = extensions.wrappedfunction(exchange, 112 wrappedextraprepare = extensions.wrappedfunction(exchange,
114 '_pullbundle2extraprepare', pullbundle2extraprepare_widen) 113 '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
115 114
116 def pullnarrow(orig, repo, *args, **kwargs): 115 def pullnarrow(orig, repo, *args, **kwargs):
117 if opts_narrow: 116 if opts['narrow']:
118 repo.requirements.add(repository.NARROW_REQUIREMENT) 117 repo.requirements.add(repository.NARROW_REQUIREMENT)
119 repo._writerequirements() 118 repo._writerequirements()
120 119
121 return orig(repo, *args, **kwargs) 120 return orig(repo, *args, **kwargs)
122 121