From: Junio C Hamano Date: Mon, 03 Mar 2025 20:29:56 GMT Subject: Re: [PATCH 3/3] completion: fix bugs with slashes in remote names Message-ID: In-Reply-To: <65d903c0-6b4b-4a55-b7e4-4a277417f0f1@gmail.com> phillip.wood123@gmail.com writes: >>     local fer_pids= >>     for ... >>     do >>         __git for-each-ref ... & >>         fer_pids="$fer_pids $!" >>     done >>     test -z "$fer_pids" || wait $fer_pids >> } | sort | uniq -u >> That might cause spikes in cpu/memory/disk usage that aren't ideal >> though. > > Yes, if there were a 100 remotes that's a bit of a fork-bomb. And they are all competing for a shared common resource for read access. I wonder if a single invocation of for-each-ref for refs/remotes/ hierarchy would be sufficient? That is, the calling shell script can set up a shell function "foo" and then eval $(for-each-ref --format='foo %(refname)' --shell refs/remotes/) and "foo" can do its thing avoiding as much forks as possible. As you are allowed bash-ism in completion script, you do not have to limit yourself to POSIX parameter substitution but can use substring expansion ${parameter:offset:length} and pattern substitution ${parameter/pattern/string} and other kind of bash exotics, as well as shell arrays (e.g., define an array __git__remote_branches[] for each remote, which may contain the remote-tracking branches for the remote).