<commit_before>GIT_PROMPT_ORDER=(
	"prefix"
	"branch"
	"behind"
	"ahead"
	"separator"
	"staged"
	"changed"
	"conflicts"
	"untracked"
	"clean"
	"suffix"
)

declare -A GIT_PROMPT_SYMBOLS
GIT_PROMPT_SYMBOLS=(
	"prefix" "%F{250}[%f"
	"branch" "%F{120}"
	"behind" "%F{216}%{←%G%}"
	"ahead" "%F{216}%{→%G%}"
	"separator" "%F{250}|%f"
	"staged" "%F{117}%{♦%G%}"
	"changed" "%F{226}%{◊%G%}"
	"conflicts" "%F{9}%{≠%G%}"
	"untracked" "%F{214}%{…%G%}"
	"clean" "%F{10}%B%{✓%G%}%b"
	"suffix" "%F{250}]%f"
)

declare -A GIT_STATUS_MAP
GIT_STATUS_MAP=(
	' M' 'changed'    # not updated, work tree changed since index
	' D' 'changed'    # not updated, deleted in work tree
	'M ' 'staged'     # updated in index, index and work tree matches
	'MM' 'changed'    # updated in index, work tree changed since index
	'MD' 'changed'    # updated in index, deleted in work tree
	'A ' 'staged'     # added to index, index and work tree matches
	'AM' 'changed'    # added to index, work tree changed since index
	'AD' 'changed'    # added to index, deleted in work tree
	'D ' 'staged'     # deleted from index
	'DM' 'changed'    # deleted from index
	'R ' 'staged'     # renamed in index, index and work tree matches
	'RM' 'changed'    # renamed in index, work tree changed since index
	'RD' 'changed'    # renamed in index, deleted in work tree
	'C ' 'staged'     # copied in index, index and work tree matches
	'CM' 'changed'    # copied in index, work tree changed since index
	'CD' 'changed'    # copied in index, deleted in work tree
	'DD' 'conflicts'  # unmerged, both deleted
	'AU' 'conflicts'  # unmerged, added by us
	'UD' 'conflicts'  # unmerged, deleted by them
	'UA' 'conflicts'  # unmerged, added by them
	'DU' 'conflicts'  # unmerged, deleted by us
	'AA' 'conflicts'  # unmerged, both added
	'UU' 'conflicts'  # unmerged, both modified
	'??' 'untracked'  # untracked
	'!!' 'ignored'    # ignored
)

GIT_PROMPT_FIFO_DIR="$HOME/.tmp/zsh-git-prompt"

