1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-29 06:51:03 +02:00

35105: completion: git: add distance_from_head to __git_recent_commits

This adds the "HEAD~15" gitrevisions(7) identifier of the commit to the
description, which also uniquifies, isn't redundant, and may be easier
to type.

Ref: zsh-workers/34820 (http://www.zsh.org/mla/workers/2015/msg00744.html)
This commit is contained in:
Daniel Shahaf 2015-05-13 16:14:32 +02:00 committed by Daniel Hahler
parent 733db1b411
commit 34a1489f43
2 changed files with 17 additions and 1 deletions

View file

@ -21,6 +21,9 @@
* 35106: completion: git: unique name for __git_recent_commits.
* Daniel Shahaf: 35105: Completion/Unix/Command/_git: add
distance_from_head to __git_recent_commits.
2015-05-16 Daniel Shahaf <d.s@daniel.shahaf.name>
* 35161: Completion/Unix/Command/_git: completion: git: Fix

View file

@ -5672,6 +5672,7 @@ __git_recent_commits () {
local gitdir expl start
declare -a descr tags heads commits
local i j k
integer distance_from_head
# 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.
@ -5681,7 +5682,19 @@ __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
descr+=("$i:[$i] $k")
if (( distance_from_head == 0 )); then
descr+=($i:"[HEAD] $k")
elif (( distance_from_head == 1 )); then
descr+=($i:"[HEAD^] $k")
elif (( distance_from_head == 2 )); then
descr+=($i:"[HEAD^^] $k")
elif (( distance_from_head < 10 )); then
descr+=($i:"[HEAD~$distance_from_head] $k")
else
descr+=($i:"[HEAD~$distance_from_head] $k")
fi
(( ++distance_from_head ))
j=${${j# \(}%\)} # strip leading ' (' and trailing ')'
j=${j/ ->/,} # Convert " -> master, origin/master".
for j in ${(s:, :)j}; do