Skip to content

Commit

Permalink
Use --list for branch and tag tab expansion
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AndreasHassing committed Jul 6, 2021
1 parent b79c2dc commit 395f22e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/GitTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ function script:gitBranches($filter, $includeHEAD = $false, $prefix = '') {
$filter = $matches['to']
}

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

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

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

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

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

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

0 comments on commit 395f22e

Please sign in to comment.