Skip to content

Commit 42aa80d

Browse files
Use --list for branch and tag tab expansion
To improve performance of those tab expansions, which are currently sub-optimal in git repos with a lot of branches. * for `branch`, `--list` has been available since 1.7.8 * https://github.com/git/git/blob/ecbdaf0899161c067986e9d9d564586d4b045d62/Documentation/RelNotes/1.7.8.txt#L25 * for `tag`, `--list` has been available since 1.7.10 * https://github.com/git/git/blob/142430338477d9d1bb25be66267225fb58498d92/Documentation/RelNotes/1.7.10.txt#L128
1 parent cb070b7 commit 42aa80d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/GitTabExpansion.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ function script:gitBranches($filter, $includeHEAD = $false, $prefix = '') {
136136
$filter = $matches['to']
137137
}
138138

139-
$branches = @(git branch --no-color | ForEach-Object { if (($_ -notmatch "^\* \(HEAD detached .+\)$") -and ($_ -match "^[\*\+]?\s*(?<ref>\S+)(?: -> .+)?")) { $matches['ref'] } }) +
140-
@(git branch --no-color -r | ForEach-Object { if ($_ -match "^ (?<ref>\S+)(?: -> .+)?") { $matches['ref'] } }) +
139+
$branches = @(git branch --no-color --list "$filter*" | ForEach-Object { if (($_ -notmatch "^\* \(HEAD detached .+\)$") -and ($_ -match "^[\*\+]?\s*(?<ref>.*)")) { $matches['ref'] } }) +
140+
@(git branch --no-color --remotes --list "$filter*" | ForEach-Object { if ($_ -match "^ (?<ref>\S+)(?: -> .+)?") { $matches['ref'] } }) +
141141
@(if ($includeHEAD) { 'HEAD','FETCH_HEAD','ORIG_HEAD','MERGE_HEAD' })
142142

143143
$branches |
@@ -147,7 +147,7 @@ function script:gitBranches($filter, $includeHEAD = $false, $prefix = '') {
147147
}
148148

149149
function script:gitRemoteUniqueBranches($filter) {
150-
git branch --no-color -r |
150+
git branch --no-color --remotes --list "$filter*" |
151151
ForEach-Object { if ($_ -match "^ (?<remote>[^/]+)/(?<branch>\S+)(?! -> .+)?$") { $matches['branch'] } } |
152152
Group-Object -NoElement |
153153
Where-Object { $_.Count -eq 1 } |
@@ -169,23 +169,23 @@ function script:gitConfigKeys($section, $filter, $defaultOptions = '') {
169169
}
170170

171171
function script:gitTags($filter, $prefix = '') {
172-
git tag |
172+
git tag --list "$filter*" |
173173
Where-Object { $_ -like "$filter*" } |
174174
ForEach-Object { $prefix + $_ } |
175175
quoteStringWithSpecialChars
176176
}
177177

178178
function script:gitFeatures($filter, $command) {
179179
$featurePrefix = git config --local --get "gitflow.prefix.$command"
180-
$branches = @(git branch --no-color | ForEach-Object { if ($_ -match "^\*?\s*$featurePrefix(?<ref>.*)") { $matches['ref'] } })
180+
$branches = @(git branch --no-color --list "$filter*" | ForEach-Object { if ($_ -match "^\*?\s*$featurePrefix(?<ref>.*)") { $matches['ref'] } })
181181
$branches |
182182
Where-Object { $_ -ne '(no branch)' -and $_ -like "$filter*" } |
183183
ForEach-Object { $featurePrefix + $_ } |
184184
quoteStringWithSpecialChars
185185
}
186186

187187
function script:gitRemoteBranches($remote, $ref, $filter, $prefix = '') {
188-
git branch --no-color -r |
188+
git branch --no-color --remotes --list "$remote/$filter*" |
189189
Where-Object { $_ -like " $remote/$filter*" } |
190190
ForEach-Object { $prefix + $ref + ($_ -replace " $remote/","") } |
191191
quoteStringWithSpecialChars

0 commit comments

Comments
 (0)