comparison mercurial/commands.py @ 33548:4cd4344a53c4

status: add a flag to terse the output (issue4119) This adds an experimental flag -t/--terse which will terse the output. The terse flag will respect other flags which filters the output. The flag takes a string whose value can be a subsequence of "marduic" (the order does not matter here.) Ignored files are not considered while tersing unless -i flag is passed or 'i' is there is the terse flag value. The flag is experimental for testing as there may be cases which will produce strange results with the flag. We can set the terse on by default by simply passing 'u' to the cmdutil.tersestatus(). This patch also adds a test file with tests covering the new feature.
author Pulkit Goyal <7895pulkit@gmail.com>
date Sat, 17 Jun 2017 20:10:22 +0530
parents 0407a51b9d8c
children 03039ff3082b cf0736696be0
comparison
equal deleted inserted replaced
33547:a6af8560494e 33548:4cd4344a53c4
4615 ('d', 'deleted', None, _('show only deleted (but tracked) files')), 4615 ('d', 'deleted', None, _('show only deleted (but tracked) files')),
4616 ('c', 'clean', None, _('show only files without changes')), 4616 ('c', 'clean', None, _('show only files without changes')),
4617 ('u', 'unknown', None, _('show only unknown (not tracked) files')), 4617 ('u', 'unknown', None, _('show only unknown (not tracked) files')),
4618 ('i', 'ignored', None, _('show only ignored files')), 4618 ('i', 'ignored', None, _('show only ignored files')),
4619 ('n', 'no-status', None, _('hide status prefix')), 4619 ('n', 'no-status', None, _('hide status prefix')),
4620 ('t', 'terse', '', _('show the terse output (EXPERIMENTAL)')),
4620 ('C', 'copies', None, _('show source of copied files')), 4621 ('C', 'copies', None, _('show source of copied files')),
4621 ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), 4622 ('0', 'print0', None, _('end filenames with NUL, for use with xargs')),
4622 ('', 'rev', [], _('show difference from revision'), _('REV')), 4623 ('', 'rev', [], _('show difference from revision'), _('REV')),
4623 ('', 'change', '', _('list the changed files of a revision'), _('REV')), 4624 ('', 'change', '', _('list the changed files of a revision'), _('REV')),
4624 ] + walkopts + subrepoopts + formatteropts, 4625 ] + walkopts + subrepoopts + formatteropts,
4660 I = ignored 4661 I = ignored
4661 = origin of the previous file (with --copies) 4662 = origin of the previous file (with --copies)
4662 4663
4663 .. container:: verbose 4664 .. container:: verbose
4664 4665
4666 The -t/--terse option abbreviates the output by showing directory name
4667 if all the files in it share the same status. The option expects a value
4668 which can be a string formed by using 'm', 'a', 'r', 'd', 'u', 'i', 'c'
4669 where, 'm' stands for 'modified', 'a' for 'added', 'r' for 'removed',
4670 'd' for 'deleted', 'u' for 'unknown', 'i' for 'ignored' and 'c' for clean.
4671
4672 It terses the output of only those status which are passed. The ignored
4673 files are not considered while tersing until 'i' is there in --terse value
4674 or the --ignored option is used.
4675
4665 Examples: 4676 Examples:
4666 4677
4667 - show changes in the working directory relative to a 4678 - show changes in the working directory relative to a
4668 changeset:: 4679 changeset::
4669 4680
4686 """ 4697 """
4687 4698
4688 opts = pycompat.byteskwargs(opts) 4699 opts = pycompat.byteskwargs(opts)
4689 revs = opts.get('rev') 4700 revs = opts.get('rev')
4690 change = opts.get('change') 4701 change = opts.get('change')
4702 terse = opts.get('terse')
4691 4703
4692 if revs and change: 4704 if revs and change:
4693 msg = _('cannot specify --rev and --change at the same time') 4705 msg = _('cannot specify --rev and --change at the same time')
4706 raise error.Abort(msg)
4707 elif revs and terse:
4708 msg = _('cannot use --terse with --rev')
4694 raise error.Abort(msg) 4709 raise error.Abort(msg)
4695 elif change: 4710 elif change:
4696 node2 = scmutil.revsingle(repo, change, None).node() 4711 node2 = scmutil.revsingle(repo, change, None).node()
4697 node1 = repo[node2].p1().node() 4712 node1 = repo[node2].p1().node()
4698 else: 4713 else:
4710 copy = {} 4725 copy = {}
4711 states = 'modified added removed deleted unknown ignored clean'.split() 4726 states = 'modified added removed deleted unknown ignored clean'.split()
4712 show = [k for k in states if opts.get(k)] 4727 show = [k for k in states if opts.get(k)]
4713 if opts.get('all'): 4728 if opts.get('all'):
4714 show += ui.quiet and (states[:4] + ['clean']) or states 4729 show += ui.quiet and (states[:4] + ['clean']) or states
4730
4715 if not show: 4731 if not show:
4716 if ui.quiet: 4732 if ui.quiet:
4717 show = states[:4] 4733 show = states[:4]
4718 else: 4734 else:
4719 show = states[:5] 4735 show = states[:5]
4720 4736
4721 m = scmutil.match(repo[node2], pats, opts) 4737 m = scmutil.match(repo[node2], pats, opts)
4722 stat = repo.status(node1, node2, m, 4738 stat = repo.status(node1, node2, m,
4723 'ignored' in show, 'clean' in show, 'unknown' in show, 4739 'ignored' in show, 'clean' in show, 'unknown' in show,
4724 opts.get('subrepos')) 4740 opts.get('subrepos'))
4741 if terse:
4742 stat = cmdutil.tersestatus(repo.root, stat, terse,
4743 repo.dirstate._ignore, opts.get('ignored'))
4725 changestates = zip(states, pycompat.iterbytestr('MAR!?IC'), stat) 4744 changestates = zip(states, pycompat.iterbytestr('MAR!?IC'), stat)
4726 4745
4727 if (opts.get('all') or opts.get('copies') 4746 if (opts.get('all') or opts.get('copies')
4728 or ui.configbool('ui', 'statuscopies')) and not opts.get('no_status'): 4747 or ui.configbool('ui', 'statuscopies')) and not opts.get('no_status'):
4729 copy = copies.pathcopies(repo[node1], repo[node2], m) 4748 copy = copies.pathcopies(repo[node1], repo[node2], m)