function git_get_status() {
	local status_string map_status chunk chunk_index mapped_status
	local -a status_chunks
	local -A git_flags git_strings git_numbers
	status_string="$(git status --branch -u --porcelain -z 2> /dev/null)"
	if [[ $? -ne 0 ]]; then
		git_flags=(
			"in_repo" 0
		)
		typeset -p git_flags git_strings git_numbers
		return
	fi
	for map_status in $GIT_STATUS_MAP; do
		git_numbers[$map_status]=0
	done
	status_chunks=(${(0)status_string})
	chunk_index=1
	while [[ chunk_index -le ${#status_chunks} ]]; do
		chunk="${status_chunks[$chunk_index]}"
		if [[ "${chunk:0:2}" == '##' ]]; then
			git_parse_status_header "${chunk:2}"
			git_strings[branch]="$RETURN_BRANCH"
			git_numbers[ahead]=$RETURN_AHEAD
			git_numbers[behind]=$RETURN_BEHIND
		else
			mapped_status=${GIT_STATUS_MAP[${chunk:0:2}]}
			git_numbers[$mapped_status]=$((git_numbers[$mapped_status] + 1))
		fi
		if [[ "${chunk:0:2}" == R* ]]; then
			chunk_index=$((chunk_index + 2))
		else
			chunk_index=$((chunk_index + 1))
		fi
	done
	git_flags[in_repo]=1
	git_flags[clean]=0
	if [[ \
		${git_numbers[staged]} -eq 0
		&& ${git_numbers[changed]} -eq 0
		&& ${git_numbers[conflicts]} -eq 0
		&& ${git_numbers[untracked]} -eq 0
	]] then
		git_flags[clean]=1
	fi
	typeset -p git_flags git_strings git_numbers
}

function git_parse_status_header() {
	local branches divergence div
	typeset -g RETURN_AHEAD RETURN_BEHIND RETURN_BRANCH<commit_msg>Fix parsing of lines describing copied files<commit_after>GIT_PROMPT_ORDER=(
	"prefix"
	"branch"
	"behind"
	"ahead"
	"separator"
	"staged"
	"changed"
	"conflicts"
	"untracked"
	"clean"
	"suffix"
)

declare -A GIT_PROMPT_SYMBOLS
GIT_PROMPT_SYMBOLS=(
	"prefix" "%F{250}[%f"
	"branch" "%F{120}"
	"behind" "%F{216}%{←%G%}"
	"ahead" "%F{216}%{→%G%}"
	"separator" "%F{250}|%f"
	"staged" "%F{117}%{♦%G%}"
	"changed" "%F{226}%{◊%G%}"
	"conflicts" "%F{9}%{≠%G%}"
	"untracked" "%F{214}%{…%G%}"
	"clean" "%F{10}%B%{✓%G%}%b"
	"suffix" "%F{250}]%f"
)

declare -A GIT_STATUS_MAP
GIT_STATUS_MAP=(
	' M' 'changed'    # not updated, work tree changed since index
	' D' 'changed'    # not updated, deleted in work tree
	'M ' 'staged'     # updated in index, index and work tree matches
	'MM' 'changed'    # updated in index, work tree changed since index
	'MD' 'changed'    # updated in index, deleted in work tree
	'A ' 'staged'     # added to index, index and work tree matches
	'AM' 'changed'    # added to index, work tree changed since index
	'AD' 'changed'    # added to index, deleted in work tree
	'D ' 'staged'     # deleted from index
	'DM' 'changed'    # deleted from index
	'R ' 'staged'     # renamed in index, index and work tree matches
	'RM' 'changed'    # renamed in index, work tree changed since index
	'RD' 'changed'    # renamed in index, deleted in work tree
	'C ' 'staged'     # copied in index, index and work tree matches
	'CM' 'changed'    # copied in index, work tree changed since index
	'CD' 'changed'    # copied in index, deleted in work tree
	'DD' 'conflicts'  # unmerged, both deleted
	'AU' 'conflicts'  # unmerged, added by us
	'UD' 'conflicts'  # unmerged, deleted by them
	'UA' 'conflicts'  # unmerged, added by them
	'DU' 'conflicts'  # unmerged, deleted by us
	'AA' 'conflicts'  # unmerged, both added
	'UU' 'conflicts'  # unmerged, both modified
	'??' 'untracked'  # untracked
	'!!' 'ignored'    # ignored
)

GIT_PROMPT_FIFO_DIR="$HOME/.tmp/zsh-git-prompt"

function git_get_status() {
	local status_string map_status chunk chunk_index mapped_status
	local -a status_chunks
	local -A git_flags git_strings git_numbers
	status_string="$(git status --branch -u --porcelain -z 2> /dev/null)"
	if [[ $? -ne 0 ]]; then
		git_flags=(
			"in_repo" 0
		)
		typeset -p git_flags git_strings git_numbers
		return
	fi
	for map_status in $GIT_STATUS_MAP; do
		git_numbers[$map_status]=0
	done
	status_chunks=(${(0)status_string})
	chunk_index=1
	while [[ chunk_index -le ${#status_chunks} ]]; do
		chunk="${status_chunks[$chunk_index]}"
		if [[ "${chunk:0:2}" == '##' ]]; then
			git_parse_status_header "${chunk:2}"
			git_strings[branch]="$RETURN_BRANCH"
			git_numbers[ahead]=$RETURN_AHEAD
			git_numbers[behind]=$RETURN_BEHIND
		else
			mapped_status=${GIT_STATUS_MAP[${chunk:0:2}]}
			git_numbers[$mapped_status]=$((git_numbers[$mapped_status] + 1))
		fi
		if [[ "${chunk:0:2}" == R* || "${chunk:0:2}" == C* ]]; then
			chunk_index=$((chunk_index + 2))
		else
			chunk_index=$((chunk_index + 1))
		fi
	done
	git_flags[in_repo]=1
	git_flags[clean]=0
	if [[ \
		${git_numbers[staged]} -eq 0
		&& ${git_numbers[changed]} -eq 0
		&& ${git_numbers[conflicts]} -eq 0
		&& ${git_numbers[untracked]} -eq 0
	]] then
		git_flags[clean]=1
	fi
	typeset -p git_flags git_strings git_numbers
}

function git_parse_status_header() {
	local branches divergence div
	typeset -g RETURN_AHEAD RETURN_BEHIND RETURN_BRANCH
{'fraction_non_alphanumeric': 0.1585239852398524, 'fraction_numerical': 0.015940959409594096, 'mean_word_length': 4.373513084853291, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2104253', 'n_tokens_mistral': 2847, 'n_tokens_neox': 2607, 'n_words': 687}