1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-01-01 05:16:05 +01:00

unposted: vcs_info: Break out VCS_INFO_quilt-patch2subject into VCS_INFO_patch2subject

... so other places can use it; compare 40030 in the 39990 thread.
This commit is contained in:
Daniel Shahaf 2016-12-01 17:11:58 +00:00
parent 1ba59c4147
commit 8891f5a33d
4 changed files with 59 additions and 48 deletions

View file

@ -1,3 +1,10 @@
2016-12-01 Daniel Shahaf <d.s@daniel.shahaf.name>
* unposted: Functions/VCS_Info/VCS_INFO_patch2subject,
Functions/VCS_Info/VCS_INFO_quilt, Functions/VCS_Info/vcs_info:
vcs_info: Break out VCS_INFO_quilt-patch2subject into
VCS_INFO_patch2subject
2016-12-01 Mikael Magnusson <mikachu@gmail.com>
* 40024: Completion/Unix/Type/_path_files: Update _path_files

View file

@ -0,0 +1,50 @@
# This function takes as an argument a filename of a patch and sets $REPLY to
# a single-line "subject", or unsets it if no subject could be extracted.
{
integer i
integer -r LIMIT=10
local -a lines
local needle
if [[ -f "$1" ]]; then
# Extract the first LIMIT lines, or up to the first empty line or the start of the unidiffs,
# whichever comes first.
while (( i++ < LIMIT )); do
IFS= read -r "lines[$i]"
if [[ -z ${lines[$i]} ]] || [[ ${lines[$i]} == (#b)(---|Index:)* ]]; then
lines[$i]=()
break
fi
done < "$1"
if needle=${lines[(i)Subject:*]}; (( needle <= $#lines )); then
# "Subject: foo" line, plus rfc822 whitespace unfolding.
#
# Example: 'git format-patch' patches.
REPLY=${lines[needle]}
REPLY=${REPLY#*: }
REPLY=${REPLY#\[PATCH\] }
while [[ ${${lines[++needle]}[1]} == ' ' ]]; do
REPLY+=${lines[needle]}
done
elif needle=${lines[(r)Description:*]}; [[ -n $needle ]]; then
# "Description: foo" line.
#
# Example: DEP-3 patches.
REPLY=${needle#*: }
elif [[ ${lines[1]} == '# HG changeset patch' ]] && { needle=${${lines:#([#]*)}[1]}; [[ -n $needle ]] }; then
# Mercurial patch
REPLY=$needle
elif (( ${+lines[1]} )); then
# The first line of the file is not part of the diff.
REPLY=${lines[1]}
else
# The patch has no subject.
unset REPLY
return 0
fi
else
# The patch cannot be examined, or invalid arguments.
unset REPLY
return 1
fi
}

View file

@ -80,55 +80,8 @@ function VCS_INFO_quilt-dirfind() {
return ${ret}
}
# This function takes as an argument a filename of a patch and sets $REPLY to
# a single-line "subject", or unsets it if no subject could be extracted.
function VCS_INFO_quilt-patch2subject() {
integer i
integer -r LIMIT=10
local -a lines
local needle
if [[ -f "$1" ]]; then
# Extract the first LIMIT lines, or up to the first empty line or the start of the unidiffs,
# whichever comes first.
while (( i++ < LIMIT )); do
IFS= read -r "lines[$i]"
if [[ -z ${lines[$i]} ]] || [[ ${lines[$i]} == (#b)(---|Index:)* ]]; then
lines[$i]=()
break
fi
done < "$1"
if needle=${lines[(i)Subject:*]}; (( needle <= $#lines )); then
# "Subject: foo" line, plus rfc822 whitespace unfolding.
#
# Example: 'git format-patch' patches.
REPLY=${lines[needle]}
REPLY=${REPLY#*: }
REPLY=${REPLY#\[PATCH\] }
while [[ ${${lines[++needle]}[1]} == ' ' ]]; do
REPLY+=${lines[needle]}
done
elif needle=${lines[(r)Description:*]}; [[ -n $needle ]]; then
# "Description: foo" line.
#
# Example: DEP-3 patches.
REPLY=${needle#*: }
elif [[ ${lines[1]} == '# HG changeset patch' ]] && { needle=${${lines:#([#]*)}[1]}; [[ -n $needle ]] }; then
# Mercurial patch
REPLY=$needle
elif (( ${+lines[1]} )); then
# The first line of the file is not part of the diff.
REPLY=${lines[1]}
else
# The patch has no subject.
unset REPLY
return 0
fi
else
# The patch cannot be examined, or invalid arguments.
unset REPLY
return 1
fi
VCS_INFO_patch2subject "$@"
}
function VCS_INFO_quilt() {

View file

@ -23,6 +23,7 @@ static_functions=(
VCS_INFO_hook
VCS_INFO_maxexports
VCS_INFO_nvcsformats
VCS_INFO_patch2subject
VCS_INFO_quilt
VCS_INFO_realpath
VCS_INFO_reposub