From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4325 invoked by alias); 4 Jun 2016 16:57:55 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 38610 Received: (qmail 26758 invoked from network); 4 Jun 2016 16:57:54 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 From: Daniel Shahaf To: zsh-workers@zsh.org Subject: [PATCH 2/2] vcs_info quilt: Extract a patch subject, 2.0. Date: Sat, 4 Jun 2016 16:57:49 +0000 Message-Id: <1465059469-4335-2-git-send-email-danielsh@tarsus.local2> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1465059469-4335-1-git-send-email-danielsh@tarsus.local2> References: <1465059469-4335-1-git-send-email-danielsh@tarsus.local2> --- Functions/VCS_Info/VCS_INFO_quilt | 42 +++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/Functions/VCS_Info/VCS_INFO_quilt b/Functions/VCS_Info/VCS_INFO_quilt index e31deb0..009c9d4 100644 --- a/Functions/VCS_Info/VCS_INFO_quilt +++ b/Functions/VCS_Info/VCS_INFO_quilt @@ -83,15 +83,49 @@ function VCS_INFO_quilt-dirfind() { # 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() { - local line - if [[ -f "$1" ]] && read -r line < "$1"; then - if [[ $line != (#b)(---|Index:)* ]]; then - REPLY=$line + 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