Patchwork [1,of,2] bash_completion: match more narrowly

mail settings
Submitter Bryan O'Sullivan
Date March 14, 2013, 9:42 p.m.
Message ID <3e6874c851bebe2ca4b3.1363297325@australite.local>
Download mbox | patch
Permalink /patch/1128/
State Accepted
Commit 69e4787b6867f958653d9556f9b98208fdda7570
Headers show


Bryan O'Sullivan - March 14, 2013, 9:42 p.m.
# HG changeset patch
# User Bryan O'Sullivan <>
# Date 1363297271 25200
# Node ID 3e6874c851bebe2ca4b3e010a67291f5b654f256
# Parent  8e7bfe183905f35744dadad44dd833080637bd56
bash_completion: match more narrowly

This greatly helps completion performance for most commands that deal
with files.

In a working dir with 150,000 files, where we want to complete the name
of a modified file under a path beginning with "a", from the root of
the working dir:

  (old) hg status -nm .            1.7 sec
  (new) hg status -nm "glob:a**"   0.3

Even "hg add" becomes a little faster, though it's the worst case (being
interested in untracked files).


diff --git a/contrib/bash_completion b/contrib/bash_completion
--- a/contrib/bash_completion
+++ b/contrib/bash_completion
@@ -82,7 +82,7 @@  shopt -s extglob
-    local files="$(_hg_cmd status -n$1 .)"
+    local files="$(_hg_cmd status -n$1 "glob:$cur**")"
     local IFS=$'\n'
     compopt -o filenames 2>/dev/null
     COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))