* completion: git: various improvements to commit object handling
@ 2015-05-13 14:26 Daniel Hahler
2015-05-13 14:26 ` [PATCH 1/7] completion: git: __git_recent_commits: remove ' ->*' from heads Daniel Hahler
` (7 more replies)
0 siblings, 8 replies; 10+ messages in thread
From: Daniel Hahler @ 2015-05-13 14:26 UTC (permalink / raw)
To: zsh-workers
I've also submitted it as a pull request against the zsh-users' mirror on Github:
https://github.com/zsh-users/zsh/pull/4
[PATCH 1/7] completion: git: __git_recent_commits: remove ' ->*' from
[PATCH 2/7] completion: git: use %D for %d, without the " (", ")"
[PATCH 3/7] completion: git: add __git_commit_objects_prefer_recent
[PATCH 4/7] completion: git: __git_commit_objects: query 1000 commits
[PATCH 5/7] completion: git: add %cr to commit objects (all and
[PATCH 6/7] completion: git: unique name for __git_recent_commits
[PATCH 7/7] completion: git: add distance_from_head to
Regards,
Daniel.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/7] completion: git: __git_recent_commits: remove ' ->*' from heads
2015-05-13 14:26 completion: git: various improvements to commit object handling Daniel Hahler
@ 2015-05-13 14:26 ` Daniel Hahler
2015-05-13 14:26 ` [PATCH 2/7] completion: git: use %D for %d, without the " (", ")" wrapping Daniel Hahler
` (6 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Daniel Hahler @ 2015-05-13 14:26 UTC (permalink / raw)
To: zsh-workers
From: Daniel Hahler <git@thequod.de>
%d/%D (decorate) will also provide a pointer to a ref, e.g.
> HEAD -> completion-git-fixes
---
Completion/Unix/Command/_git | 1 +
1 file changed, 1 insertion(+)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index c01333b..962b1e8 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5673,6 +5673,7 @@ __git_recent_commits () {
# see workers/34768
descr+=("$i:[$i] $k")
j=${${j# \(}%\)} # strip leading ' (' and trailing ')'
+ j=${j%% ->*} # Remove " -> master, origin/master" etc.
for j in ${(s:, :)j}; do
if [[ $j == 'tag: '* ]] ; then
tags+=( ${j#tag: } )
--
2.4.0.dirty
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/7] completion: git: use %D for %d, without the " (", ")" wrapping
2015-05-13 14:26 completion: git: various improvements to commit object handling Daniel Hahler
2015-05-13 14:26 ` [PATCH 1/7] completion: git: __git_recent_commits: remove ' ->*' from heads Daniel Hahler
@ 2015-05-13 14:26 ` Daniel Hahler
2015-05-13 14:26 ` [PATCH 3/7] completion: git: add __git_commit_objects_prefer_recent Daniel Hahler
` (5 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Daniel Hahler @ 2015-05-13 14:26 UTC (permalink / raw)
To: zsh-workers
From: Daniel Hahler <git@thequod.de>
This avoids having to remove this later again.
---
Completion/Unix/Command/_git | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 962b1e8..2204fc8 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5665,14 +5665,13 @@ __git_recent_commits () {
local i j k
# 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')"}}"
+ : "${(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
# Note: the after-the-colon part must be unique across the entire array;
# see workers/34768
descr+=("$i:[$i] $k")
- j=${${j# \(}%\)} # strip leading ' (' and trailing ')'
j=${j%% ->*} # Remove " -> master, origin/master" etc.
for j in ${(s:, :)j}; do
if [[ $j == 'tag: '* ]] ; then
--
2.4.0.dirty
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/7] completion: git: add __git_commit_objects_prefer_recent
2015-05-13 14:26 completion: git: various improvements to commit object handling Daniel Hahler
2015-05-13 14:26 ` [PATCH 1/7] completion: git: __git_recent_commits: remove ' ->*' from heads Daniel Hahler
2015-05-13 14:26 ` [PATCH 2/7] completion: git: use %D for %d, without the " (", ")" wrapping Daniel Hahler
@ 2015-05-13 14:26 ` Daniel Hahler
2015-05-14 14:29 ` Daniel Shahaf
2015-05-13 14:26 ` [PATCH 4/7] completion: git: __git_commit_objects: query 1000 commits Daniel Hahler
` (4 subsequent siblings)
7 siblings, 1 reply; 10+ messages in thread
From: Daniel Hahler @ 2015-05-13 14:26 UTC (permalink / raw)
To: zsh-workers
From: Daniel Hahler <git@thequod.de>
This is used with __git_commits then, and is meant to only call
__git_recent_commits, if there are matches.
---
Completion/Unix/Command/_git | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 2204fc8..b590df0 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5599,6 +5599,11 @@ __git_remote_branch_names_noprefix () {
_wanted remote-branch-names-noprefix expl 'remote branch name' compadd "$@" -a - branch_names
}
+(( $+functions[__git_commit_objects_prefer_recent] )) ||
+__git_commit_objects_prefer_recent () {
+ __git_recent_commits || __git_commit_objects
+}
+
(( $+functions[__git_commits] )) ||
__git_commits () {
# TODO: deal with things that __git_heads and __git_tags has in common (i.e.,
@@ -5609,7 +5614,7 @@ __git_commits () {
_alternative \
"heads::__git_heads $sopts" \
"commit-tags::__git_commit_tags $sopts" \
- 'commit-objects::__git_commit_objects'
+ 'commit-objects::__git_commit_objects_prefer_recent'
}
(( $+functions[__git_heads] )) ||
--
2.4.0.dirty
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 4/7] completion: git: __git_commit_objects: query 1000 commits
2015-05-13 14:26 completion: git: various improvements to commit object handling Daniel Hahler
` (2 preceding siblings ...)
2015-05-13 14:26 ` [PATCH 3/7] completion: git: add __git_commit_objects_prefer_recent Daniel Hahler
@ 2015-05-13 14:26 ` Daniel Hahler
2015-05-13 14:26 ` [PATCH 5/7] completion: git: add %cr to commit objects (all and recent) Daniel Hahler
` (3 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Daniel Hahler @ 2015-05-13 14:26 UTC (permalink / raw)
To: zsh-workers
From: Daniel Hahler <git@thequod.de>
Also, `--all` and `--reflog` is used to get all commits.
It adds the _guard in front, so only non-empty values will come here.
Also, __git_commit_objects_prefer_recent will only call it, if there are
no matching recent commits.
---
Completion/Unix/Command/_git | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index b590df0..faf2e55 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5655,12 +5655,15 @@ __git_commit_objects () {
local gitdir expl start
declare -a commits
+ # Abort if the argument does not match a commit hash (including empty).
+ _guard '[[:xdigit:]](#c,40)' || return 1
+
# Note: the after-the-colon part must be unique across the entire array;
# see workers/34768
- : ${(A)commits::=${(f)"$(_call_program commits git --no-pager log -20 --format='%h:\\\[%h\\\]\ %s')"}}
+ : ${(A)commits::=${(f)"$(_call_program commits git --no-pager log -1000 --all --reflog --format='%h:\\\[%h\\\]\ %s')"}}
__git_command_successful $pipestatus || return 1
- _describe -V -t commits 'commit object name' commits || _guard '[[:xdigit:]](#c,40)' 'commit object name'
+ _describe -V -t commits 'commit object name' commits
}
(( $+functions[__git_recent_commits] )) ||
--
2.4.0.dirty
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 5/7] completion: git: add %cr to commit objects (all and recent)
2015-05-13 14:26 completion: git: various improvements to commit object handling Daniel Hahler
` (3 preceding siblings ...)
2015-05-13 14:26 ` [PATCH 4/7] completion: git: __git_commit_objects: query 1000 commits Daniel Hahler
@ 2015-05-13 14:26 ` Daniel Hahler
2015-05-13 14:26 ` [PATCH 6/7] completion: git: unique name for __git_recent_commits Daniel Hahler
` (2 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Daniel Hahler @ 2015-05-13 14:26 UTC (permalink / raw)
To: zsh-workers
From: Daniel Hahler <git@thequod.de>
---
Completion/Unix/Command/_git | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index faf2e55..8135c6d 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5660,7 +5660,7 @@ __git_commit_objects () {
# Note: the after-the-colon part must be unique across the entire array;
# see workers/34768
- : ${(A)commits::=${(f)"$(_call_program commits git --no-pager log -1000 --all --reflog --format='%h:\\\[%h\\\]\ %s')"}}
+ : ${(A)commits::=${(f)"$(_call_program commits git --no-pager log -1000 --all --reflog --format='%h:\[%h\]\ %s\ \(%cr\)')"}}
__git_command_successful $pipestatus || return 1
_describe -V -t commits 'commit object name' commits
@@ -5673,7 +5673,7 @@ __git_recent_commits () {
local i j k
# 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')"}}"
+ : "${(A)commits::=${(@f)"$(_call_program commits git --no-pager log -20 --format='%h%n%D%n%s\ \(%cr\)')"}}"
__git_command_successful $pipestatus || return 1
for i j k in "$commits[@]" ; do
--
2.4.0.dirty
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 6/7] completion: git: unique name for __git_recent_commits
2015-05-13 14:26 completion: git: various improvements to commit object handling Daniel Hahler
` (4 preceding siblings ...)
2015-05-13 14:26 ` [PATCH 5/7] completion: git: add %cr to commit objects (all and recent) Daniel Hahler
@ 2015-05-13 14:26 ` Daniel Hahler
2015-05-13 14:26 ` [PATCH 7/7] completion: git: add distance_from_head to __git_recent_commits Daniel Hahler
2015-05-17 19:09 ` completion: git: various improvements to commit object handling Daniel Hahler
7 siblings, 0 replies; 10+ messages in thread
From: Daniel Hahler @ 2015-05-13 14:26 UTC (permalink / raw)
To: zsh-workers
From: Daniel Hahler <git@thequod.de>
This helps to distinguish it from __git_commit_objects.
---
Completion/Unix/Command/_git | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 8135c6d..09ea68b 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5697,7 +5697,7 @@ __git_recent_commits () {
expl=()
_wanted heads expl 'head' compadd "$@" -a - heads && ret=0
expl=()
- _describe -2Vx -t commits 'commit object name' descr && ret=0
+ _describe -2Vx -t commits 'recent commit object name' descr && ret=0
}
(( $+functions[__git_blob_objects] )) ||
--
2.4.0.dirty
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 7/7] completion: git: add distance_from_head to __git_recent_commits
2015-05-13 14:26 completion: git: various improvements to commit object handling Daniel Hahler
` (5 preceding siblings ...)
2015-05-13 14:26 ` [PATCH 6/7] completion: git: unique name for __git_recent_commits Daniel Hahler
@ 2015-05-13 14:26 ` Daniel Hahler
2015-05-17 19:09 ` completion: git: various improvements to commit object handling Daniel Hahler
7 siblings, 0 replies; 10+ messages in thread
From: Daniel Hahler @ 2015-05-13 14:26 UTC (permalink / raw)
To: zsh-workers
From: Daniel Shahaf <d.s@daniel.shahaf.name>
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)
---
Completion/Unix/Command/_git | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 09ea68b..ef95dfd 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5671,6 +5671,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!
: "${(A)commits::=${(@f)"$(_call_program commits git --no-pager log -20 --format='%h%n%D%n%s\ \(%cr\)')"}}"
@@ -5679,7 +5680,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%% ->*} # Remove " -> master, origin/master" etc.
for j in ${(s:, :)j}; do
if [[ $j == 'tag: '* ]] ; then
--
2.4.0.dirty
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/7] completion: git: add __git_commit_objects_prefer_recent
2015-05-13 14:26 ` [PATCH 3/7] completion: git: add __git_commit_objects_prefer_recent Daniel Hahler
@ 2015-05-14 14:29 ` Daniel Shahaf
0 siblings, 0 replies; 10+ messages in thread
From: Daniel Shahaf @ 2015-05-14 14:29 UTC (permalink / raw)
To: Daniel Hahler; +Cc: zsh-workers
Daniel Hahler wrote on Wed, May 13, 2015 at 16:26:27 +0200:
> +__git_commit_objects_prefer_recent () {
> + __git_recent_commits || __git_commit_objects
> +}
Add a 'return ret' at the end of __git_recent_commits?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: completion: git: various improvements to commit object handling
2015-05-13 14:26 completion: git: various improvements to commit object handling Daniel Hahler
` (6 preceding siblings ...)
2015-05-13 14:26 ` [PATCH 7/7] completion: git: add distance_from_head to __git_recent_commits Daniel Hahler
@ 2015-05-17 19:09 ` Daniel Hahler
7 siblings, 0 replies; 10+ messages in thread
From: Daniel Hahler @ 2015-05-17 19:09 UTC (permalink / raw)
To: zsh-workers
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I will push this series later.
- From discussion on IRC with Daniel Shahaf, I've ended up with the following interdiff:
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 858f817..708eb2a 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5675,7 +5675,8 @@ __git_recent_commits () {
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\ \(%cr\)')"}}"
+ # NOTE: we could use %D directly, but it's not available in git 1.9.1 at least.
+ : "${(A)commits::=${(@f)"$(_call_program commits git --no-pager log -20 --format='%h%n%d%n%s\ \(%cr\)')"}}"
__git_command_successful $pipestatus || return 1
for i j k in "$commits[@]" ; do
@@ -5694,7 +5695,8 @@ __git_recent_commits () {
fi
(( ++distance_from_head ))
- j=${j%% ->*} # Remove " -> master, origin/master" etc.
+ j=${${j# \(}%\)} # strip leading ' (' and trailing ')'
+ j=${j/ ->/,} # Convert " -> master, origin/master".
for j in ${(s:, :)j}; do
if [[ $j == 'tag: '* ]] ; then
tags+=( ${j#tag: } )
@@ -5712,6 +5714,7 @@ __git_recent_commits () {
_wanted heads expl 'head' compadd "$@" -a - heads && ret=0
expl=()
_describe -2Vx -t commits 'recent commit object name' descr && ret=0
+ return $ret
}
(( $+functions[__git_blob_objects] )) ||
Regards,
Daniel.
On 13.05.2015 16:26, Daniel Hahler wrote:
> I've also submitted it as a pull request against the zsh-users' mirror on Github:
> https://github.com/zsh-users/zsh/pull/4
>
> [PATCH 1/7] completion: git: __git_recent_commits: remove ' ->*' from
> [PATCH 2/7] completion: git: use %D for %d, without the " (", ")"
> [PATCH 3/7] completion: git: add __git_commit_objects_prefer_recent
> [PATCH 4/7] completion: git: __git_commit_objects: query 1000 commits
> [PATCH 5/7] completion: git: add %cr to commit objects (all and
> [PATCH 6/7] completion: git: unique name for __git_recent_commits
> [PATCH 7/7] completion: git: add distance_from_head to
>
>
> Regards,
> Daniel.
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iD8DBQFVWOdffAK/hT/mPgARAtgfAKDMwzqAiPBQGR+feZ+aK9gK0Ote5ACg2jHo
reNSvIDJRWAWMNochFIbUBk=
=elZp
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2015-05-17 19:09 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-13 14:26 completion: git: various improvements to commit object handling Daniel Hahler
2015-05-13 14:26 ` [PATCH 1/7] completion: git: __git_recent_commits: remove ' ->*' from heads Daniel Hahler
2015-05-13 14:26 ` [PATCH 2/7] completion: git: use %D for %d, without the " (", ")" wrapping Daniel Hahler
2015-05-13 14:26 ` [PATCH 3/7] completion: git: add __git_commit_objects_prefer_recent Daniel Hahler
2015-05-14 14:29 ` Daniel Shahaf
2015-05-13 14:26 ` [PATCH 4/7] completion: git: __git_commit_objects: query 1000 commits Daniel Hahler
2015-05-13 14:26 ` [PATCH 5/7] completion: git: add %cr to commit objects (all and recent) Daniel Hahler
2015-05-13 14:26 ` [PATCH 6/7] completion: git: unique name for __git_recent_commits Daniel Hahler
2015-05-13 14:26 ` [PATCH 7/7] completion: git: add distance_from_head to __git_recent_commits Daniel Hahler
2015-05-17 19:09 ` completion: git: various improvements to commit object handling Daniel Hahler
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).