hgext/sparse.py
changeset 48747 a6efb9180764
parent 47945 8e46934c58d2
child 48966 6000f5b25c9b
equal deleted inserted replaced
48746:fd2cf9e0c64e 48747:a6efb9180764
    74 from __future__ import absolute_import
    74 from __future__ import absolute_import
    75 
    75 
    76 from mercurial.i18n import _
    76 from mercurial.i18n import _
    77 from mercurial.pycompat import setattr
    77 from mercurial.pycompat import setattr
    78 from mercurial import (
    78 from mercurial import (
       
    79     cmdutil,
    79     commands,
    80     commands,
    80     dirstate,
    81     dirstate,
    81     error,
    82     error,
    82     extensions,
    83     extensions,
    83     logcmdutil,
    84     logcmdutil,
   151 
   152 
   152     extensions.wrapfunction(logcmdutil, b'_initialrevs', _initialrevs)
   153     extensions.wrapfunction(logcmdutil, b'_initialrevs', _initialrevs)
   153 
   154 
   154 
   155 
   155 def _clonesparsecmd(orig, ui, repo, *args, **opts):
   156 def _clonesparsecmd(orig, ui, repo, *args, **opts):
   156     include_pat = opts.get('include')
   157     include = opts.get('include')
   157     exclude_pat = opts.get('exclude')
   158     exclude = opts.get('exclude')
   158     enableprofile_pat = opts.get('enable_profile')
   159     enableprofile = opts.get('enable_profile')
   159     narrow_pat = opts.get('narrow')
   160     narrow_pat = opts.get('narrow')
   160     include = exclude = enableprofile = False
   161 
   161     if include_pat:
       
   162         pat = include_pat
       
   163         include = True
       
   164     if exclude_pat:
       
   165         pat = exclude_pat
       
   166         exclude = True
       
   167     if enableprofile_pat:
       
   168         pat = enableprofile_pat
       
   169         enableprofile = True
       
   170     if sum([include, exclude, enableprofile]) > 1:
       
   171         raise error.Abort(_(b"too many flags specified."))
       
   172     # if --narrow is passed, it means they are includes and excludes for narrow
   162     # if --narrow is passed, it means they are includes and excludes for narrow
   173     # clone
   163     # clone
   174     if not narrow_pat and (include or exclude or enableprofile):
   164     if not narrow_pat and (include or exclude or enableprofile):
   175 
   165 
   176         def clonesparse(orig, ctx, *args, **kwargs):
   166         def clonesparse(orig, ctx, *args, **kwargs):
   177             sparse.updateconfig(
   167             sparse.updateconfig(
   178                 ctx.repo().unfiltered(),
   168                 ctx.repo().unfiltered(),
   179                 pat,
       
   180                 {},
   169                 {},
   181                 include=include,
   170                 include=include,
   182                 exclude=exclude,
   171                 exclude=exclude,
   183                 enableprofile=enableprofile,
   172                 enableprofile=enableprofile,
   184                 usereporootpaths=True,
   173                 usereporootpaths=True,
   212         if opts.get('sparse'):
   201         if opts.get('sparse'):
   213             dirs = set()
   202             dirs = set()
   214             for pat in pats:
   203             for pat in pats:
   215                 dirname, basename = util.split(pat)
   204                 dirname, basename = util.split(pat)
   216                 dirs.add(dirname)
   205                 dirs.add(dirname)
   217             sparse.updateconfig(repo, list(dirs), opts, include=True)
   206             sparse.updateconfig(repo, opts, include=list(dirs))
   218         return orig(ui, repo, *pats, **opts)
   207         return orig(ui, repo, *pats, **opts)
   219 
   208 
   220     extensions.wrapcommand(commands.table, b'add', _add)
   209     extensions.wrapcommand(commands.table, b'add', _add)
   221 
   210 
   222 
   211 
   284 
   273 
   285 
   274 
   286 @command(
   275 @command(
   287     b'debugsparse',
   276     b'debugsparse',
   288     [
   277     [
   289         (b'I', b'include', False, _(b'include files in the sparse checkout')),
   278         (
   290         (b'X', b'exclude', False, _(b'exclude files in the sparse checkout')),
   279             b'I',
   291         (b'd', b'delete', False, _(b'delete an include/exclude rule')),
   280             b'include',
       
   281             [],
       
   282             _(b'include files in the sparse checkout'),
       
   283             _(b'PATTERN'),
       
   284         ),
       
   285         (
       
   286             b'X',
       
   287             b'exclude',
       
   288             [],
       
   289             _(b'exclude files in the sparse checkout'),
       
   290             _(b'PATTERN'),
       
   291         ),
       
   292         (
       
   293             b'd',
       
   294             b'delete',
       
   295             [],
       
   296             _(b'delete an include/exclude rule'),
       
   297             _(b'PATTERN'),
       
   298         ),
   292         (
   299         (
   293             b'f',
   300             b'f',
   294             b'force',
   301             b'force',
   295             False,
   302             False,
   296             _(b'allow changing rules even with pending changes'),
   303             _(b'allow changing rules even with pending changes'),
   297         ),
   304         ),
   298         (b'', b'enable-profile', False, _(b'enables the specified profile')),
   305         (
   299         (b'', b'disable-profile', False, _(b'disables the specified profile')),
   306             b'',
   300         (b'', b'import-rules', False, _(b'imports rules from a file')),
   307             b'enable-profile',
       
   308             [],
       
   309             _(b'enables the specified profile'),
       
   310             _(b'PATTERN'),
       
   311         ),
       
   312         (
       
   313             b'',
       
   314             b'disable-profile',
       
   315             [],
       
   316             _(b'disables the specified profile'),
       
   317             _(b'PATTERN'),
       
   318         ),
       
   319         (
       
   320             b'',
       
   321             b'import-rules',
       
   322             [],
       
   323             _(b'imports rules from a file'),
       
   324             _(b'PATTERN'),
       
   325         ),
   301         (b'', b'clear-rules', False, _(b'clears local include/exclude rules')),
   326         (b'', b'clear-rules', False, _(b'clears local include/exclude rules')),
   302         (
   327         (
   303             b'',
   328             b'',
   304             b'refresh',
   329             b'refresh',
   305             False,
   330             False,
   306             _(b'updates the working after sparseness changes'),
   331             _(b'updates the working after sparseness changes'),
   307         ),
   332         ),
   308         (b'', b'reset', False, _(b'makes the repo full again')),
   333         (b'', b'reset', False, _(b'makes the repo full again')),
   309     ]
   334     ]
   310     + commands.templateopts,
   335     + commands.templateopts,
   311     _(b'[--OPTION] PATTERN...'),
   336     _(b'[--OPTION]'),
   312     helpbasic=True,
   337     helpbasic=True,
   313 )
   338 )
   314 def debugsparse(ui, repo, *pats, **opts):
   339 def debugsparse(ui, repo, **opts):
   315     """make the current checkout sparse, or edit the existing checkout
   340     """make the current checkout sparse, or edit the existing checkout
   316 
   341 
   317     The sparse command is used to make the current checkout sparse.
   342     The sparse command is used to make the current checkout sparse.
   318     This means files that don't meet the sparse condition will not be
   343     This means files that don't meet the sparse condition will not be
   319     written to disk, or show up in any working copy operations. It does
   344     written to disk, or show up in any working copy operations. It does
   361     importrules = opts.get(b'import_rules')
   386     importrules = opts.get(b'import_rules')
   362     clearrules = opts.get(b'clear_rules')
   387     clearrules = opts.get(b'clear_rules')
   363     delete = opts.get(b'delete')
   388     delete = opts.get(b'delete')
   364     refresh = opts.get(b'refresh')
   389     refresh = opts.get(b'refresh')
   365     reset = opts.get(b'reset')
   390     reset = opts.get(b'reset')
   366     count = sum(
   391     action = cmdutil.check_at_most_one_arg(
   367         [
   392         opts, b'import_rules', b'clear_rules', b'refresh'
   368             include,
       
   369             exclude,
       
   370             enableprofile,
       
   371             disableprofile,
       
   372             delete,
       
   373             importrules,
       
   374             refresh,
       
   375             clearrules,
       
   376             reset,
       
   377         ]
       
   378     )
   393     )
       
   394     updateconfig = bool(
       
   395         include or exclude or delete or reset or enableprofile or disableprofile
       
   396     )
       
   397     count = sum([updateconfig, bool(action)])
   379     if count > 1:
   398     if count > 1:
   380         raise error.Abort(_(b"too many flags specified"))
   399         raise error.Abort(_(b"too many flags specified"))
   381 
   400 
   382     if count == 0:
   401     if count == 0:
   383         if repo.vfs.exists(b'sparse'):
   402         if repo.vfs.exists(b'sparse'):
   395                     b'the debugsparse command is only supported on'
   414                     b'the debugsparse command is only supported on'
   396                     b' sparse repositories'
   415                     b' sparse repositories'
   397                 )
   416                 )
   398             )
   417             )
   399 
   418 
   400     if include or exclude or delete or reset or enableprofile or disableprofile:
   419     if updateconfig:
   401         sparse.updateconfig(
   420         sparse.updateconfig(
   402             repo,
   421             repo,
   403             pats,
       
   404             opts,
   422             opts,
   405             include=include,
   423             include=include,
   406             exclude=exclude,
   424             exclude=exclude,
   407             reset=reset,
   425             reset=reset,
   408             delete=delete,
   426             delete=delete,
   410             disableprofile=disableprofile,
   428             disableprofile=disableprofile,
   411             force=force,
   429             force=force,
   412         )
   430         )
   413 
   431 
   414     if importrules:
   432     if importrules:
   415         sparse.importfromfiles(repo, opts, pats, force=force)
   433         sparse.importfromfiles(repo, opts, importrules, force=force)
   416 
   434 
   417     if clearrules:
   435     if clearrules:
   418         sparse.clearrules(repo, force=force)
   436         sparse.clearrules(repo, force=force)
   419 
   437 
   420     if refresh:
   438     if refresh: