From c6f759c72a1ad7e9bc8040e2bbb576bfe5b36062 Mon Sep 17 00:00:00 2001 From: Marcus Reid Date: Mon, 27 Jul 2015 04:17:41 +0100 Subject: [PATCH 01/16] Use git-status-cache-posh-client to retrieve git informaiton when module is available. --- GitPrompt.ps1 | 1 + GitUtils.ps1 | 90 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 56 insertions(+), 35 deletions(-) diff --git a/GitPrompt.ps1 b/GitPrompt.ps1 index d2629ff46..d62170997 100644 --- a/GitPrompt.ps1 +++ b/GitPrompt.ps1 @@ -48,6 +48,7 @@ $global:GitPromptSettings = New-Object PSObject -Property @{ EnablePromptStatus = !$Global:GitMissing EnableFileStatus = $true + EnableFileStatusFromCache = (Get-Module GitStatusCachePoshClient) -ne $null RepositoriesInWhichToDisableFileStatus = @( ) # Array of repository paths DescribeStyle = '' diff --git a/GitUtils.ps1 b/GitUtils.ps1 index 8f335ed2e..ae01fe5fe 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -117,44 +117,64 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { $filesUnmerged = @() if($settings.EnableFileStatus -and !$(InDisabledRepository)) { - dbg 'Getting status' $sw - $status = git -c color.status=false status --short --branch 2>$null - } else { - $status = @() - } + if ($settings.EnableFileStatusFromCache) { + $cacheResponse = Get-GitStatusFromCache - dbg 'Parsing status' $sw - $status | foreach { - dbg "Status: $_" $sw - if($_) { - switch -regex ($_) { - '^(?[^#])(?.) (?.*?)(?: -> (?.*))?$' { - switch ($matches['index']) { - 'A' { $indexAdded += $matches['path1'] } - 'M' { $indexModified += $matches['path1'] } - 'R' { $indexModified += $matches['path1'] } - 'C' { $indexModified += $matches['path1'] } - 'D' { $indexDeleted += $matches['path1'] } - 'U' { $indexUnmerged += $matches['path1'] } - } - switch ($matches['working']) { - '?' { $filesAdded += $matches['path1'] } - 'A' { $filesAdded += $matches['path1'] } - 'M' { $filesModified += $matches['path1'] } - 'D' { $filesDeleted += $matches['path1'] } - 'U' { $filesUnmerged += $matches['path1'] } - } - } + $indexAdded = $cacheResponse.IndexAdded + $indexModified = $cacheResponse.IndexModified + $cacheResponse.IndexRenamed | foreach { $indexModified += $_ } + $indexDeleted = $cacheResponse.IndexDeleted - '^## (?\S+?)(?:\.\.\.(?\S+))?(?: \[(?:ahead (?\d+))?(?:, )?(?:behind (?\d+))?\])?$' { - $branch = $matches['branch'] - $upstream = $matches['upstream'] - $aheadBy = [int]$matches['ahead'] - $behindBy = [int]$matches['behind'] - } + $filesAdded = $cacheResponse.WorkingAdded + $filesModified = $cacheResponse.WorkingModified + $cacheResponse.WorkingRenamed | foreach { $filesModified += $_ } + $filesDeleted = $cacheResponse.WorkingDeleted + + $branch = $cacheResponse.Branch + $upstream = $cacheResponse.Upstream + $aheadBy = $cacheResponse.AheadBy + $behindBy = $cacheResponse.BehindBy - '^## Initial commit on (?\S+)$' { - $branch = $matches['branch'] + if ($cacheResponse.State) { $branch += "|" + $cacheResponse.State } + } + else { + dbg 'Getting status' $sw + $status = git -c color.status=false status --short --branch 2>$null + + dbg 'Parsing status' $sw + $status | foreach { + dbg "Status: $_" $sw + if($_) { + switch -regex ($_) { + '^(?[^#])(?.) (?.*?)(?: -> (?.*))?$' { + switch ($matches['index']) { + 'A' { $indexAdded += $matches['path1'] } + 'M' { $indexModified += $matches['path1'] } + 'R' { $indexModified += $matches['path1'] } + 'C' { $indexModified += $matches['path1'] } + 'D' { $indexDeleted += $matches['path1'] } + 'U' { $indexUnmerged += $matches['path1'] } + } + switch ($matches['working']) { + '?' { $filesAdded += $matches['path1'] } + 'A' { $filesAdded += $matches['path1'] } + 'M' { $filesModified += $matches['path1'] } + 'D' { $filesDeleted += $matches['path1'] } + 'U' { $filesUnmerged += $matches['path1'] } + } + } + + '^## (?\S+?)(?:\.\.\.(?\S+))?(?: \[(?:ahead (?\d+))?(?:, )?(?:behind (?\d+))?\])?$' { + $branch = $matches['branch'] + $upstream = $matches['upstream'] + $aheadBy = [int]$matches['ahead'] + $behindBy = [int]$matches['behind'] + } + + '^## Initial commit on (?\S+)$' { + $branch = $matches['branch'] + } + } } } } From f970bd69df3711c50c8b56f99404b33b19a7ab03 Mon Sep 17 00:00:00 2001 From: Marcus Reid Date: Fri, 7 Aug 2015 08:58:05 -0700 Subject: [PATCH 02/16] Read conflicted files from cache response. --- GitUtils.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index ae01fe5fe..be7001ee0 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -118,17 +118,20 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { if($settings.EnableFileStatus -and !$(InDisabledRepository)) { if ($settings.EnableFileStatusFromCache) { + dbg 'Getting status from cache' $sw $cacheResponse = Get-GitStatusFromCache $indexAdded = $cacheResponse.IndexAdded $indexModified = $cacheResponse.IndexModified $cacheResponse.IndexRenamed | foreach { $indexModified += $_ } $indexDeleted = $cacheResponse.IndexDeleted + $indexUnmerged = $cacheResponse.Conflicted $filesAdded = $cacheResponse.WorkingAdded $filesModified = $cacheResponse.WorkingModified $cacheResponse.WorkingRenamed | foreach { $filesModified += $_ } $filesDeleted = $cacheResponse.WorkingDeleted + $filesUnmerged = $cacheResponse.Conflicted $branch = $cacheResponse.Branch $upstream = $cacheResponse.Upstream From e032b91df5c147fd5c743b68c788de7d258fe2a7 Mon Sep 17 00:00:00 2001 From: Marcus Reid Date: Mon, 10 Aug 2015 07:27:58 +0100 Subject: [PATCH 03/16] Add dbg calls for timing. --- GitUtils.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index be7001ee0..87463d220 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -120,6 +120,7 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { if ($settings.EnableFileStatusFromCache) { dbg 'Getting status from cache' $sw $cacheResponse = Get-GitStatusFromCache + dbg 'Parsing status' $sw $indexAdded = $cacheResponse.IndexAdded $indexModified = $cacheResponse.IndexModified From 92a55626d2d9d1d20a68ede5c2166c01e9d62bda Mon Sep 17 00:00:00 2001 From: Marcus Reid Date: Tue, 11 Aug 2015 08:51:40 +0100 Subject: [PATCH 04/16] Update parsing for renamed files. --- GitUtils.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index 87463d220..66012323a 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -124,13 +124,13 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { $indexAdded = $cacheResponse.IndexAdded $indexModified = $cacheResponse.IndexModified - $cacheResponse.IndexRenamed | foreach { $indexModified += $_ } + $cacheResponse.IndexRenamed | foreach { $indexModified += $_.Old } $indexDeleted = $cacheResponse.IndexDeleted $indexUnmerged = $cacheResponse.Conflicted $filesAdded = $cacheResponse.WorkingAdded $filesModified = $cacheResponse.WorkingModified - $cacheResponse.WorkingRenamed | foreach { $filesModified += $_ } + $cacheResponse.WorkingRenamed | foreach { $filesModified += $_.Old } $filesDeleted = $cacheResponse.WorkingDeleted $filesUnmerged = $cacheResponse.Conflicted From 2d3cf044b43aec5c753a2f7ae87b25009aec5f0e Mon Sep 17 00:00:00 2001 From: Marcus Reid Date: Wed, 19 Aug 2015 04:55:19 +0100 Subject: [PATCH 05/16] Delay computing EnableFileStatusFromCache setting until first request to avoid ordering dependency in $profile --- GitPrompt.ps1 | 2 +- GitUtils.ps1 | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/GitPrompt.ps1 b/GitPrompt.ps1 index d62170997..7508acc88 100644 --- a/GitPrompt.ps1 +++ b/GitPrompt.ps1 @@ -48,7 +48,7 @@ $global:GitPromptSettings = New-Object PSObject -Property @{ EnablePromptStatus = !$Global:GitMissing EnableFileStatus = $true - EnableFileStatusFromCache = (Get-Module GitStatusCachePoshClient) -ne $null + EnableFileStatusFromCache = $null RepositoriesInWhichToDisableFileStatus = @( ) # Array of repository paths DescribeStyle = '' diff --git a/GitUtils.ps1 b/GitUtils.ps1 index 66012323a..7be757faa 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -117,6 +117,10 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { $filesUnmerged = @() if($settings.EnableFileStatus -and !$(InDisabledRepository)) { + if ($settings.EnableFileStatusFromCache -eq $null) { + $settings.EnableFileStatusFromCache = (Get-Module GitStatusCachePoshClient) -ne $null + } + if ($settings.EnableFileStatusFromCache) { dbg 'Getting status from cache' $sw $cacheResponse = Get-GitStatusFromCache From cf1b9bca536fe10c4e694382c51ff3d809b8fc4e Mon Sep 17 00:00:00 2001 From: Marcus Reid Date: Wed, 19 Aug 2015 06:09:14 +0100 Subject: [PATCH 06/16] Fix whitespace. --- GitUtils.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index 7be757faa..11f6f1495 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -117,9 +117,9 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { $filesUnmerged = @() if($settings.EnableFileStatus -and !$(InDisabledRepository)) { - if ($settings.EnableFileStatusFromCache -eq $null) { - $settings.EnableFileStatusFromCache = (Get-Module GitStatusCachePoshClient) -ne $null - } + if ($settings.EnableFileStatusFromCache -eq $null) { + $settings.EnableFileStatusFromCache = (Get-Module GitStatusCachePoshClient) -ne $null + } if ($settings.EnableFileStatusFromCache) { dbg 'Getting status from cache' $sw From 6bafdd48fb80dec9eb11f22a4c28183e4ee06a67 Mon Sep 17 00:00:00 2001 From: Marcus Reid Date: Mon, 24 Aug 2015 21:33:41 -0700 Subject: [PATCH 07/16] Fix incorrect brace style. --- GitUtils.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index 11f6f1495..c0e60ed2b 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -144,8 +144,7 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { $behindBy = $cacheResponse.BehindBy if ($cacheResponse.State) { $branch += "|" + $cacheResponse.State } - } - else { + } else { dbg 'Getting status' $sw $status = git -c color.status=false status --short --branch 2>$null From 008836ebd5f1dcd150d24047a4b80e1888f6dacb Mon Sep 17 00:00:00 2001 From: Marcus Reid Date: Sun, 6 Sep 2015 08:29:22 -0700 Subject: [PATCH 08/16] Read stash count from cache. --- GitUtils.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index da981da17..d7511026a 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -144,6 +144,7 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { $aheadBy = $cacheResponse.AheadBy $behindBy = $cacheResponse.BehindBy + if ($cacheResponse.Stashes) { $stashCount = $cacheResponse.Stashes.Length } if ($cacheResponse.State) { $branch += "|" + $cacheResponse.State } } else { dbg 'Getting status' $sw From b90f7dfdc8e75ea522706a837c1435899f4755ca Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Mon, 2 Jan 2017 11:51:11 -0600 Subject: [PATCH 09/16] Reformat --- GitUtils.ps1 | 91 +++++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 47 deletions(-) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index f55fa67d4..48d1e4c7d 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -144,60 +144,57 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { $stashCount = 0 if($settings.EnableFileStatus -and !$(InDisabledRepository)) { - dbg 'Getting status' $sw - $status = git -c color.status=false status --short --branch 2>$null - if($settings.EnableStashStatus) { - dbg 'Getting stash count' $sw - $stashCount = $null | git stash list 2>$null | measure-object | Select-Object -expand Count - } - } - else { - $status = @() - } - - dbg 'Parsing status' $sw - switch -regex ($status) { - '^(?[^#])(?.) (?.*?)(?: -> (?.*))?$' { - if ($sw) { dbg "Status: $_" $sw } - - switch ($matches['index']) { - 'A' { $null = $indexAdded.Add($matches['path1']); break } - 'M' { $null = $indexModified.Add($matches['path1']); break } - 'R' { $null = $indexModified.Add($matches['path1']); break } - 'C' { $null = $indexModified.Add($matches['path1']); break } - 'D' { $null = $indexDeleted.Add($matches['path1']); break } - 'U' { $null = $indexUnmerged.Add($matches['path1']); break } - } - switch ($matches['working']) { - '?' { $null = $filesAdded.Add($matches['path1']); break } - 'A' { $null = $filesAdded.Add($matches['path1']); break } - 'M' { $null = $filesModified.Add($matches['path1']); break } - 'D' { $null = $filesDeleted.Add($matches['path1']); break } - 'U' { $null = $filesUnmerged.Add($matches['path1']); break } + dbg 'Getting status' $sw + $status = git -c color.status=false status --short --branch 2>$null + if($settings.EnableStashStatus) { + dbg 'Getting stash count' $sw + $stashCount = $null | git stash list 2>$null | measure-object | Select-Object -expand Count } - continue - } - '^## (?\S+?)(?:\.\.\.(?\S+))?(?: \[(?:ahead (?\d+))?(?:, )?(?:behind (?\d+))?(?gone)?\])?$' { - if ($sw) { dbg "Status: $_" $sw } + dbg 'Parsing status' $sw + switch -regex ($status) { + '^(?[^#])(?.) (?.*?)(?: -> (?.*))?$' { + if ($sw) { dbg "Status: $_" $sw } + + switch ($matches['index']) { + 'A' { $null = $indexAdded.Add($matches['path1']); break } + 'M' { $null = $indexModified.Add($matches['path1']); break } + 'R' { $null = $indexModified.Add($matches['path1']); break } + 'C' { $null = $indexModified.Add($matches['path1']); break } + 'D' { $null = $indexDeleted.Add($matches['path1']); break } + 'U' { $null = $indexUnmerged.Add($matches['path1']); break } + } + switch ($matches['working']) { + '?' { $null = $filesAdded.Add($matches['path1']); break } + 'A' { $null = $filesAdded.Add($matches['path1']); break } + 'M' { $null = $filesModified.Add($matches['path1']); break } + 'D' { $null = $filesDeleted.Add($matches['path1']); break } + 'U' { $null = $filesUnmerged.Add($matches['path1']); break } + } + continue + } + + '^## (?\S+?)(?:\.\.\.(?\S+))?(?: \[(?:ahead (?\d+))?(?:, )?(?:behind (?\d+))?(?gone)?\])?$' { + if ($sw) { dbg "Status: $_" $sw } - $branch = $matches['branch'] - $upstream = $matches['upstream'] - $aheadBy = [int]$matches['ahead'] - $behindBy = [int]$matches['behind'] - $gone = [string]$matches['gone'] -eq 'gone' - continue - } + $branch = $matches['branch'] + $upstream = $matches['upstream'] + $aheadBy = [int]$matches['ahead'] + $behindBy = [int]$matches['behind'] + $gone = [string]$matches['gone'] -eq 'gone' + continue + } - '^## Initial commit on (?\S+)$' { - if ($sw) { dbg "Status: $_" $sw } + '^## Initial commit on (?\S+)$' { + if ($sw) { dbg "Status: $_" $sw } - $branch = $matches['branch'] - continue - } + $branch = $matches['branch'] + continue + } - default { if ($sw) { dbg "Status: $_" $sw } } + default { if ($sw) { dbg "Status: $_" $sw } } + } } if(!$branch) { $branch = Get-GitBranch $gitDir $sw } From 03131e1b97525a4981310734807d0119904b03d7 Mon Sep 17 00:00:00 2001 From: Marcus Reid Date: Mon, 2 Jan 2017 11:18:15 -0800 Subject: [PATCH 10/16] Update cache response parsing to add to existing lists rather than overwrite with arrays. --- GitUtils.ps1 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index d9487246f..3cdbc1618 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -153,17 +153,17 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { $cacheResponse = Get-GitStatusFromCache dbg 'Parsing status' $sw - $indexAdded = $cacheResponse.IndexAdded - $indexModified = $cacheResponse.IndexModified - $cacheResponse.IndexRenamed | foreach { $indexModified += $_.Old } - $indexDeleted = $cacheResponse.IndexDeleted - $indexUnmerged = $cacheResponse.Conflicted - - $filesAdded = $cacheResponse.WorkingAdded - $filesModified = $cacheResponse.WorkingModified - $cacheResponse.WorkingRenamed | foreach { $filesModified += $_.Old } - $filesDeleted = $cacheResponse.WorkingDeleted - $filesUnmerged = $cacheResponse.Conflicted + $cacheResponse.IndexAdded | foreach { $indexAdded.Add($_) } + $cacheResponse.IndexModified | foreach { $indexModified.Add($_) } + $cacheResponse.IndexRenamed | foreach { $indexModified.Add($_.Old) } + $cacheResponse.IndexDeleted | foreach { $indexDeleted.Add($_) } + $cacheResponse.Conflicted | foreach { $indexUnmerged.Add($_) } + + $cacheResponse.WorkingAdded | foreach { $filesAdded.Add($_) } + $cacheResponse.WorkingModified | foreach { $filesModified.Add($_) } + $cacheResponse.WorkingRenamed | foreach { $filesModified.Add($_.Old) } + $cacheResponse.WorkingDeleted | foreach { $filesDeleted.Add($_) } + $cacheResponse.Conflicted | foreach { $filesUnmerged.Add($_) } $branch = $cacheResponse.Branch $upstream = $cacheResponse.Upstream @@ -233,7 +233,7 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { # # This collection is used twice, so create the array just once $filesAdded = $filesAdded.ToArray() - + $indexPaths = @(GetUniquePaths $indexAdded,$indexModified,$indexDeleted,$indexUnmerged) $workingPaths = @(GetUniquePaths $filesAdded,$filesModified,$filesDeleted,$filesUnmerged) $index = (,$indexPaths) | From 3e13ee89d946ddd3e0f592467d4dfa2325e01ae1 Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Mon, 2 Jan 2017 13:22:33 -0600 Subject: [PATCH 11/16] Add cache responses to existing lists --- GitUtils.ps1 | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index d9487246f..6672d1ac9 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -153,17 +153,17 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { $cacheResponse = Get-GitStatusFromCache dbg 'Parsing status' $sw - $indexAdded = $cacheResponse.IndexAdded - $indexModified = $cacheResponse.IndexModified - $cacheResponse.IndexRenamed | foreach { $indexModified += $_.Old } - $indexDeleted = $cacheResponse.IndexDeleted - $indexUnmerged = $cacheResponse.Conflicted - - $filesAdded = $cacheResponse.WorkingAdded - $filesModified = $cacheResponse.WorkingModified - $cacheResponse.WorkingRenamed | foreach { $filesModified += $_.Old } - $filesDeleted = $cacheResponse.WorkingDeleted - $filesUnmerged = $cacheResponse.Conflicted + $indexAdded.AddRange([string[]]$cacheResponse.IndexAdded) + $indexModified.AddRange([string[]]$cacheResponse.IndexModified) + $indexModified.AddRange([string[]]@($cacheResponse.IndexRenamed | Select-Object -ExpandProperty Old)) + $indexDeleted.AddRange([string[]]$cacheResponse.IndexDeleted) + $indexUnmerged.AddRange([string[]]$cacheResponse.Conflicted) + + $filesAdded.AddRange([string[]]$cacheResponse.WorkingAdded) + $filesModified.AddRange([string[]]$cacheResponse.WorkingModified) + $filesModified.AddRange([string[]]@($cacheResponse.WorkingRenamed | Select-Object -ExpandProperty Old)) + $filesDeleted.AddRange([string[]]$cacheResponse.WorkingDeleted) + $filesUnmerged.AddRange([string[]]$cacheResponse.Conflicted) $branch = $cacheResponse.Branch $upstream = $cacheResponse.Upstream From 6c53ac1242f701710ec1a61de97dc5394c8c193d Mon Sep 17 00:00:00 2001 From: Marcus Reid Date: Mon, 2 Jan 2017 11:27:00 -0800 Subject: [PATCH 12/16] Revert accidental whitepsace add. --- GitUtils.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index 3cdbc1618..5ceb7118f 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -233,7 +233,7 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { # # This collection is used twice, so create the array just once $filesAdded = $filesAdded.ToArray() - + $indexPaths = @(GetUniquePaths $indexAdded,$indexModified,$indexDeleted,$indexUnmerged) $workingPaths = @(GetUniquePaths $filesAdded,$filesModified,$filesDeleted,$filesUnmerged) $index = (,$indexPaths) | From b07bce5ba557f7cdc6a14247171aff6f0837ed9e Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Wed, 4 Jan 2017 15:34:55 -0600 Subject: [PATCH 13/16] Use efficient ConvertTo-StringSeq --- GitUtils.ps1 | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index 6672d1ac9..5e9f47b53 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -118,6 +118,16 @@ function GetUniquePaths($pathCollections) { $hash.Keys } +$castStringSeq = [Linq.Enumerable].GetMethod("Cast").MakeGenericMethod([string]) +$emptyStringSeq = [Linq.Enumerable].GetMethod("Empty").MakeGenericMethod([string]) +function ConvertTo-StringSeq ([Parameter(ValueFromPipeline=$true)][Object[]]$source) { + if (!$source) { + return ,$emptyStringSeq.Invoke($null, @()) + } + + return ,$castStringSeq.Invoke($null, (,$source)) +} + function Get-GitStatus($gitDir = (Get-GitDirectory)) { $settings = $Global:GitPromptSettings $enabled = (-not $settings) -or $settings.EnablePromptStatus @@ -153,17 +163,17 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { $cacheResponse = Get-GitStatusFromCache dbg 'Parsing status' $sw - $indexAdded.AddRange([string[]]$cacheResponse.IndexAdded) - $indexModified.AddRange([string[]]$cacheResponse.IndexModified) - $indexModified.AddRange([string[]]@($cacheResponse.IndexRenamed | Select-Object -ExpandProperty Old)) - $indexDeleted.AddRange([string[]]$cacheResponse.IndexDeleted) - $indexUnmerged.AddRange([string[]]$cacheResponse.Conflicted) - - $filesAdded.AddRange([string[]]$cacheResponse.WorkingAdded) - $filesModified.AddRange([string[]]$cacheResponse.WorkingModified) - $filesModified.AddRange([string[]]@($cacheResponse.WorkingRenamed | Select-Object -ExpandProperty Old)) - $filesDeleted.AddRange([string[]]$cacheResponse.WorkingDeleted) - $filesUnmerged.AddRange([string[]]$cacheResponse.Conflicted) + $indexAdded.AddRange(($cacheResponse.IndexAdded | ConvertTo-StringSeq)) + $indexModified.AddRange(($cacheResponse.IndexModified | ConvertTo-StringSeq)) + $indexModified.AddRange(($cacheResponse.IndexRenamed | Select-Object -ExpandProperty Old | ConvertTo-StringSeq)) + $indexDeleted.AddRange(($cacheResponse.IndexDeleted | ConvertTo-StringSeq)) + $indexUnmerged.AddRange(($cacheResponse.Conflicted | ConvertTo-StringSeq)) + + $filesAdded.AddRange(($cacheResponse.WorkingAdded | ConvertTo-StringSeq)) + $filesModified.AddRange(($cacheResponse.WorkingModified | ConvertTo-StringSeq)) + $filesModified.AddRange(($cacheResponse.WorkingRenamed | Select-Object -ExpandProperty Old | ConvertTo-StringSeq)) + $filesDeleted.AddRange(($cacheResponse.WorkingDeleted | ConvertTo-StringSeq)) + $filesUnmerged.AddRange(($cacheResponse.Conflicted | ConvertTo-StringSeq)) $branch = $cacheResponse.Branch $upstream = $cacheResponse.Upstream From 25a4c616f41d8582627841d033e0e7c828910deb Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Sat, 7 Jan 2017 15:47:52 -0600 Subject: [PATCH 14/16] Inline ConvertTo-StringSeq --- GitUtils.ps1 | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index 5e9f47b53..1db24d1e5 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -119,14 +119,6 @@ function GetUniquePaths($pathCollections) { } $castStringSeq = [Linq.Enumerable].GetMethod("Cast").MakeGenericMethod([string]) -$emptyStringSeq = [Linq.Enumerable].GetMethod("Empty").MakeGenericMethod([string]) -function ConvertTo-StringSeq ([Parameter(ValueFromPipeline=$true)][Object[]]$source) { - if (!$source) { - return ,$emptyStringSeq.Invoke($null, @()) - } - - return ,$castStringSeq.Invoke($null, (,$source)) -} function Get-GitStatus($gitDir = (Get-GitDirectory)) { $settings = $Global:GitPromptSettings @@ -163,17 +155,17 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { $cacheResponse = Get-GitStatusFromCache dbg 'Parsing status' $sw - $indexAdded.AddRange(($cacheResponse.IndexAdded | ConvertTo-StringSeq)) - $indexModified.AddRange(($cacheResponse.IndexModified | ConvertTo-StringSeq)) - $indexModified.AddRange(($cacheResponse.IndexRenamed | Select-Object -ExpandProperty Old | ConvertTo-StringSeq)) - $indexDeleted.AddRange(($cacheResponse.IndexDeleted | ConvertTo-StringSeq)) - $indexUnmerged.AddRange(($cacheResponse.Conflicted | ConvertTo-StringSeq)) - - $filesAdded.AddRange(($cacheResponse.WorkingAdded | ConvertTo-StringSeq)) - $filesModified.AddRange(($cacheResponse.WorkingModified | ConvertTo-StringSeq)) - $filesModified.AddRange(($cacheResponse.WorkingRenamed | Select-Object -ExpandProperty Old | ConvertTo-StringSeq)) - $filesDeleted.AddRange(($cacheResponse.WorkingDeleted | ConvertTo-StringSeq)) - $filesUnmerged.AddRange(($cacheResponse.Conflicted | ConvertTo-StringSeq)) + $indexAdded.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.IndexAdded)))) + $indexModified.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.IndexModified)))) + $indexModified.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.IndexRenamed | Select-Object -ExpandProperty Old)))) + $indexDeleted.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.IndexDeleted)))) + $indexUnmerged.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.Conflicted)))) + + $filesAdded.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.WorkingAdded)))) + $filesModified.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.WorkingModified)))) + $filesModified.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.WorkingRenamed | Select-Object -ExpandProperty Old)))) + $filesDeleted.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.WorkingDeleted)))) + $filesUnmerged.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.Conflicted)))) $branch = $cacheResponse.Branch $upstream = $cacheResponse.Upstream From 2b202c0cf4fddc47981134afe58647b763067d3d Mon Sep 17 00:00:00 2001 From: Marcus Reid Date: Fri, 13 Jan 2017 23:15:07 -0800 Subject: [PATCH 15/16] Fix cast break on PSObjects returned by Select-Object. --- GitUtils.ps1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index 8c77ddad8..6dacd0cf3 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -159,13 +159,19 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { $indexAdded.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.IndexAdded)))) $indexModified.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.IndexModified)))) - $indexModified.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.IndexRenamed | Select-Object -ExpandProperty Old)))) + $indexRenamedOld = $cacheResponse.IndexRenamed.Old + if ($indexRenamedOld) { + $indexModified.AddRange($castStringSeq.Invoke($null, (,@($indexRenamedOld)))) + } $indexDeleted.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.IndexDeleted)))) $indexUnmerged.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.Conflicted)))) $filesAdded.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.WorkingAdded)))) $filesModified.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.WorkingModified)))) - $filesModified.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.WorkingRenamed | Select-Object -ExpandProperty Old)))) + $workingRenamedOld = $cacheResponse.WorkingRenamed.Old + if ($workingRenamedOld) { + $filesModified.AddRange($castStringSeq.Invoke($null, (,@($workingRenamedOld)))) + } $filesDeleted.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.WorkingDeleted)))) $filesUnmerged.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.Conflicted)))) From 05015b9270afa05efcb93b1846e810fe5bb0d0df Mon Sep 17 00:00:00 2001 From: Marcus Reid Date: Sat, 14 Jan 2017 16:16:08 -0800 Subject: [PATCH 16/16] Remove member enumeration to support earlier versions of PowerShell. --- GitUtils.ps1 | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index 6dacd0cf3..24bc8a476 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -159,18 +159,16 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { $indexAdded.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.IndexAdded)))) $indexModified.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.IndexModified)))) - $indexRenamedOld = $cacheResponse.IndexRenamed.Old - if ($indexRenamedOld) { - $indexModified.AddRange($castStringSeq.Invoke($null, (,@($indexRenamedOld)))) + foreach ($indexRenamed in $cacheResponse.IndexRenamed) { + $indexModified.Add($indexRenamed.Old) } $indexDeleted.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.IndexDeleted)))) $indexUnmerged.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.Conflicted)))) $filesAdded.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.WorkingAdded)))) $filesModified.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.WorkingModified)))) - $workingRenamedOld = $cacheResponse.WorkingRenamed.Old - if ($workingRenamedOld) { - $filesModified.AddRange($castStringSeq.Invoke($null, (,@($workingRenamedOld)))) + foreach ($workingRenamed in $cacheResponse.WorkingRenamed) { + $filesModified.Add($workingRenamed.Old) } $filesDeleted.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.WorkingDeleted)))) $filesUnmerged.AddRange($castStringSeq.Invoke($null, (,@($cacheResponse.Conflicted))))