* [PATCH 1/5] _git: Fix recent commit completion descriptions.
@ 2015-10-25 18:34 Daniel Shahaf
0 siblings, 0 replies; only message in thread
From: Daniel Shahaf @ 2015-10-25 18:34 UTC (permalink / raw)
To: zsh-workers
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-10-25 18:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-25 18:34 [PATCH 1/5] _git: Fix recent commit completion descriptions Daniel Shahaf
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).