From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21372 invoked by alias); 25 Oct 2015 18:42:58 -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: 36958 Received: (qmail 27362 invoked from network); 25 Oct 2015 18:42:55 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=content-type:date:from:message-id :mime-version:subject:to:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=g2L pE27OO2E5XsjYR3DXUV9qk5k=; b=goQo2MdIdvLlpBAtxiQll3eOKYKPdMYgj1a vxSbvfK8K+0JDDLpTUYQemmGWz++6/YFoSOw0NUzYaP3S8Mtk3Ke4BgZjc++9lAl 0pvgowdx9wSkXKnB9kWelX/sCM0/VAPBiISqTAd3tzduv5f7BDMqe2Dq6xSYi+cR Rohoab/g= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=g2 LpE27OO2E5XsjYR3DXUV9qk5k=; b=qAvE8Yq9o3kV3HE1Y1ucl0UesCMoNlf3cp f0dYoGJXwAH7Eg2dwc1bnlluMYO9gzE55EJFwd10umoSKQqAfoyDHS7Wc8Q/G1hd 6DiBydnVl+plaOKQRHR3YPQGq6hszIBHwixq1GiVSEqiLFpO4WXJ9PwbUZ9EXFt3 /wiOMkNGA= X-Sasl-enc: BAqVQ26nhr+JnCXv9zVrW8egPLXNXuOe/Wsfcr64g+Ue 1445798052 Date: Sun, 25 Oct 2015 18:34:08 +0000 From: Daniel Shahaf To: zsh-workers@zsh.org Subject: [PATCH 1/5] _git: Fix recent commit completion descriptions. Message-ID: <20151025183408.GJ11372@tarsus.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) The uniquifiers 'HEAD~$n' were incorrect when a recent commit was the second parent of a merge commit. Detect that case and print something correct instead. --- Completion/Unix/Command/_git | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index 719d717..7f9881f 100644 --- a/Completion/Unix/Command/_git +++ b/Completion/Unix/Command/_git @@ -5650,6 +5650,8 @@ __git_recent_commits () { local i j k ret integer distance_from_head local label + local parents + local next_first_parent_ancestral_line_commit zparseopts -D -E O:=argument_array_names # Turn (-O foo:bar) to (foo bar) @@ -5659,10 +5661,10 @@ __git_recent_commits () { # Careful: most %d will expand to the empty string. Quote properly! # NOTE: we could use %D directly, but it's not available in git 1.9.1 at least. - commits=("${(f)"$(_call_program commits git --no-pager log $commit_opts -20 --format='%h%n%d%n%s\ \(%cr\)')"}") + commits=("${(f)"$(_call_program commits git --no-pager log $commit_opts -20 --format='%h%n%d%n%s\ \(%cr\)%n%p')"}") __git_command_successful $pipestatus || return 1 - for i j k in "$commits[@]" ; do + for i j k parents in "$commits[@]" ; do # Note: the after-the-colon part must be unique across the entire array; # see workers/34768 if (( $#commit_opts )); then @@ -5671,20 +5673,35 @@ __git_recent_commits () { # description unique (due to workers/34768), which we do by including the # hash. Git always prints enough hash digits to make the output unique.) label="[$i]" - elif (( distance_from_head == 0 )); then - label="[HEAD] " - elif (( distance_from_head == 1 )); then - label="[HEAD^] " - elif (( distance_from_head == 2 )); then - label="[HEAD^^] " - elif (( distance_from_head < 10 )); then - label="[HEAD~$distance_from_head] " + elif (( distance_from_head )) && [[ $i != $next_first_parent_ancestral_line_commit ]]; then + # The first commit (HEAD), and its ancestors along the first-parent line, + # get HEAD~$n labels. + # + # For other commits, we just print the hash. (${parents} does provide enough + # information to compute HEAD~3^2~4 -style labels, though, if somebody cared + # enough to implement that.) + label="[$i]" else - label="[HEAD~$distance_from_head]" + # Compute a first-parent-ancestry commit's label. + if false ; then + elif (( distance_from_head == 0 )); then + label="[HEAD] " + elif (( distance_from_head == 1 )); then + label="[HEAD^] " + elif (( distance_from_head == 2 )); then + label="[HEAD^^] " + elif (( distance_from_head < 10 )); then + label="[HEAD~$distance_from_head] " + else + label="[HEAD~$distance_from_head]" + fi + + # Prepare for the next first-parent-ancestry commit. + (( ++distance_from_head )) + next_first_parent_ancestral_line_commit=${parents%% *} fi # label is now 9 bytes, so the descriptions ($k) will be aligned. descr+=($i:"${label} $k") - (( ++distance_from_head )) j=${${j# \(}%\)} # strip leading ' (' and trailing ')' j=${j/ ->/,} # Convert " -> master, origin/master". -- 2.1.4