|
54 | 54 | # First, we need to determine what the combined git command was. |
55 | 55 | # Luckily, this is easy: just combine "git" with the list of git argument |
56 | 56 | $gitCommand = @('git') + $GitArgument[0..$GitArgument.Length] -join ' ' |
57 | | - # Now that we have that, let's initialize an empty variable to keep any extension validation errors. |
58 | | - $extensionValidationErrors = $null |
59 | | - # Then we create a hashtable containing the parameters to Get-UGitExtension: |
60 | | - $uGitExtensionParams = @{ |
61 | | - CommandName = $MyInvocation.MyCommand # We want extensions for this command |
62 | | - ValidateInput = $gitCommand # that are valid, given $GitCommand. |
63 | | - ErrorAction = 'SilentlyContinue' # We do not want to display errors |
64 | | - ErrorVariable = 'extensionValidationErrors' # we want to redirect them into $extensionValidationErrros. |
| 57 | + |
| 58 | + # Now we need to see if we have have a cached for extension mapping. |
| 59 | + if (-not $script:GitExtensionMappingCache) { |
| 60 | + $script:GitExtensionMappingCache = @{} # If we don't, create one. |
65 | 61 | } |
66 | | - # Now we get a list of git output extensions |
67 | | - $gitOutputExtensions = @(Get-UGitExtension @uGitExtensionParams) |
68 | | - # If any of them had errors, and we want to see the -Verbose channel |
69 | | - if ($extensionValidationErrors -and $VerbosePreference -ne 'silentlyContinue') { |
70 | | - foreach ($validationError in $extensionValidationErrors) { |
71 | | - Write-Verbose "$validationError" # write the validation errors to verbose. |
72 | | - # It should be noted that there will almost always be validation errors, |
73 | | - # since most extensions will not apply to a given $GitCommand |
| 62 | + |
| 63 | + if (-not $script:GitExtensionMappingCache[$gitCommand]) { # If we don't have a cached extension list |
| 64 | + |
| 65 | + # let's initialize an empty variable to keep any extension validation errors. |
| 66 | + $extensionValidationErrors = $null |
| 67 | + # Then we create a hashtable containing the parameters to Get-UGitExtension: |
| 68 | + $uGitExtensionParams = @{ |
| 69 | + CommandName = $MyInvocation.MyCommand # We want extensions for this command |
| 70 | + ValidateInput = $gitCommand # that are valid, given $GitCommand. |
| 71 | + |
74 | 72 | } |
75 | | - } |
| 73 | + |
| 74 | + # If -Verbose is -Debug is set, we will want to populate extensionValidationErrors |
| 75 | + if ($VerbosePreference -ne 'silentlyContinue' -or |
| 76 | + $DebugPreference -ne 'silentlyContinue') { |
| 77 | + $uGitExtensionParams.ErrorAction = 'SilentlyContinue' # We do not want to display errors |
| 78 | + $uGitExtensionParams.ErrorVariable = 'extensionValidationErrors' # we want to redirect them into $extensionValidationErrors. |
| 79 | + $uGitExtensionParams.AllValid = $true # and we want to see that all of the validation attributes are correct. |
| 80 | + } else { |
| 81 | + $uGitExtensionParams.ErrorAction = 'Ignore' |
| 82 | + } |
| 83 | + |
| 84 | + # Now we get a list of git output extensions and store it in the cache. |
| 85 | + $script:GitExtensionMappingCache[$gitCommand] = $gitOutputExtensions = @(Get-UGitExtension @uGitExtensionParams) |
| 86 | + |
| 87 | + # If any of them had errors, and we want to see the -Verbose channel |
| 88 | + if ($extensionValidationErrors -and $VerbosePreference -ne 'silentlyContinue') { |
| 89 | + foreach ($validationError in $extensionValidationErrors) { |
| 90 | + Write-Verbose "$validationError" # write the validation errors to verbose. |
| 91 | + # It should be noted that there will almost always be validation errors, |
| 92 | + # since most extensions will not apply to a given $GitCommand |
| 93 | + } |
| 94 | + } |
| 95 | + } else { |
| 96 | + # If there was already an extension cached, we can skip the previous steps and just reuse the cached extensions. |
| 97 | + $gitOutputExtensions = $script:GitExtensionMappingCache[$gitCommand] |
| 98 | + } |
76 | 99 |
|
77 | 100 | # Next we want to create a collection of SteppablePipelines. |
78 | 101 | # These allow us to run the begin/process/end blocks of each Extension. |
|
0 commit comments