From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24357 invoked by alias); 17 Feb 2014 04:01:52 -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: 32396 Received: (qmail 10389 invoked from network); 17 Feb 2014 04:01:37 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, T_TO_NO_BRKTS_FREEMAIL autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tpCB469J2rIqVDoauSc5GXxcAT1LOoAXbSTG4NW0GBw=; b=qxD48YVBRVDS0XLT4dx1U3BhNHlNYl9XwgyOVw1OPO0ZooR1yv71XgEk+cZnj8Ny+X pUnmE4mDdDouVutWIOADjSl5vsG0KI+uzMcc3feLnako0nOZeXIcmK7LTF9n+sHMJ7GP tTkdu/Qo8AreBqiD9hTqmue8qxOvQmQyFxk4Bv3XcK34pIbk3GdrL6+8ng0m3SwDQ7m8 zf9LJV18USFwmzUcekigrZXg7AXxCwEtC8j6sFwXgH/jsOPLBUzk+ippXmktIogfOvld sQXE4v+Xv1ynDsEfPxceSjLULuTNaU+GGsQCt9UdqdgYP9bdOy0hZjdhz9jF9V0uaj/7 7LdQ== X-Received: by 10.14.98.66 with SMTP id u42mr25122476eef.18.1392609693139; Sun, 16 Feb 2014 20:01:33 -0800 (PST) From: m0viefreak To: zsh-workers@zsh.org Cc: m0viefreak Subject: [PATCH 1/4] _git: fix __git_committish_range_{first,last} and __git_is_committish_range Date: Mon, 17 Feb 2014 05:00:36 +0100 Message-Id: <1392609639-2916-2-git-send-email-m0viefreak.cm@googlemail.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1392609639-2916-1-git-send-email-m0viefreak.cm@googlemail.com> References: <1392609639-2916-1-git-send-email-m0viefreak.cm@googlemail.com> - Ranges with 3 dots would always fail, because the non-greedy expansion %..(.|)* in __git_committish_range_first would only remove '..' and never three dots. 'a...b' would end up in 'a.'. Use ${${1%..*}%.} instead. - Use a similar approach for __git_committish_range_last. - Wrap them in another expansion to replace empty results with 'HEAD'. Git man-page states omitted range ending are being replaced with HEAD. This rule has to be followed to make completions like 'git log foo.. -- ' work properly. - Add an additional check to make sure none of the extracted first/last parts contain additional '..' in invalied ranges such as 'a..b..c'. This gets rid of the 'TODO:' and ideally saves a few unneded calls to git rev-parse. --- Completion/Unix/Command/_git | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index c09f255..8562ab2 100644 --- a/Completion/Unix/Command/_git +++ b/Completion/Unix/Command/_git @@ -4798,12 +4798,12 @@ __git_command_successful () { (( $+functions[__git_committish_range_first] )) || __git_committish_range_first () { - print -r -- ${1%..(.|)*} + print -r -- ${${${1%..*}%.}:-HEAD} } (( $+functions[__git_committish_range_last] )) || __git_committish_range_last () { - print -r -- ${1##*..(.|)} + print -r -- ${${${1#*..}#.}:-HEAD} } (( $+functions[__git_pattern_escape] )) || @@ -4832,12 +4832,12 @@ __git_is_treeish () { (( $+functions[__git_is_committish_range] )) || __git_is_committish_range () { - # TODO: This isn't quite right. We would like to do parts=${(~s:..(.|))}, - # but that doesn't work. (This would allow us to make sure that parts only - # contains two elements and then apply __git_is_committish on them. - [[ $1 == *..(.|)* ]] && - __git_is_committish $(__git_committish_range_first $1) && - __git_is_committish $(__git_committish_range_last $1) + [[ $1 == *..(.|)* ]] || return 1 + local first=$(__git_committish_range_first $1) + local last=$(__git_committish_range_last $1) + [[ $first != *..* && $last != *..* ]] && \ + __git_is_committish $first && \ + __git_is_committish $last } (( $+functions[__git_is_initial_commit] )) || -- 1.9.0.1.g7244ca4