>From a7936c3d11dae2cecfb185cba2db5310c9e9c2b4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 30 Aug 2015 11:41:32 +0000 Subject: [PATCH 2/3] Don't show wrong labels --- Completion/Unix/Command/_git | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index 69d7719..dd2d771 100644 --- a/Completion/Unix/Command/_git +++ b/Completion/Unix/Command/_git @@ -5640,6 +5640,7 @@ __git_recent_commits () { declare -a descr tags heads commits argument_array_names commit_opts local i j k ret integer distance_from_head + local label zparseopts -D -E O:=argument_array_names # Turn (-O foo:bar) to (foo bar) @@ -5654,17 +5655,25 @@ __git_recent_commits () { for i j k in "$commits[@]" ; do # Note: the after-the-colon part must be unique across the entire array; # see workers/34768 - if (( distance_from_head == 0 )); then - descr+=($i:"[HEAD] $k") + if (( $#commit_opts )); then + # $commit_opts is set, so the commits we receive might not be in order, + # or might not be ancestors of HEAD. However, we must make the + # 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 - descr+=($i:"[HEAD^] $k") + label="[HEAD^] " elif (( distance_from_head == 2 )); then - descr+=($i:"[HEAD^^] $k") + label="[HEAD^^] " elif (( distance_from_head < 10 )); then - descr+=($i:"[HEAD~$distance_from_head] $k") + label="[HEAD~$distance_from_head] " else - descr+=($i:"[HEAD~$distance_from_head] $k") + label="[HEAD~$distance_from_head]" 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 ')' -- 2.1.4