comparison mercurial/commands.py @ 21778:f6a6d07b66b3

commands: define inferrepo in command decorator
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 04 May 2014 22:22:59 -0700
parents 5403245edb3a
children 15baed3f24ee
comparison
equal deleted inserted replaced
21777:17d1ac452127 21778:f6a6d07b66b3
31 norepo = '' 31 norepo = ''
32 # Space delimited list of commands that optionally require local repositories. 32 # Space delimited list of commands that optionally require local repositories.
33 # This should be populated by passing optionalrepo=True into the @command 33 # This should be populated by passing optionalrepo=True into the @command
34 # decorator. 34 # decorator.
35 optionalrepo = '' 35 optionalrepo = ''
36 inferrepo = ("add addremove annotate cat commit diff grep forget log parents" 36 # Space delimited list of commands that will examine arguments looking for
37 " remove resolve status debugwalk") 37 # a repository. This should be populated by passing inferrepo=True into the
38 # @command decorator.
39 inferrepo = ''
40
38 # common command options 41 # common command options
39 42
40 globalopts = [ 43 globalopts = [
41 ('R', 'repository', '', 44 ('R', 'repository', '',
42 _('repository root directory or name of overlay bundle file'), 45 _('repository root directory or name of overlay bundle file'),
154 157
155 # Commands start here, listed alphabetically 158 # Commands start here, listed alphabetically
156 159
157 @command('^add', 160 @command('^add',
158 walkopts + subrepoopts + dryrunopts, 161 walkopts + subrepoopts + dryrunopts,
159 _('[OPTION]... [FILE]...')) 162 _('[OPTION]... [FILE]...'),
163 inferrepo=True)
160 def add(ui, repo, *pats, **opts): 164 def add(ui, repo, *pats, **opts):
161 """add the specified files on the next commit 165 """add the specified files on the next commit
162 166
163 Schedule files to be version controlled and added to the 167 Schedule files to be version controlled and added to the
164 repository. 168 repository.
190 opts.get('subrepos'), prefix="", explicitonly=False) 194 opts.get('subrepos'), prefix="", explicitonly=False)
191 return rejected and 1 or 0 195 return rejected and 1 or 0
192 196
193 @command('addremove', 197 @command('addremove',
194 similarityopts + walkopts + dryrunopts, 198 similarityopts + walkopts + dryrunopts,
195 _('[OPTION]... [FILE]...')) 199 _('[OPTION]... [FILE]...'),
200 inferrepo=True)
196 def addremove(ui, repo, *pats, **opts): 201 def addremove(ui, repo, *pats, **opts):
197 """add all new files, delete all missing files 202 """add all new files, delete all missing files
198 203
199 Add all new files and remove all missing files from the 204 Add all new files and remove all missing files from the
200 repository. 205 repository.
234 ('d', 'date', None, _('list the date (short with -q)')), 239 ('d', 'date', None, _('list the date (short with -q)')),
235 ('n', 'number', None, _('list the revision number (default)')), 240 ('n', 'number', None, _('list the revision number (default)')),
236 ('c', 'changeset', None, _('list the changeset')), 241 ('c', 'changeset', None, _('list the changeset')),
237 ('l', 'line-number', None, _('show line number at the first appearance')) 242 ('l', 'line-number', None, _('show line number at the first appearance'))
238 ] + diffwsopts + walkopts, 243 ] + diffwsopts + walkopts,
239 _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...')) 244 _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'),
245 inferrepo=True)
240 def annotate(ui, repo, *pats, **opts): 246 def annotate(ui, repo, *pats, **opts):
241 """show changeset information by line for each file 247 """show changeset information by line for each file
242 248
243 List changes in files, showing the revision id responsible for 249 List changes in files, showing the revision id responsible for
244 each line 250 each line
1176 [('o', 'output', '', 1182 [('o', 'output', '',
1177 _('print output to file with formatted name'), _('FORMAT')), 1183 _('print output to file with formatted name'), _('FORMAT')),
1178 ('r', 'rev', '', _('print the given revision'), _('REV')), 1184 ('r', 'rev', '', _('print the given revision'), _('REV')),
1179 ('', 'decode', None, _('apply any matching decode filter')), 1185 ('', 'decode', None, _('apply any matching decode filter')),
1180 ] + walkopts, 1186 ] + walkopts,
1181 _('[OPTION]... FILE...')) 1187 _('[OPTION]... FILE...'),
1188 inferrepo=True)
1182 def cat(ui, repo, file1, *pats, **opts): 1189 def cat(ui, repo, file1, *pats, **opts):
1183 """output the current or given revision of files 1190 """output the current or given revision of files
1184 1191
1185 Print the specified files as they were at the given revision. If 1192 Print the specified files as they were at the given revision. If
1186 no revision is given, the parent of the working directory is used. 1193 no revision is given, the parent of the working directory is used.
1332 ('', 'amend', None, _('amend the parent of the working dir')), 1339 ('', 'amend', None, _('amend the parent of the working dir')),
1333 ('s', 'secret', None, _('use the secret phase for committing')), 1340 ('s', 'secret', None, _('use the secret phase for committing')),
1334 ('e', 'edit', None, 1341 ('e', 'edit', None,
1335 _('further edit commit message already specified')), 1342 _('further edit commit message already specified')),
1336 ] + walkopts + commitopts + commitopts2 + subrepoopts, 1343 ] + walkopts + commitopts + commitopts2 + subrepoopts,
1337 _('[OPTION]... [FILE]...')) 1344 _('[OPTION]... [FILE]...'),
1345 inferrepo=True)
1338 def commit(ui, repo, *pats, **opts): 1346 def commit(ui, repo, *pats, **opts):
1339 """commit the specified files or all outstanding changes 1347 """commit the specified files or all outstanding changes
1340 1348
1341 Commit changes to the given files into the repository. Unlike a 1349 Commit changes to the given files into the repository. Unlike a
1342 centralized SCM, this operation is a local operation. See 1350 centralized SCM, this operation is a local operation. See
2796 for node in succsset[1:]: 2804 for node in succsset[1:]:
2797 ui.write(' ') 2805 ui.write(' ')
2798 ui.write(node2str(node)) 2806 ui.write(node2str(node))
2799 ui.write('\n') 2807 ui.write('\n')
2800 2808
2801 @command('debugwalk', walkopts, _('[OPTION]... [FILE]...')) 2809 @command('debugwalk', walkopts, _('[OPTION]... [FILE]...'), inferrepo=True)
2802 def debugwalk(ui, repo, *pats, **opts): 2810 def debugwalk(ui, repo, *pats, **opts):
2803 """show how files match on given patterns""" 2811 """show how files match on given patterns"""
2804 m = scmutil.match(repo[None], pats, opts) 2812 m = scmutil.match(repo[None], pats, opts)
2805 items = list(repo.walk(m)) 2813 items = list(repo.walk(m))
2806 if not items: 2814 if not items:
2839 2847
2840 @command('^diff', 2848 @command('^diff',
2841 [('r', 'rev', [], _('revision'), _('REV')), 2849 [('r', 'rev', [], _('revision'), _('REV')),
2842 ('c', 'change', '', _('change made by revision'), _('REV')) 2850 ('c', 'change', '', _('change made by revision'), _('REV'))
2843 ] + diffopts + diffopts2 + walkopts + subrepoopts, 2851 ] + diffopts + diffopts2 + walkopts + subrepoopts,
2844 _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...')) 2852 _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...'),
2853 inferrepo=True)
2845 def diff(ui, repo, *pats, **opts): 2854 def diff(ui, repo, *pats, **opts):
2846 """diff repository (or selected files) 2855 """diff repository (or selected files)
2847 2856
2848 Show differences between revisions for the specified files. 2857 Show differences between revisions for the specified files.
2849 2858
3001 ui.note(_('exporting patch:\n')) 3010 ui.note(_('exporting patch:\n'))
3002 cmdutil.export(repo, revs, template=opts.get('output'), 3011 cmdutil.export(repo, revs, template=opts.get('output'),
3003 switch_parent=opts.get('switch_parent'), 3012 switch_parent=opts.get('switch_parent'),
3004 opts=patch.diffopts(ui, opts)) 3013 opts=patch.diffopts(ui, opts))
3005 3014
3006 @command('^forget', walkopts, _('[OPTION]... FILE...')) 3015 @command('^forget', walkopts, _('[OPTION]... FILE...'), inferrepo=True)
3007 def forget(ui, repo, *pats, **opts): 3016 def forget(ui, repo, *pats, **opts):
3008 """forget the specified files on the next commit 3017 """forget the specified files on the next commit
3009 3018
3010 Mark the specified files so they will no longer be tracked 3019 Mark the specified files so they will no longer be tracked
3011 after the next commit. 3020 after the next commit.
3266 ('r', 'rev', [], 3275 ('r', 'rev', [],
3267 _('only search files changed within revision range'), _('REV')), 3276 _('only search files changed within revision range'), _('REV')),
3268 ('u', 'user', None, _('list the author (long with -v)')), 3277 ('u', 'user', None, _('list the author (long with -v)')),
3269 ('d', 'date', None, _('list the date (short with -q)')), 3278 ('d', 'date', None, _('list the date (short with -q)')),
3270 ] + walkopts, 3279 ] + walkopts,
3271 _('[OPTION]... PATTERN [FILE]...')) 3280 _('[OPTION]... PATTERN [FILE]...'),
3281 inferrepo=True)
3272 def grep(ui, repo, pattern, *pats, **opts): 3282 def grep(ui, repo, pattern, *pats, **opts):
3273 """search for a pattern in specified files and revisions 3283 """search for a pattern in specified files and revisions
3274 3284
3275 Search revisions of files for a regular expression. 3285 Search revisions of files for a regular expression.
3276 3286
4045 ('b', 'branch', [], 4055 ('b', 'branch', [],
4046 _('show changesets within the given named branch'), _('BRANCH')), 4056 _('show changesets within the given named branch'), _('BRANCH')),
4047 ('P', 'prune', [], 4057 ('P', 'prune', [],
4048 _('do not display revision or any of its ancestors'), _('REV')), 4058 _('do not display revision or any of its ancestors'), _('REV')),
4049 ] + logopts + walkopts, 4059 ] + logopts + walkopts,
4050 _('[OPTION]... [FILE]')) 4060 _('[OPTION]... [FILE]'),
4061 inferrepo=True)
4051 def log(ui, repo, *pats, **opts): 4062 def log(ui, repo, *pats, **opts):
4052 """show revision history of entire repository or files 4063 """show revision history of entire repository or files
4053 4064
4054 Print the revision history of the specified files or the entire 4065 Print the revision history of the specified files or the entire
4055 project. 4066 project.
4403 del repo._subtoppath 4414 del repo._subtoppath
4404 4415
4405 @command('parents', 4416 @command('parents',
4406 [('r', 'rev', '', _('show parents of the specified revision'), _('REV')), 4417 [('r', 'rev', '', _('show parents of the specified revision'), _('REV')),
4407 ] + templateopts, 4418 ] + templateopts,
4408 _('[-r REV] [FILE]')) 4419 _('[-r REV] [FILE]'),
4420 inferrepo=True)
4409 def parents(ui, repo, file_=None, **opts): 4421 def parents(ui, repo, file_=None, **opts):
4410 """show the parents of the working directory or revision 4422 """show the parents of the working directory or revision
4411 4423
4412 Print the working directory's parent revisions. If a revision is 4424 Print the working directory's parent revisions. If a revision is
4413 given via -r/--rev, the parent of that revision will be printed. 4425 given via -r/--rev, the parent of that revision will be printed.
4800 @command('^remove|rm', 4812 @command('^remove|rm',
4801 [('A', 'after', None, _('record delete for missing files')), 4813 [('A', 'after', None, _('record delete for missing files')),
4802 ('f', 'force', None, 4814 ('f', 'force', None,
4803 _('remove (and delete) file even if added or modified')), 4815 _('remove (and delete) file even if added or modified')),
4804 ] + walkopts, 4816 ] + walkopts,
4805 _('[OPTION]... FILE...')) 4817 _('[OPTION]... FILE...'),
4818 inferrepo=True)
4806 def remove(ui, repo, *pats, **opts): 4819 def remove(ui, repo, *pats, **opts):
4807 """remove the specified files on the next commit 4820 """remove the specified files on the next commit
4808 4821
4809 Schedule the indicated files for removal from the current branch. 4822 Schedule the indicated files for removal from the current branch.
4810 4823
4929 ('l', 'list', None, _('list state of files needing merge')), 4942 ('l', 'list', None, _('list state of files needing merge')),
4930 ('m', 'mark', None, _('mark files as resolved')), 4943 ('m', 'mark', None, _('mark files as resolved')),
4931 ('u', 'unmark', None, _('mark files as unresolved')), 4944 ('u', 'unmark', None, _('mark files as unresolved')),
4932 ('n', 'no-status', None, _('hide status prefix'))] 4945 ('n', 'no-status', None, _('hide status prefix'))]
4933 + mergetoolopts + walkopts, 4946 + mergetoolopts + walkopts,
4934 _('[OPTION]... [FILE]...')) 4947 _('[OPTION]... [FILE]...'),
4948 inferrepo=True)
4935 def resolve(ui, repo, *pats, **opts): 4949 def resolve(ui, repo, *pats, **opts):
4936 """redo merges or set/view the merge status of files 4950 """redo merges or set/view the merge status of files
4937 4951
4938 Merges with unresolved conflicts are often the result of 4952 Merges with unresolved conflicts are often the result of
4939 non-interactive merging using the ``internal:merge`` configuration 4953 non-interactive merging using the ``internal:merge`` configuration
5325 ('C', 'copies', None, _('show source of copied files')), 5339 ('C', 'copies', None, _('show source of copied files')),
5326 ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), 5340 ('0', 'print0', None, _('end filenames with NUL, for use with xargs')),
5327 ('', 'rev', [], _('show difference from revision'), _('REV')), 5341 ('', 'rev', [], _('show difference from revision'), _('REV')),
5328 ('', 'change', '', _('list the changed files of a revision'), _('REV')), 5342 ('', 'change', '', _('list the changed files of a revision'), _('REV')),
5329 ] + walkopts + subrepoopts, 5343 ] + walkopts + subrepoopts,
5330 _('[OPTION]... [FILE]...')) 5344 _('[OPTION]... [FILE]...'),
5345 inferrepo=True)
5331 def status(ui, repo, *pats, **opts): 5346 def status(ui, repo, *pats, **opts):
5332 """show changed files in the working directory 5347 """show changed files in the working directory
5333 5348
5334 Show status of files in the repository. If names are given, only 5349 Show status of files in the repository. If names are given, only
5335 files that match are shown. Files that are clean or ignored or 5350 files that match are shown. Files that are clean or ignored or