Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: completion: git: --fixup: problem with _describe -2V and duplicate commit subjects



Daniel Shahaf wrote on Sun, Mar 29, 2015 at 05:47:53 +0000:
> > As a workaround I could imagine also adding the date, which is useful
> > by itself:
...
> Actually, I'm tempted to deduplicate it by throwing the hash into the
> description:

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

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 5524cb0..00b124d 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5645,13 +5645,27 @@ __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!
   : "${(A)commits::=${(@f)"$(_call_program commits git --no-pager log -20 --format='%h%n%d%n%s')"}}"
   __git_command_successful $pipestatus || return 1
 
   for i j k in "$commits[@]" ; do
-    descr+=($i:$k)
+    # 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")
+    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 ')'
     for j in ${(s:, :)j}; do
       if [[ $j == 'tag: '* ]] ; then

I came up with this because copying the hex digits is annoying.  (It's
basically a captcha.)  I'm half seriously considering binding '=' to
a widget that inserts '=<TAB>HEAD~' if [[ $LBUFFER == *--fixup ]], to
allow me to type just '--fixup=12' to get '--fixup=HEAD~12'.



Messages sorted by: Reverse Date, Date, Thread, Author