Patchwork [2,of,2] completion: selectively use debugpathcomplete in bash_completion

login
register
mail settings
Submitter Bryan O'Sullivan
Date March 21, 2013, 6:17 p.m.
Message ID <03374a7a43c726bb8041.1363889839@australite.thefacebook.com>
Download mbox | patch
Permalink /patch/1150/
State Accepted
Commit a821ec835223492b9605e4804abfaaec8700cbb3
Headers show

Comments

Bryan O'Sullivan - March 21, 2013, 6:17 p.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano@fb.com>
# Date 1363889832 25200
# Node ID 03374a7a43c726bb80417bfbb9e6a184139221ee
# Parent  d91fe1c607511dc57cb51e557229c243908a6b39
completion: selectively use debugpathcomplete in bash_completion

The current bash_completion code can be very slow in a large working
directory. It always uses "hg status" to generate possibly matching
files, which checks the status of every file. We often don't care
about status when completing, so that cost is very high.

As the new debugpathcomplete command does not check the status of
files, it offers much better performance for commands that only
care about completing names.
Nikolaj Sjujskij - April 15, 2013, 3:01 p.m.
Den 2013-03-21 22:17:19 skrev Bryan O'Sullivan <bos@serpentine.com>:

> # HG changeset patch
> # User Bryan O'Sullivan <bryano@fb.com>
> # Date 1363889832 25200
> # Node ID 03374a7a43c726bb80417bfbb9e6a184139221ee
> # Parent  d91fe1c607511dc57cb51e557229c243908a6b39
> completion: selectively use debugpathcomplete in bash_completion
> ...
> As the new debugpathcomplete command does not check the status of
> files, it offers much better performance for commands that only
> care about completing names.
>
> diff --git a/contrib/bash_completion b/contrib/bash_completion
> --- a/contrib/bash_completion
> +++ b/contrib/bash_completion
> @@ -80,6 +80,14 @@ shopt -s extglob

>  	forget)
> -	    _hg_status "a"
> +	    _hg_debugpathcomplete -fa
>  	;;
  While I was thinking about how (or whether) should I use  
debugpathcomplete in zsh_completion, two questions arose:

  1. Why forget should complete only added files? One may want to forget a  
clean or even modified file as well, not only the one (wrongly) added just  
now.

  2. `debugpathcomplete -fa` offering a significant improvement over  
`status -a` seems wrong. `hg status --added` has no more reasons to walk  
workdir than debugpathcomplete, I think.

Patch

diff --git a/contrib/bash_completion b/contrib/bash_completion
--- a/contrib/bash_completion
+++ b/contrib/bash_completion
@@ -80,6 +80,14 @@  shopt -s extglob
     done
 }
 
+_hg_debugpathcomplete()
+{
+    local files="$(_hg_cmd debugpathcomplete $1 "$cur")"
+    local IFS=$'\n'
+    compopt -o filenames 2>/dev/null
+    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
+}
+
 _hg_status()
 {
     local files="$(_hg_cmd status -n$1 "glob:$cur**")"
@@ -241,16 +249,16 @@  shopt -s extglob
 	    _hg_status "mar"
 	;;
 	remove)
-	    _hg_status "mcd"
+	    _hg_debugpathcomplete -n
 	;;
 	forget)
-	    _hg_status "a"
+	    _hg_debugpathcomplete -fa
 	;;
 	diff)
 	    _hg_status "mar"
 	;;
 	revert)
-	    _hg_status "mard"
+	    _hg_debugpathcomplete
 	;;
 	clone)
 	    local count=$(_hg_count_non_option)