summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Completion/Unix/Command/_git15
2 files changed, 17 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index a00c51162..68b644823 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 4222bf211..708eb2a06 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -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