Patchwork [1,of,3,crewed] pathcomplete: complete directories more conservatively

login
register
mail settings
Submitter Bryan O'Sullivan
Date March 22, 2013, 5:31 a.m.
Message ID <fa6d5c62f3bd7a5e95f1.1363930289@australite.local>
Download mbox | patch
Permalink /patch/1164/
State Accepted
Commit fa6d5c62f3bd7a5e95f12473272c2acde683c29d
Headers show

Comments

Bryan O'Sullivan - March 22, 2013, 5:31 a.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano@fb.com>
# Date 1363929054 25200
#      Thu Mar 21 22:10:54 2013 -0700
# Node ID fa6d5c62f3bd7a5e95f12473272c2acde683c29d
# Parent  704229c06dcfd1347d8303c39a6cbb1db9135e27
pathcomplete: complete directories more conservatively

Suppose we want to perform a single-level completion (i.e. without
--full) of "fi" in a repo containing "fee", "fie/dead", "fie/live",
and "foe".

If we give back "fie/" as the only answer, the shell will consider
the completion to be unambiguous, and will append a space after the
completion.  We can't complete "fie/live" or "fie/dead" without
first backspacing over that space.

We used to thus create two fake names, "fie/a" and "fie/b", to force
the shell to consider the completion to be ambiguous. It would then
stop at "fie/" without appending a space, allowing us to hit tab
again to complete "fie/live" or "fie/dead".

The change here arises from realising that we only need to force
the shell to consider a completion as ambiguous if we have exactly
one directory and zero files as possible completions.

This prevents spurious names from showing up as possible completions
when they don't need to be invented in the first place.
Bryan O'Sullivan - March 22, 2013, 5:31 a.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano@fb.com>
# Date 1363929741 25200
#      Thu Mar 21 22:22:21 2013 -0700
# Node ID c394a365483e1224c8627b94d9f1a40c279dcded
# Parent  fa6d5c62f3bd7a5e95f12473272c2acde683c29d
tests: rename test-debugcomplete.t to test-completion.t

diff --git a/tests/test-debugcomplete.t b/tests/test-completion.t
rename from tests/test-debugcomplete.t
rename to tests/test-completion.t

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2198,9 +2198,11 @@  def debugpathcomplete(ui, repo, *specs, 
         f, d = complete(spec, acceptable or 'nmar')
         files.update(f)
         dirs.update(d)
-    for d in dirs:
-        files.add(d + 'a')
-        files.add(d + 'b')
+    if not files and len(dirs) == 1:
+        # force the shell to consider a completion that matches one
+        # directory and zero files to be ambiguous
+        dirs.add(iter(dirs).next() + '.')
+    files.update(dirs)
     ui.write('\n'.join(repo.pathto(p, cwd) for p in sorted(files)))
     ui.write('\n')