comparison mercurial/commands.py @ 22423:edf07a804ac4

files: add new command unifying locate and manifest functionality
author Matt Mackall <mpm@selenic.com>
date Fri, 12 Sep 2014 18:32:46 -0500
parents fdfc9faca273
children 7a7eed5176a4
comparison
equal deleted inserted replaced
22422:75bb7c702317 22423:edf07a804ac4
3059 ui.note(_('exporting patch:\n')) 3059 ui.note(_('exporting patch:\n'))
3060 cmdutil.export(repo, revs, template=opts.get('output'), 3060 cmdutil.export(repo, revs, template=opts.get('output'),
3061 switch_parent=opts.get('switch_parent'), 3061 switch_parent=opts.get('switch_parent'),
3062 opts=patch.diffopts(ui, opts)) 3062 opts=patch.diffopts(ui, opts))
3063 3063
3064 @command('files',
3065 [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')),
3066 ('0', 'print0', None, _('end filenames with NUL, for use with xargs')),
3067 ] + walkopts,
3068 _('[OPTION]... [PATTERN]...'))
3069 def files(ui, repo, *pats, **opts):
3070 """list tracked files
3071
3072 Print files under Mercurial control in the working directory or
3073 specified revision whose names match the given patterns (excluding
3074 removed files).
3075
3076 If no patterns are given to match, this command prints the names
3077 of all files under Mercurial control in the working copy.
3078
3079 .. container:: verbose
3080
3081 Examples:
3082
3083 - list all files under the current directory::
3084
3085 hg files .
3086
3087 - shows sizes and flags for current revision::
3088
3089 hg files -vr .
3090
3091 - list all files named README::
3092
3093 hg files -I "**/README"
3094
3095 - list all binary files::
3096
3097 hg files "set:binary()"
3098
3099 - find files containing a regular expression:
3100
3101 hg files "set:grep('bob')"
3102
3103 - search tracked file contents with xargs and grep::
3104
3105 hg files -0 | xargs -0 grep foo
3106
3107 See :hg:'help pattern' and :hg:'help revsets' for more information
3108 on specifying file patterns.
3109
3110 Returns 0 if a match is found, 1 otherwise.
3111
3112 """
3113 ctx = scmutil.revsingle(repo, opts.get('rev'), None)
3114 rev = ctx.rev()
3115 ret = 1
3116
3117 end = '\n'
3118 if opts.get('print0'):
3119 end = '\0'
3120 fm = ui.formatter('status', opts)
3121 fmt = '%s' + end
3122
3123 m = scmutil.match(ctx, pats, opts)
3124 for f in ctx.walk(m):
3125 if rev is None and repo.dirstate[f] in 'R?!':
3126 continue
3127 fm.startitem()
3128 if ui.verbose:
3129 fc = ctx[f]
3130 fm.write('size flags', '% 10d % 1s ', fc.size(), fc.flags())
3131 fm.data(abspath=f)
3132 fm.write('path', fmt, m.rel(f))
3133 ret = 0
3134
3135 fm.end()
3136
3137 return ret
3138
3064 @command('^forget', walkopts, _('[OPTION]... FILE...'), inferrepo=True) 3139 @command('^forget', walkopts, _('[OPTION]... FILE...'), inferrepo=True)
3065 def forget(ui, repo, *pats, **opts): 3140 def forget(ui, repo, *pats, **opts):
3066 """forget the specified files on the next commit 3141 """forget the specified files on the next commit
3067 3142
3068 Mark the specified files so they will no longer be tracked 3143 Mark the specified files so they will no longer be tracked