From patchwork Wed Mar 25 05:46:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2,of,2] status: add terse option flag (issue4119) From: Sean Farley X-Patchwork-Id: 8257 Message-Id: <1fc4b58112600db90c71.1427262417@1.0.0.127.in-addr.arpa> To: mercurial-devel@selenic.com Date: Tue, 24 Mar 2015 22:46:57 -0700 # HG changeset patch # User Sean Farley # Date 1427261050 25200 # Tue Mar 24 22:24:10 2015 -0700 # Node ID 1fc4b58112600db90c710f32a3ec6f5c4438d5df # Parent f9e43618a84b4ce1de23c8cdf22de5e9bcadafdd status: add terse option flag (issue4119) Based on work by Martin Geisler, this patch adds the option to list only directories of untracked files. A test has been added. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -5688,10 +5688,11 @@ class httpservice(object): ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), ('', 'rev', [], _('show difference from revision'), _('REV')), ('', 'change', '', _('list the changed files of a revision'), _('REV')), ('', 'relative', None, ('list the changed files relative to working directory')), + ('t', 'terse', None, _('show only directory of unknown files')), ] + walkopts + subrepoopts + formatteropts, _('[OPTION]... [FILE]...'), inferrepo=True) def status(ui, repo, *pats, **opts): """show changed files in the working directory @@ -5788,10 +5789,40 @@ def status(ui, repo, *pats, **opts): show = states[:5] stat = repo.status(node1, node2, scmutil.match(repo[node2], pats, opts), 'ignored' in show, 'clean' in show, 'unknown' in show, opts.get('subrepos')) + + if 'unknown' in show and opts.get('terse'): + knowndirs = set(['']) # root is always known + results = set() + + # gather known directories + for path in repo[node1]: + d = os.path.dirname(path) + while d not in knowndirs: + knowndirs.add(d) + d = os.path.dirname(d) + + # now loop over to prune them out + for path in stat.unknown: + prev = path + d = os.path.dirname(prev) + while d not in knowndirs: + prev = d + d = os.path.dirname(prev) + + if prev != path: + results.add(prev + '/') + else: + results.add(path) + + # replace the previous unknown list + stat = list(stat) + stat[4] = list(sorted(results)) + stat = scmutil.status(*stat) + changestates = zip(states, 'MAR!?IC', stat) if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'): copy = copies.pathcopies(repo[node1], repo[node2]) diff --git a/tests/test-completion.t b/tests/test-completion.t --- a/tests/test-completion.t +++ b/tests/test-completion.t @@ -211,11 +211,11 @@ Show all commands + options merge: force, rev, preview, tool pull: update, force, rev, bookmark, branch, ssh, remotecmd, insecure push: force, rev, bookmark, branch, new-branch, ssh, remotecmd, insecure remove: after, force, subrepos, include, exclude serve: accesslog, daemon, daemon-pipefds, errorlog, port, address, prefix, name, web-conf, webdir-conf, pid-file, stdio, cmdserver, templates, style, ipv6, certificate - status: all, modified, added, removed, deleted, clean, unknown, ignored, no-status, copies, print0, rev, change, relative, include, exclude, subrepos, template + status: all, modified, added, removed, deleted, clean, unknown, ignored, no-status, copies, print0, rev, change, relative, terse, include, exclude, subrepos, template summary: remote update: clean, check, date, rev, tool addremove: similarity, subrepos, include, exclude, dry-run archive: no-decode, prefix, rev, type, subrepos, include, exclude backout: merge, commit, parent, rev, edit, tool, include, exclude, message, logfile, date, user diff --git a/tests/test-help.t b/tests/test-help.t --- a/tests/test-help.t +++ b/tests/test-help.t @@ -570,10 +570,11 @@ Test command without options -C --copies show source of copied files -0 --print0 end filenames with NUL, for use with xargs --rev REV [+] show difference from revision --change REV list the changed files of a revision --relative list the changed files relative to working directory + -t --terse show only directory of unknown files -I --include PATTERN [+] include names matching the given patterns -X --exclude PATTERN [+] exclude names matching the given patterns -S --subrepos recurse into subrepositories (some details hidden, use --verbose to show complete help) diff --git a/tests/test-status.t b/tests/test-status.t --- a/tests/test-status.t +++ b/tests/test-status.t @@ -109,10 +109,17 @@ test status relative flag ? ../../a/in_a ? ../1/in_b_1 ? in_b_2 ? ../in_b ? ../../in_root + +test status with terse + + $ hg status --terse + ? a/ + ? b/ + ? in_root $ cd ../.. combining patterns with root and patterns without a root works $ hg st a/in_a re:.*b$