{"thread":{"id":"34878","subject":"Bash completion doing full tree traversal?","startedAt":"2013-09-08T12:12:48Z","lastAt":"2013-09-19T19:31:10Z","messageCount":4,"participants":["Isaac Levy","SZEDER Gábor","Jonathan Nieder"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"227124","messageId":"CADHXV5kfaMm3nAEK_uR0McoAahj6pVtm=11Ei0_Y_teDJixWTQ@mail.gmail.com","threadId":"34878","inReplyTo":null,"subject":"Bash completion doing full tree traversal?","fromName":"Isaac Levy","fromEmail":"ilevy@google.com","sentAt":"2013-09-08T12:12:48Z","receivedAt":"2013-09-08T12:12:48Z","isPatch":false,"sender":{"key":"ilevy@google.com","avatar":null},"body":"I experienced a weird stall from git bash completion:\n$ git add p<TAB>\n\nI did some investigation and found this call trace:\n\n+ __git_index_files '--others --modified' ''\n   ---> git ls-files --exclude-standard --others --modified\n\nThis bash function captures output of the git call and strips all but\nthe base directory or base filename.  The results are limited to\nentries in the current directory.\n\nAppears to be from fea16b47b603e and first released in v1.8.2 (I have 1.8.4).\n\nIsaac\n"},{"id":"227711","messageId":"CADHXV5=ZVif6xppJgOXRKmqG9bBmAF0=A-sS9TUkH1RHSX9k6g@mail.gmail.com","threadId":"34878","inReplyTo":"CADHXV5kfaMm3nAEK_uR0McoAahj6pVtm=11Ei0_Y_teDJixWTQ@mail.gmail.com","subject":"Re: Bash completion doing full tree traversal?","fromName":"Isaac Levy","fromEmail":"ilevy@google.com","sentAt":"2013-09-16T15:54:07Z","receivedAt":"2013-09-16T15:54:07Z","isPatch":false,"sender":{"key":"ilevy@google.com","avatar":null},"body":"I should clarify that I had an untracked directory which contained a\nsignificant number of files; I can fix by adding it to gitignore.\nStill, the long delay & tree traversal were unexpected.\n\nIsaac\n\nOn Sun, Sep 8, 2013 at 2:12 PM, Isaac Levy <ilevy@google.com> wrote:\n> I experienced a weird stall from git bash completion:\n> $ git add p<TAB>\n>\n> I did some investigation and found this call trace:\n>\n> + __git_index_files '--others --modified' ''\n>    ---> git ls-files --exclude-standard --others --modified\n>\n> This bash function captures output of the git call and strips all but\n> the base directory or base filename.  The results are limited to\n> entries in the current directory.\n>\n> Appears to be from fea16b47b603e and first released in v1.8.2 (I have 1.8.4).\n>\n> Isaac\n"},{"id":"227845","messageId":"1379523968-20668-1-git-send-email-szeder@ira.uka.de","threadId":"34878","inReplyTo":"CADHXV5=ZVif6xppJgOXRKmqG9bBmAF0=A-sS9TUkH1RHSX9k6g@mail.gmail.com","subject":"[PATCH] completion: improve untracked directory filtering for filename completion","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2013-09-18T17:06:08Z","receivedAt":"2013-09-18T17:06:08Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Similar to Bash's default filename completion, our git-aware filename\ncompletion stops at directory boundaries, i.e. it doesn't offer the\nfull 'path/to/file' at first, but only 'path/'.  To achieve that the\ncompletion script runs 'git ls-files' with specific command line\noptions to get the list of relevant paths under the current directory,\nand then processes each path to strip all but the base directory or\nfilename (see __git_index_files()).\n\nTo offer only modified and untracked files for 'git add' the\ncompletion script runs 'git ls-files --exclude-standard --others\n--modified'.  This command lists all non-ignored files in untracked\ndirectories, which leads to a noticeable delay caused by the\nprocessing mentioned above if there are a lot of such files\n(__git_index_files() specifies '--exclude-standard' internally):\n\n  $ mkdir untracked-dir\n  $ for i in {1..10000} ; do >untracked-dir/$i ; done\n  $ time __git_index_files \"--others --modified\"\n  untracked-dir\n\n  real\t0m0.537s\n  user\t0m0.452s\n  sys\t0m0.160s\n\nEliminate this delay by additionally passing the '--directory\n--no-empty-directory' options to 'git ls-files' to show only the\ndirectory name of non-empty untracked directories instead their whole\ncontent:\n\n  $ time __git_index_files \"--others --modified --directory --no-empty-directory\"\n  untracked-dir\n\n  real\t0m0.029s\n  user\t0m0.020s\n  sys\t0m0.004s\n\nFilename completion for 'git clean' suffers from the same delay, as it\noffers untracked files, too.  The fix could be the same, but since it\nactually makes sense to 'git clean' empty directories, in this case we\nonly pass the '--directory' option to 'git ls-files'.\n\nReported-by: Isaac Levy <ilevy@google.com>\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n contrib/completion/git-completion.bash | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex e1b7313072..86f77345fd 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -901,7 +901,7 @@ _git_add ()\n \tesac\n \n \t# XXX should we check for --update and --all options ?\n-\t__git_complete_index_file \"--others --modified\"\n+\t__git_complete_index_file \"--others --modified --directory --no-empty-directory\"\n }\n \n _git_archive ()\n@@ -1063,7 +1063,7 @@ _git_clean ()\n \tesac\n \n \t# XXX should we check for -x option ?\n-\t__git_complete_index_file \"--others\"\n+\t__git_complete_index_file \"--others --directory\"\n }\n \n _git_clone ()\n-- \n1.8.4.366.g16e4e67\n"},{"id":"227894","messageId":"20130919193109.GA9464@google.com","threadId":"34878","inReplyTo":"1379523968-20668-1-git-send-email-szeder@ira.uka.de","subject":"Re: [PATCH] completion: improve untracked directory filtering for filename completion","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2013-09-19T19:31:10Z","receivedAt":"2013-09-19T19:31:10Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"SZEDER Gábor wrote:\n\n>   $ time __git_index_files \"--others --modified\"\n>   untracked-dir\n>\n>   real\t0m0.537s\n>   user\t0m0.452s\n>   sys\t0m0.160s\n>\n> Eliminate this delay by additionally passing the '--directory\n> --no-empty-directory' options to 'git ls-files' to show only the\n> directory name of non-empty untracked directories instead their whole\n> content:\n>\n>   $ time __git_index_files \"--others --modified --directory --no-empty-directory\"\n>   untracked-dir\n>\n>   real\t0m0.029s\n>   user\t0m0.020s\n>   sys\t0m0.004s\n\nNice.  This is what \"git status\" uses, too.\n\n> Filename completion for 'git clean' suffers from the same delay, as it\n> offers untracked files, too.  The fix could be the same, but since it\n> actually makes sense to 'git clean' empty directories, in this case we\n> only pass the '--directory' option to 'git ls-files'.\n\nAlso sensible.\n\nFor what it's worth,\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n"}]}