comparison hgext/narrow/narrowcommands.py @ 39440:ab20ee07b82d

narrow: add '--import-rules' flag to tracked command This patch adds a `--import-rules` flag to tracked command provided by narrow extension. Using the --import-rules flag, you can pass a filename from which narrowspecs should be read and added to main narrowspec. A lot of times, in automation or manually also, when you are working with big repo, specifying each path name on commandline using '--addinclude' and '--addexclude' is tedious and something which can scale. So we needed something where we can pass a file to extend the narrowspecs. Nice thing about this is that the automations which reads some file to change the sparse profile, can now read the same file for changing narrowspecs too. Tests are added for the new feature. Differential Revision: https://phab.mercurial-scm.org/D4125
author Pulkit Goyal <pulkit@yandex-team.ru>
date Mon, 06 Aug 2018 14:06:19 +0300
parents 2b8adb7ca39a
children 4062bbb1d10f
comparison
equal deleted inserted replaced
39439:dc61a67c1fc0 39440:ab20ee07b82d
12 from mercurial.i18n import _ 12 from mercurial.i18n import _
13 from mercurial import ( 13 from mercurial import (
14 cmdutil, 14 cmdutil,
15 commands, 15 commands,
16 discovery, 16 discovery,
17 encoding,
17 error, 18 error,
18 exchange, 19 exchange,
19 extensions, 20 extensions,
20 hg, 21 hg,
21 merge, 22 merge,
324 # TODO(rdamazio): Make new matcher format and update description 325 # TODO(rdamazio): Make new matcher format and update description
325 @command('tracked', 326 @command('tracked',
326 [('', 'addinclude', [], _('new paths to include')), 327 [('', 'addinclude', [], _('new paths to include')),
327 ('', 'removeinclude', [], _('old paths to no longer include')), 328 ('', 'removeinclude', [], _('old paths to no longer include')),
328 ('', 'addexclude', [], _('new paths to exclude')), 329 ('', 'addexclude', [], _('new paths to exclude')),
330 ('', 'import-rules', '', _('import narrowspecs from a file')),
329 ('', 'removeexclude', [], _('old paths to no longer exclude')), 331 ('', 'removeexclude', [], _('old paths to no longer exclude')),
330 ('', 'clear', False, _('whether to replace the existing narrowspec')), 332 ('', 'clear', False, _('whether to replace the existing narrowspec')),
331 ('', 'force-delete-local-changes', False, 333 ('', 'force-delete-local-changes', False,
332 _('forces deletion of local changes when narrowing')), 334 _('forces deletion of local changes when narrowing')),
333 ] + commands.remoteopts, 335 ] + commands.remoteopts,
366 # Before supporting, decide whether it "hg tracked --clear" should mean 368 # Before supporting, decide whether it "hg tracked --clear" should mean
367 # tracking no paths or all paths. 369 # tracking no paths or all paths.
368 if opts['clear']: 370 if opts['clear']:
369 ui.warn(_('The --clear option is not yet supported.\n')) 371 ui.warn(_('The --clear option is not yet supported.\n'))
370 return 1 372 return 1
373
374 # import rules from a file
375 newrules = opts.get('import_rules')
376 if newrules:
377 try:
378 filepath = os.path.join(pycompat.getcwd(), newrules)
379 fdata = util.readfile(filepath)
380 except IOError as inst:
381 raise error.Abort(_("cannot read narrowspecs from '%s': %s") %
382 (filepath, encoding.strtolocal(inst.strerror)))
383 includepats, excludepats, profiles = sparse.parseconfig(ui, fdata,
384 'narrow')
385 if profiles:
386 raise error.Abort(_("including other spec files using '%include' "
387 "is not supported in narrowspec"))
388 opts['addinclude'].extend(includepats)
389 opts['addexclude'].extend(excludepats)
371 390
372 if narrowspec.needsexpansion(opts['addinclude'] + opts['addexclude']): 391 if narrowspec.needsexpansion(opts['addinclude'] + opts['addexclude']):
373 raise error.Abort('Expansion not yet supported on widen/narrow') 392 raise error.Abort('Expansion not yet supported on widen/narrow')
374 393
375 addedincludes = narrowspec.parsepatterns(opts['addinclude']) 394 addedincludes = narrowspec.parsepatterns(opts['addinclude'])