Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
865f6572
Commit
865f6572
authored
Apr 14, 2018
by
Marc Cornellà
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix performance drop of iterating over lines and other stuff
- Fix 'STASHED' key and unsupported syntax in 5.0.2 - Optimise `if` statement to make it more idiomatic.
parent
45a954cb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
32 deletions
+30
-32
git.zsh
lib/git.zsh
+30
-32
No files found.
lib/git.zsh
View file @
865f6572
...
...
@@ -150,15 +150,11 @@ function git_prompt_long_sha() {
function
git_prompt_status
()
{
[[
"
$(
__git_prompt_git config
--get
oh-my-zsh.hide-status 2>/dev/null
)
"
=
1
]]
&&
return
local
status_prompt
=
""
# A lookup table of each git status encountered
local
-A
statuses_seen
# Maps a git status prefix to an internal constant
# This cannot use the prompt constants, as they may be empty
local
-A
prefix_constant_map
=(
'?? '
'UNTRACKED'
local
-A
prefix_constant_map
prefix_constant_map
=(
'\?\? '
'UNTRACKED'
'A '
'ADDED'
'M '
'ADDED'
'MM '
'ADDED'
...
...
@@ -176,7 +172,8 @@ function git_prompt_status() {
)
# Maps the internal constant to the prompt theme
local
-A
constant_prompt_map
=(
local
-A
constant_prompt_map
constant_prompt_map
=(
'UNTRACKED'
"
$ZSH_THEME_GIT_PROMPT_UNTRACKED
"
'ADDED'
"
$ZSH_THEME_GIT_PROMPT_ADDED
"
'MODIFIED'
"
$ZSH_THEME_GIT_PROMPT_MODIFIED
"
...
...
@@ -190,25 +187,33 @@ function git_prompt_status() {
)
# The order that the prompt displays should be added to the prompt
local
status_constants
=(
UNTRACKED ADDED MODIFIED RENAMED DELETED STASHED
UNMERGED AHEAD BEHIND DIVERGED
)
local
status_constants
status_constants
=(
UNTRACKED ADDED MODIFIED RENAMED DELETED
STASHED UNMERGED AHEAD BEHIND DIVERGED
)
local
status_text
=
$(
__git_prompt_git status
--porcelain
-b
2> /dev/null
)
local
status_text
=
"
$(
__git_prompt_git status
--porcelain
-b
2> /dev/null
)
"
# Don't continue on a catastrophic failure
if
[[
$?
-eq
128
]]
;
then
return
1
fi
if
$(
__git_prompt_git rev-parse
--verify
refs/stash
>
/dev/null 2>&1
)
;
then
statuses_seen[
'STASHED'
]=
1
# A lookup table of each git status encountered
local
-A
statuses_seen
if
__git_prompt_git rev-parse
--verify
refs/stash &>/dev/null
;
then
statuses_seen[STASHED]
=
1
fi
local
status_lines
=(
"
${
(@f)
${
status_text
}}
"
)
;
local
status_lines
status_lines
=(
"
${
(@f)
${
status_text
}}
"
)
# If the tracking line exists, get and parse it
if
[[
$status_lines
[
1]
=
~
"^## [^ ]+
\[
(.*)
\]
"
]]
;
then
local
branch_statuses
=(
"
${
(@s/,/)match
}
"
)
if
[[
"
$status_lines
[1]"
=
~
"^## [^ ]+
\[
(.*)
\]
"
]]
;
then
local
branch_statuses
branch_statuses
=(
"
${
(@s/,/)match
}
"
)
for
branch_status
in
$branch_statuses
;
do
if
[[
!
$branch_status
=
~
"(behind|diverged|ahead) ([0-9]+)?"
]]
;
then
continue
...
...
@@ -216,29 +221,22 @@ function git_prompt_status() {
local
last_parsed_status
=
$prefix_constant_map
[
$match
[
1]]
statuses_seen[
$last_parsed_status
]=
$match
[
2]
done
shift
status_lines
fi
#
This not only gives us a status lookup, but the count of each type
for
status_
line
in
${
status_lines
}
;
do
local
status_
prefix
=
${
status_line
[1, 3]
}
local
status_
constant
=
${
(v)prefix_constant_map[
$status_prefix
]
}
#
For each status prefix, do a regex comparison
for
status_
prefix
in
${
(k)prefix_constant_map
}
;
do
local
status_
constant
=
"
${
prefix_constant_map
[
$status_prefix
]
}
"
local
status_
regex
=
"(^|
\n
)
$status_prefix
"
if
[[
-z
$status_constant
]]
;
then
continue
if
[[
"
$status_text
"
=
~
$status_regex
]]
;
then
statuses_seen[
$status_constant
]=
1
fi
((
statuses_seen[
$status_constant
]
++
))
done
# At this point, the statuses_seen hash contains:
# - Tracking => The difference between tracked and current
# - Modifications => The count of that type of modification
# - Stash => Whether or not a stash exists
# Might be useful for someone?
# Display the seen statuses in the order specified
local
status_prompt
for
status_constant
in
$status_constants
;
do
if
[[
${
+statuses_seen[
$status_constant
]
}
-eq
1
]]
;
then
if
((
${
+statuses_seen[
$status_constant
]
}
))
;
then
local
next_display
=
$constant_prompt_map
[
$status_constant
]
status_prompt
=
"
$next_display$status_prompt
"
fi
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment