Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance Optimization: Added an option to get a more concise git status #924

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions src/GitPrompt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,20 @@ function Write-GitIndexStatus {
$NoLeadingSpace = $false
}

$indexStatusText += "$($s.FileAddedText)$($Status.Index.Added.Count)"
if ($settings.EnableFileConciseStatusFromCache) {
$added = $status.Index.Added
$modified = $status.Index.Modified
$deleted = $status.Index.Deleted
$unmerged = $status.Index.Unmerged
}
else {
$added = $status.Index.Added.Count
$modified = $status.Index.Modified.Count
$deleted = $status.Index.Deleted.Count
$unmerged = $status.Index.Unmerged.Count
}

$indexStatusText += "$($s.FileAddedText)$($added)"

if ($StringBuilder) {
$StringBuilder | Write-Prompt $indexStatusText -Color $s.IndexColor > $null
Expand All @@ -587,7 +600,7 @@ function Write-GitIndexStatus {
$NoLeadingSpace = $false
}

$indexStatusText += "$($s.FileModifiedText)$($status.Index.Modified.Count)"
$indexStatusText += "$($s.FileModifiedText)$($modified)"

if ($StringBuilder) {
$StringBuilder | Write-Prompt $indexStatusText -Color $s.IndexColor > $null
Expand All @@ -604,7 +617,7 @@ function Write-GitIndexStatus {
$NoLeadingSpace = $false
}

$indexStatusText += "$($s.FileRemovedText)$($Status.Index.Deleted.Count)"
$indexStatusText += "$($s.FileRemovedText)$($deleted)"

if ($StringBuilder) {
$StringBuilder | Write-Prompt $indexStatusText -Color $s.IndexColor > $null
Expand All @@ -621,7 +634,7 @@ function Write-GitIndexStatus {
$NoLeadingSpace = $false
}

$indexStatusText += "$($s.FileConflictedText)$($Status.Index.Unmerged.Count)"
$indexStatusText += "$($s.FileConflictedText)$($unmerged)"

if ($StringBuilder) {
$StringBuilder | Write-Prompt $indexStatusText -Color $s.IndexColor > $null
Expand Down Expand Up @@ -685,7 +698,20 @@ function Write-GitWorkingDirStatus {
$NoLeadingSpace = $false
}

$workingStatusText += "$($s.FileAddedText)$($Status.Working.Added.Count)"
if ($settings.EnableFileConciseStatusFromCache) {
$added = $status.Working.Added
$modified = $status.Working.Modified
$deleted = $status.Working.Deleted
$unmerged = $status.Working.Unmerged
}
else {
$added = $status.Working.Added.Count
$modified = $status.Working.Modified.Count
$deleted = $status.Working.Deleted.Count
$unmerged = $status.Working.Unmerged.Count
}

$workingStatusText += "$($s.FileAddedText)$($added)"

if ($StringBuilder) {
$StringBuilder | Write-Prompt $workingStatusText -Color $s.WorkingColor > $null
Expand All @@ -702,7 +728,7 @@ function Write-GitWorkingDirStatus {
$NoLeadingSpace = $false
}

$workingStatusText += "$($s.FileModifiedText)$($Status.Working.Modified.Count)"
$workingStatusText += "$($s.FileModifiedText)$($modified)"

if ($StringBuilder) {
$StringBuilder | Write-Prompt $workingStatusText -Color $s.WorkingColor > $null
Expand All @@ -719,7 +745,7 @@ function Write-GitWorkingDirStatus {
$NoLeadingSpace = $false
}

$workingStatusText += "$($s.FileRemovedText)$($Status.Working.Deleted.Count)"
$workingStatusText += "$($s.FileRemovedText)$($deleted)"

if ($StringBuilder) {
$StringBuilder | Write-Prompt $workingStatusText -Color $s.WorkingColor > $null
Expand All @@ -736,7 +762,7 @@ function Write-GitWorkingDirStatus {
$NoLeadingSpace = $false
}

$workingStatusText += "$($s.FileConflictedText)$($Status.Working.Unmerged.Count)"
$workingStatusText += "$($s.FileConflictedText)$($unmerged)"

if ($StringBuilder) {
$StringBuilder | Write-Prompt $workingStatusText -Color $s.WorkingColor > $null
Expand Down
73 changes: 65 additions & 8 deletions src/GitUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function Get-GitStatus {
$fileStatusEnabled = $Force -or $settings.EnableFileStatus
# Optimization: short-circuit to avoid InDotGitOrBareRepoDir and InDisabledRepository if !$fileStatusEnabled
if ($fileStatusEnabled -and !$($isDotGitOrBare = InDotGitOrBareRepoDir $GitDir) -and !$(InDisabledRepository)) {
if ($null -eq $settings.EnableFileStatusFromCache) {
if ($null -eq $settings.EnableFileStatusFromCache -and !$settings.EnableFileConciseStatusFromCache) {
$settings.EnableFileStatusFromCache = $null -ne (Get-Module GitStatusCachePoshClient)
}

Expand Down Expand Up @@ -320,6 +320,47 @@ function Get-GitStatus {
$branch += "|" + $cacheResponse.State
}
}
}
elseif ($settings.EnableFileConciseStatusFromCache) {
dbg 'Getting concise status from cache' $sw
$cacheResponse = Get-GitConciseStatusFromCache

if ($cacheResponse.Error) {
# git-status-cache failed; set $global:GitStatusCacheLoggingEnabled = $true, call Restart-GitStatusCache,
# and check %temp%\GitStatusCache_[timestamp].log for details.
dbg "Cache returned an error: $($cacheResponse.Error)" $sw
$branch = "CACHE ERROR"
$behindBy = 1
}
else {
dbg 'Parsing status' $sw

$indexAdded = $cacheResponse.IndexAdded
$indexDeleted= $cacheResponse.IndexDeleted
$indexModified = $cacheResponse.IndexModified + $cacheResponse.IndexRenamed
$indexUnmerged = $cacheResponse.Conflicted

$filesAdded = $cacheResponse.WorkingAdded
$filesDeleted= $cacheResponse.IndexDeleted
$filesModified = $cacheResponse.WorkingModified + $cacheResponse.WorkingRenamed
$filesUnmerged = $cacheResponse.Conflicted

$branch = $cacheResponse.Branch
$upstream = $cacheResponse.Upstream
$gone = $cacheResponse.UpstreamGone
$aheadBy = $cacheResponse.AheadBy
$behindBy = $cacheResponse.BehindBy

if ($settings.EnableStashStatus -and $cacheResponse.Stashes) {
$stashCount = $cacheResponse.Stashes.Length
}

if ($cacheResponse.State) {
$branch += "|" + $cacheResponse.State
}
}


}
else {
dbg 'Getting status' $sw
Expand Down Expand Up @@ -392,23 +433,39 @@ function Get-GitStatus {
$branch = Get-GitBranch -Branch $branch -GitDir $GitDir -IsDotGitOrBare:$isDotGitOrBare -sw $sw

dbg 'Building status object' $sw
if ($settings.EnableFileConciseStatusFromCache) {
$indexPaths = @(GetUniquePaths $indexAdded, $indexModified, $indexDeleted, $indexUnmerged)
$workingPaths = @(GetUniquePaths $filesAdded, $filesModified, $filesDeleted, $filesUnmerged)
$index = (, $indexPaths) |
Add-Member -Force -PassThru NoteProperty Added $indexAdded |
Add-Member -Force -PassThru NoteProperty Modified $indexModified |
Add-Member -Force -PassThru NoteProperty Deleted $indexDeleted |
Add-Member -Force -PassThru NoteProperty Unmerged $indexUnmerged

$working = (, $workingPaths) |
Add-Member -Force -PassThru NoteProperty Added $filesAdded |
Add-Member -Force -PassThru NoteProperty Modified $filesModified |
Add-Member -Force -PassThru NoteProperty Deleted $filesDeleted |
Add-Member -Force -PassThru NoteProperty Unmerged $filesUnmerged
}
else {
# This collection is used twice, so create the array just once
$filesAdded = $filesAdded.ToArray()

# 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) |
$indexPaths = @(GetUniquePaths $indexAdded, $indexModified, $indexDeleted, $indexUnmerged)
$workingPaths = @(GetUniquePaths $filesAdded, $filesModified, $filesDeleted, $filesUnmerged)
$index = (, $indexPaths) |
Add-Member -Force -PassThru NoteProperty Added $indexAdded.ToArray() |
Add-Member -Force -PassThru NoteProperty Modified $indexModified.ToArray() |
Add-Member -Force -PassThru NoteProperty Deleted $indexDeleted.ToArray() |
Add-Member -Force -PassThru NoteProperty Unmerged $indexUnmerged.ToArray()

$working = (, $workingPaths) |
$working = (, $workingPaths) |
Add-Member -Force -PassThru NoteProperty Added $filesAdded |
Add-Member -Force -PassThru NoteProperty Modified $filesModified.ToArray() |
Add-Member -Force -PassThru NoteProperty Deleted $filesDeleted.ToArray() |
Add-Member -Force -PassThru NoteProperty Unmerged $filesUnmerged.ToArray()
}

$result = New-Object PSObject -Property @{
GitDir = $GitDir
Expand Down
1 change: 1 addition & 0 deletions src/PoshGitTypes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ class PoshGitPromptSettings {
[bool]$EnableFileStatus = $true

[Nullable[bool]]$EnableFileStatusFromCache = $null
[Nullable[bool]]$EnableFileConciseStatusFromCache = $null
[string[]]$RepositoriesInWhichToDisableFileStatus = @()

[string]$DescribeStyle = ''
Expand Down