completion: let 'for-each-ref' sort remote branches for 'checkout' DWIMery
commit400a7553c4e0f0cafa1bef5a1dd792b6cc10c450
authorSZEDER Gábor <szeder.dev@gmail.com>
Thu, 23 Mar 2017 15:29:21 +0000 (23 16:29 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 23 Mar 2017 18:18:22 +0000 (23 11:18 -0700)
treebbd88c21538b34ecf8e6c339d747e996577f72b6
parent824388d54b238b0d0cdc3f584dd27cb334df4ebc
completion: let 'for-each-ref' sort remote branches for 'checkout' DWIMery

When listing unique remote branches for 'git checkout's tracking
DWIMery, __git_refs() runs the classic '... |sort |uniq -u' pattern to
filter out duplicate remote branches.

Let 'git for-each-ref' do the sorting, sparing the overhead of
fork()+exec()ing 'sort' and a stage in the pipeline where potentially
relatively large amount of data can be passed between two subsequent
pipeline stages.

This speeds up refs completion for 'git checkout' a bit when a lot of
remote branches match the current word to be completed.  Listing a
single local and 100k remote branches, all packed, best of five:

  On Linux, before:

    $ time __git_complete_refs --track

    real    0m1.856s
    user    0m1.816s
    sys     0m0.060s

  After:

    real    0m1.550s
    user    0m1.512s
    sys     0m0.060s

  On Windows, before:

    real    0m3.128s
    user    0m2.155s
    sys     0m0.183s

  After:

    real    0m2.781s
    user    0m1.826s
    sys     0m0.136s

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-completion.bash