diff --git a/hgext3rd/sparse.py b/hgext3rd/sparse.py --- a/hgext3rd/sparse.py +++ b/hgext3rd/sparse.py @@ -627,6 +627,7 @@ ('', 'clear-rules', False, _('clears local include/exclude rules')), ('', 'refresh', False, _('updates the working after sparseness changes')), ('', 'reset', False, _('makes the repo full again')), + ('', 'cwd-list', False, _('get contents of the current directory')), ] + commands.templateopts, _('[--OPTION] PATTERN...')) def sparse(ui, repo, *pats, **opts): @@ -668,6 +669,10 @@ --clear-rules removes all local include and exclude rules, while leaving any enabled profiles in place. + --cwd-list list all the contents of the current directory. The files + in the sparse profile are annotated with a hyphen ('-') before the + name. + The following config option defines whether sparse treats supplied paths as relative to repo root or to the current working dir for include and exclude options: @@ -694,8 +699,9 @@ delete = opts.get('delete') refresh = opts.get('refresh') reset = opts.get('reset') + cwdlist = opts.get('cwd_list') count = sum([include, exclude, enableprofile, disableprofile, delete, - importrules, refresh, clearrules, reset]) + importrules, refresh, clearrules, reset, cwdlist]) if count > 1: raise error.Abort(_("too many flags specified")) @@ -731,6 +737,9 @@ finally: wlock.release() + if cwdlist: + _cwdlist(repo) + def _config(ui, repo, pats, opts, include=False, exclude=False, reset=False, delete=False, enableprofile=False, disableprofile=False, force=False): @@ -1004,6 +1013,43 @@ fm.condwrite(ui.verbose, 'files_conflicting', 'Files conflicting: %d\n', lookup) +def _cwdlist(repo): + """ List the contents in the current directory. Annotate + the files in the sparse profile. + """ + ctx = repo['.'] + files = ctx.manifest() + cwd = os.getcwd() + cwd = util.normpath(cwd) + # Get the root of the repo so that we remove the content of + # the root from the current working directory + root = repo.root + if cwd.startswith(root): + cwd = cwd[len(root):] + else: + raise error.Abort(_("the current working directory should begin " + + "with the root %s"% root)) + cwd = cwd.strip("/") + sparsematch = repo.sparsematch(ctx.rev()) + checkedoutfolders = set() + allfolders = set() + cwdlength = len(cwd)+1 + for file in files: + if file.startswith(cwd): + tail = file[cwdlength:] if cwdlength > 1 else file + # tail = file[filelength:] + foldername = tail.split('/')[0] + if sparsematch(file): + # A set of all the folders in the current directory + # in the checkout + checkedoutfolders.add(foldername) + # A set of all folders in the current directory + allfolders.add(foldername) + + for folder in sorted(allfolders): + marker = ' ' if folder in checkedoutfolders else '-' + repo.ui.status("%s %s\n" % (marker, folder)) + class forceincludematcher(object): """A matcher that returns true for any of the forced includes before testing against the actual matcher."""