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-find', False, _('get contents of the current directory')), ] + commands.templateopts, _('[--OPTION] PATTERN...')) def sparse(ui, repo, *pats, **opts): @@ -668,6 +669,9 @@ --clear-rules removes all local include and exclude rules, while leaving any enabled profiles in place. + --cwd-find list all the contents of the current directory. The files + in the sparse profile are annotated and others are not. + 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 +698,9 @@ delete = opts.get('delete') refresh = opts.get('refresh') reset = opts.get('reset') + cwdfind = opts.get('cwd_find') count = sum([include, exclude, enableprofile, disableprofile, delete, - importrules, refresh, clearrules, reset]) + importrules, refresh, clearrules, reset, cwdfind]) if count > 1: raise error.Abort(_("too many flags specified")) @@ -731,6 +736,9 @@ finally: wlock.release() + if cwdfind: + _cwd_find(repo) + def _config(ui, repo, pats, opts, include=False, exclude=False, reset=False, delete=False, enableprofile=False, disableprofile=False, force=False): @@ -1004,6 +1012,44 @@ fm.condwrite(ui.verbose, 'files_conflicting', 'Files conflicting: %d\n', lookup) +def _cwd_find(repo): + """ List the contents in the current directory. Annotate + the files in the sparse profile. + """ + ctx = repo['.'] + mf = ctx.manifest() + files = set(mf) + cwd = os.getcwd() + # Get the root of the repo. + 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()) + checkedout_folders = set() + all_folders = set() + for file in files: + if file.startswith(cwd): + # Remove the characters in cwd from the file. + # Also, remove the leading slash + tail = file[len(cwd)+1:] + folder_name = tail.split('/')[0] + if sparsematch(file): + # A set of all the folders in the current directory + # in the checkout + checkedout_folders.add(folder_name) + # A set of all folders in the current directory + all_folders.add(folder_name) + + for folder in all_folders: + if folder in checkedout_folders: + repo.ui.status("%s\n" % folder) + else: + repo.ui.status("- %s\n" % folder) + class forceincludematcher(object): """A matcher that returns true for any of the forced includes before testing against the actual matcher."""