* [PATCH 1/2] __git_recent_branches: Retrieve less data, but faster.
@ 2017-03-10 9:05 Daniel Shahaf
2017-03-10 9:05 ` [PATCH 2/2] _git-checkout: When completing local heads, prefer recently-checked-out ones. (after 38592) Daniel Shahaf
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Shahaf @ 2017-03-10 9:05 UTC (permalink / raw)
To: zsh-workers
By replacing the --grep-reflog=needle argument with a ${(M)...:#needle} filter,
we retrieve less data from the reflog, and consequently run (on my test cases)
16% to 40% faster. The trade-off is that we retrieve less data: instead of
retrieving the 1000 most recent 'checkout' operations, we retrieve the most
recent 1000 operations, which would include fewer than 1000 checkout operations.
Also change [[:xdigit:]] to [0-9a-f] since it's faster, however, the absolute
gain from this is minor compared to the cost of 'git reflog'.
---
Completion/Unix/Command/_git | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 43cbc46..73daedc 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -6126,12 +6126,13 @@ __git_recent_branches__names()
# 2. Extracts the move-source from each
# 3. Eliminates duplicates
# 4. Eliminates commit hashes (leaving only ref names)
+ # [This step is done again by the caller.]
#
# See workers/38592 for an equivalent long-hand implementation, and the rest
# of that thread for why this implementation was chosen instead.
#
# Note: since we obtain the "from" part of the reflog, we only obtain heads, not tags.
- reply=(${${(u)${${(0)"$(_call_program reflog git reflog -1000 -z --grep-reflog='\^checkout:\ moving\ from\ ' --pretty='%gs')"}#checkout: moving from }%% *}:#[[:xdigit:]](#c40)})
+ reply=(${${(u)${${(M)${(0)"$(_call_program reflog git reflog -1000 -z --pretty='%gs')"}:#(#s)checkout: moving from *}#checkout: moving from }%% *}:#[0-9a-f](#c40)})
}
(( $+functions[__git_recent_branches] )) ||
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 2/2] _git-checkout: When completing local heads, prefer recently-checked-out ones. (after 38592)
2017-03-10 9:05 [PATCH 1/2] __git_recent_branches: Retrieve less data, but faster Daniel Shahaf
@ 2017-03-10 9:05 ` Daniel Shahaf
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Shahaf @ 2017-03-10 9:05 UTC (permalink / raw)
To: zsh-workers
---
This changes the completion of local branch names at «git checkout <TAB>»
by finally hooking up the code written in 38592 by default.
In my experience, the cold cache behaviour was sometimes a bit slow. If
others see this too then perhaps the 'depth' constant down in
__git_recent_branches should be reduced?
Cheers,
Daniel
Completion/Unix/Command/_git | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 73daedc..85aac92 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -476,7 +476,7 @@ _git-checkout () {
# TODO: Allow A...B
local \
remote_branch_noprefix_arg='remote-branch-names-noprefix::__git_remote_branch_names_noprefix' \
- tree_ish_arg='tree-ishs::__git_tree_ishs' \
+ tree_ish_arg='tree-ishs::__git_commits_prefer_recent' \
file_arg='modified-files::__git_modified_files'
if [[ -n ${opt_args[(I)-b|-B|--orphan|--detach]} ]]; then
@@ -6169,6 +6169,10 @@ __git_recent_branches() {
_describe -V -t recent-branches "recent branches" branches_colon_descriptions
}
+(( $+functions[__git_commits_prefer_recent] )) ||
+__git_commits_prefer_recent () {
+ _alternative 'recent-branches::__git_recent_branches' 'commits::__git_commits'
+}
(( $+functions[__git_commits] )) ||
__git_commits () {
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-03-10 9:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-10 9:05 [PATCH 1/2] __git_recent_branches: Retrieve less data, but faster Daniel Shahaf
2017-03-10 9:05 ` [PATCH 2/2] _git-checkout: When completing local heads, prefer recently-checked-out ones. (after 38592) 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).