* Re: [PATCH v2 4/8] completion: factor out _git_xxx calling code
@ 2018-03-25 20:57 Recep Aslan
0 siblings, 0 replies; 2+ messages in thread
From: Recep Aslan @ 2018-03-25 20:57 UTC (permalink / raw)
To: pclouds; +Cc: git, gitster, szeder.dev
Sssss
iPhone’umdan gönderildi
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] completion: add option completion for most builtin commands
@ 2018-03-21 19:30 Nguyễn Thái Ngọc Duy
2018-03-24 20:35 ` [PATCH v2 0/8] " Nguyễn Thái Ngọc Duy
0 siblings, 1 reply; 2+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-03-21 19:30 UTC (permalink / raw)
To: git; +Cc: SZEDER Gábor, Nguyễn Thái Ngọc Duy
These commands can take options and use parse-options so it's quite
easy to allow option completion. This does not pollute the command
name completion though. "git <tab>" will show you the same set as
before. This only kicks in when you type the correct command name.
Some other builtin commands are not still added because either they
don't use parse-options, or they are deprecated, or they are those
-helper commands that are used to move some logic back in C for
sh-based commands.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
contrib/completion/git-completion.bash | 276 +++++++++++++++++++++++++
1 file changed, 276 insertions(+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6da95b8095..0cd9180f48 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1202,6 +1202,15 @@ _git_bisect ()
esac
}
+_git_blame() {
+ case "$cur" in
+ --*)
+ __gitcomp_builtin blame
+ return
+ ;;
+ esac
+}
+
_git_branch ()
{
local i c=1 only_local_ref="n" has_r="n"
@@ -1254,6 +1263,42 @@ _git_bundle ()
esac
}
+_git_cat_file() {
+ case "$cur" in
+ --*)
+ __gitcomp_builtin cat-file
+ return
+ ;;
+ esac
+}
+
+_git_check_attr() {
+ case "$cur" in
+ --*)
+ __gitcomp_builtin check-attr
+ return
+ ;;
+ esac
+}
+
+_git_check_ignore() {
+ case "$cur" in
+ --*)
+ __gitcomp_builtin check-ignore
+ return
+ ;;
+ esac
+}
+
+_git_check_mailmap() {
+ case "$cur" in
+ --*)
+ __gitcomp_builtin check-mailmap
+ return
+ ;;
+ esac
+}
+
_git_checkout ()
{
__git_has_doubledash && return
@@ -1278,6 +1323,15 @@ _git_checkout ()
esac
}
+_git_checkout_index() {
+ case "$cur" in
+ --*)
+ __gitcomp_builtin checkout-index
+ return
+ ;;
+ esac
+}
+
_git_cherry ()
{
__git_complete_refs
@@ -1326,6 +1380,15 @@ _git_clone ()
esac
}
+_git_column() {
+ case "$cur" in
+ --*)
+ __gitcomp_builtin column
+ return
+ ;;
+ esac
+}
+
__git_untracked_file_modes="all no normal"
_git_commit ()
@@ -1365,6 +1428,15 @@ _git_commit ()
fi
}
+_git_count_objects() {
+ case "$cur" in
+ --*)
+ __gitcomp_builtin count-objects
+ return
+ ;;
+ esac
+}
+
_git_describe ()
{
case "$cur" in
@@ -1446,6 +1518,15 @@ _git_difftool ()
__git_complete_revlist_file
}
+_git_fast_export() {
+ case "$cur" in
+ --*)
+ __gitcomp_builtin fast-export
+ return
+ ;;
+ esac
+}
+
__git_fetch_recurse_submodules="yes on-demand no"
_git_fetch ()
@@ -1573,6 +1654,15 @@ _git_grep ()
__git_complete_refs
}
+_git_hash_object() {
+ case "$cur" in
+ --*)
+ __gitcomp_builtin hash-object
+ return
+ ;;
+ esac
+}
+
_git_help ()
{
case "$cur" in
@@ -1590,6 +1680,15 @@ _git_help ()
"
}
+_git_index_pack() {
+ case "$cur" in
+ --*)
+ __gitcomp_builtin index-pack
+ return
+ ;;
+ esac
+}
+
_git_init ()
{
case "$cur" in
@@ -1606,6 +1705,15 @@ _git_init ()
esac
}
+_git_interpret_trailers() {
+ case "$cur" in
+ --*)
+ __gitcomp_builtin interpret-trailers
+ return
+ ;;
+ esac
+}
+
_git_ls_files ()
{
case "$cur" in
@@ -1765,6 +1873,15 @@ _git_merge ()
__git_complete_refs
}
+_git_merge_file() {
+ case "$cur" in
+ --*)
+ __gitcomp_builtin merge-file
+ return
+ ;;
+ esac
+}
+
_git_mergetool ()
{
case "$cur" in
@@ -1790,6 +1907,15 @@ _git_merge_base ()
__git_complete_refs
}
+_git_mktree() {
+ case "$cur" in
+ --*)
+ __gitcomp_builtin mktree
+ return
+ ;;
+ esac
+}
+
_git_mv ()
{
case "$cur" in
@@ -1853,6 +1979,46 @@ _git_notes ()
esac
}
+_git_pack_objects ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp_builtin pack-objects
+ return
+ ;;
+ esac
+}
+
+_git_pack_refs ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp_builtin pack-refs
+ return
+ ;;
+ esac
+}
+
+_git_prune ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp_builtin prune
+ return
+ ;;
+ esac
+}
+
+_git_prune_packed ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp_builtin prune-packed
+ return
+ ;;
+ esac
+}
+
_git_pull ()
{
__git_complete_strategy && return
@@ -1925,6 +2091,16 @@ _git_push ()
__git_complete_remote_or_refspec
}
+_git_read_tree ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp_builtin read-tree
+ return
+ ;;
+ esac
+}
+
_git_rebase ()
{
__git_find_repo_path
@@ -1974,6 +2150,16 @@ _git_reflog ()
fi
}
+_git_repack ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp_builtin repack
+ return
+ ;;
+ esac
+}
+
__git_send_email_confirm_options="always never auto cc compose"
__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
@@ -2031,6 +2217,26 @@ _git_send_email ()
__git_complete_revlist
}
+_git_send_pack ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp_builtin send-pack
+ return
+ ;;
+ esac
+}
+
+_git_show_ref ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp_builtin show-ref
+ return
+ ;;
+ esac
+}
+
_git_stage ()
{
_git_add
@@ -2082,6 +2288,26 @@ _git_status ()
__git_complete_index_file "$complete_opt"
}
+_git_stripspace ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp_builtin stripspace
+ return
+ ;;
+ esac
+}
+
+_git_symbolic_ref ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp_builtin symbolic-ref
+ return
+ ;;
+ esac
+}
+
__git_config_get_set_variables ()
{
local prevword word config_file= c=$cword
@@ -2998,6 +3224,46 @@ _git_tag ()
esac
}
+_git_update_index ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp_builtin update-index
+ return
+ ;;
+ esac
+}
+
+_git_update_ref ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp_builtin update-ref
+ return
+ ;;
+ esac
+}
+
+_git_verify_commit ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp_builtin verify-commit
+ return
+ ;;
+ esac
+}
+
+_git_verify_tag ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp_builtin verify-tag
+ return
+ ;;
+ esac
+}
+
_git_whatchanged ()
{
_git_log
@@ -3032,6 +3298,16 @@ _git_worktree ()
fi
}
+_git_write_tree ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp_builtin write-tree
+ return
+ ;;
+ esac
+}
+
__git_main ()
{
local i c=1 command __git_dir __git_repo_path
--
2.17.0.rc0.348.gd5a49e0b6f
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH v2 0/8] completion: add option completion for most builtin commands
2018-03-21 19:30 [PATCH] completion: add option completion for most builtin commands Nguyễn Thái Ngọc Duy
@ 2018-03-24 20:35 ` Nguyễn Thái Ngọc Duy
2018-03-24 20:35 ` [PATCH v2 4/8] completion: factor out _git_xxx calling code Nguyễn Thái Ngọc Duy
0 siblings, 1 reply; 2+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-03-24 20:35 UTC (permalink / raw)
To: pclouds; +Cc: git, szeder.dev, Junio C Hamano
This series adds option completion for many more commands. More
importantly it introduces a generic completion function
__git_complete_common(). With --git-completion-helper providing more
and more information in future, this function can start to replace
many other _git_xxx() in this file.
Nguyễn Thái Ngọc Duy (8):
git.c: move cmd_struct declaration up
git.c: add hidden option --list-parseopt-builtins
completion: mention the oldest version we need to support
completion: factor out _git_xxx calling code
completion: add --option completion for most builtin commands
completion: delete option-only completion commands
completion: use __gitcomp_builtin in _git_ls_tree
completion: use __gitcomp_builtin in _git_cherry
contrib/completion/git-completion.bash | 75 +++++++++++----
git.c | 122 +++++++++++++------------
t/t9902-completion.sh | 6 ++
3 files changed, 127 insertions(+), 76 deletions(-)
--
2.17.0.rc0.348.gd5a49e0b6f
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH v2 4/8] completion: factor out _git_xxx calling code
2018-03-24 20:35 ` [PATCH v2 0/8] " Nguyễn Thái Ngọc Duy
@ 2018-03-24 20:35 ` Nguyễn Thái Ngọc Duy
0 siblings, 0 replies; 2+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-03-24 20:35 UTC (permalink / raw)
To: pclouds; +Cc: git, szeder.dev, Junio C Hamano
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
contrib/completion/git-completion.bash | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 9bef457792..b3a9ecfad0 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3034,6 +3034,17 @@ _git_worktree ()
fi
}
+__git_complete_command () {
+ local command="$1"
+ local completion_func="_git_${command//-/_}"
+ if declare -f $completion_func >/dev/null 2>/dev/null; then
+ $completion_func
+ return 0
+ else
+ return 1
+ fi
+}
+
__git_main ()
{
local i c=1 command __git_dir __git_repo_path
@@ -3093,14 +3104,12 @@ __git_main ()
return
fi
- local completion_func="_git_${command//-/_}"
- declare -f $completion_func >/dev/null 2>/dev/null && $completion_func && return
+ __git_complete_command "$command" && return
local expansion=$(__git_aliased_command "$command")
if [ -n "$expansion" ]; then
words[1]=$expansion
- completion_func="_git_${expansion//-/_}"
- declare -f $completion_func >/dev/null 2>/dev/null && $completion_func
+ __git_complete_command "$expansion"
fi
}
--
2.17.0.rc0.348.gd5a49e0b6f
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-03-25 21:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-25 20:57 [PATCH v2 4/8] completion: factor out _git_xxx calling code Recep Aslan
-- strict thread matches above, loose matches on Subject: below --
2018-03-21 19:30 [PATCH] completion: add option completion for most builtin commands Nguyễn Thái Ngọc Duy
2018-03-24 20:35 ` [PATCH v2 0/8] " Nguyễn Thái Ngọc Duy
2018-03-24 20:35 ` [PATCH v2 4/8] completion: factor out _git_xxx calling code Nguyễn Thái Ngọc Duy
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).