diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -3061,6 +3061,81 @@ def export(ui, repo, *changesets, **opts switch_parent=opts.get('switch_parent'), opts=patch.diffopts(ui, opts)) +@command('files', + [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), + ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), + ] + walkopts, + _('[OPTION]... [PATTERN]...')) +def files(ui, repo, *pats, **opts): + """list tracked files + + Print files under Mercurial control in the working directory or + specified revision whose names match the given patterns (excluding + removed files). + + If no patterns are given to match, this command prints the names + of all files under Mercurial control in the working copy. + + .. container:: verbose + + Examples: + + - list all files under the current directory:: + + hg files . + + - shows sizes and flags for current revision:: + + hg files -vr . + + - list all files named README:: + + hg files -I "**/README" + + - list all binary files:: + + hg files "set:binary()" + + - find files containing a regular expression: + + hg files "set:grep('bob')" + + - search tracked file contents with xargs and grep:: + + hg files -0 | xargs -0 grep foo + + See :hg:'help pattern' and :hg:'help revsets' for more information + on specifying file patterns. + + Returns 0 if a match is found, 1 otherwise. + + """ + ctx = scmutil.revsingle(repo, opts.get('rev'), None) + rev = ctx.rev() + ret = 1 + + end = '\n' + if opts.get('print0'): + end = '\0' + fm = ui.formatter('status', opts) + fmt = '%s' + end + + m = scmutil.match(ctx, pats, opts) + for f in ctx.walk(m): + if rev is None and repo.dirstate[f] in 'R?!': + continue + fm.startitem() + if ui.verbose: + fc = ctx[f] + fm.write('size flags', '% 10d % 1s ', fc.size(), fc.flags()) + fm.data(abspath=f) + fm.write('path', fmt, m.rel(f)) + ret = 0 + + fm.end() + + return ret + @command('^forget', walkopts, _('[OPTION]... FILE...'), inferrepo=True) def forget(ui, repo, *pats, **opts): """forget the specified files on the next commit diff --git a/tests/test-completion.t b/tests/test-completion.t --- a/tests/test-completion.t +++ b/tests/test-completion.t @@ -17,6 +17,7 @@ Show all commands except debug commands copy diff export + files forget graft grep @@ -257,6 +258,7 @@ Show all commands + options debugsuccessorssets: debugwalk: include, exclude debugwireargs: three, four, five, ssh, remotecmd, insecure + files: rev, print0, include, exclude graft: rev, continue, edit, log, force, currentdate, currentuser, date, user, tool, dry-run grep: print0, all, text, follow, ignore-case, files-with-matches, line-number, rev, user, date, include, exclude heads: rev, topo, active, closed, style, template diff --git a/tests/test-globalopts.t b/tests/test-globalopts.t --- a/tests/test-globalopts.t +++ b/tests/test-globalopts.t @@ -301,6 +301,7 @@ Testing -h/--help: copy mark files as copied for the next commit diff diff repository (or selected files) export dump the header and diffs for one or more changesets + files list tracked files forget forget the specified files on the next commit graft copy changes from other branches onto the current branch grep search for a pattern in specified files and revisions @@ -383,6 +384,7 @@ Testing -h/--help: copy mark files as copied for the next commit diff diff repository (or selected files) export dump the header and diffs for one or more changesets + files list tracked files forget forget the specified files on the next commit graft copy changes from other branches onto the current branch grep search for a pattern in specified files and revisions diff --git a/tests/test-help.t b/tests/test-help.t --- a/tests/test-help.t +++ b/tests/test-help.t @@ -66,6 +66,7 @@ Short help: copy mark files as copied for the next commit diff diff repository (or selected files) export dump the header and diffs for one or more changesets + files list tracked files forget forget the specified files on the next commit graft copy changes from other branches onto the current branch grep search for a pattern in specified files and revisions @@ -142,6 +143,7 @@ Short help: copy mark files as copied for the next commit diff diff repository (or selected files) export dump the header and diffs for one or more changesets + files list tracked files forget forget the specified files on the next commit graft copy changes from other branches onto the current branch grep search for a pattern in specified files and revisions @@ -684,6 +686,7 @@ Test that default list of commands omits copy mark files as copied for the next commit diff diff repository (or selected files) export dump the header and diffs for one or more changesets + files list tracked files forget forget the specified files on the next commit graft copy changes from other branches onto the current branch grep search for a pattern in specified files and revisions @@ -1444,6 +1447,13 @@ Dish up an empty repo; serve it cold. mark files as copied for the next commit + + files + + + list tracked files + + graft diff --git a/tests/test-locate.t b/tests/test-locate.t --- a/tests/test-locate.t +++ b/tests/test-locate.t @@ -92,6 +92,16 @@ Issue294: hg remove --after dir fails wh t/e.h (glob) t/x (glob) + $ hg files + b + dir.h/foo + t.h + t/b + t/e.h + t/x + $ hg files b + b + $ mkdir otherdir $ cd otherdir diff --git a/tests/test-manifest.t b/tests/test-manifest.t --- a/tests/test-manifest.t +++ b/tests/test-manifest.t @@ -24,6 +24,14 @@ The next call is expected to return noth b/a l + $ hg files -vr . + 2 a + 2 x b/a + 1 l l + $ hg files -r . -X b + a + l + $ hg manifest -v 644 a 755 * b/a