Re: [PATCH] completion: do not cache if --git-completion-helper fails
From: Duy Nguyen <hidden>
Date: 2019-06-12 08:52:47
On Sat, Jun 8, 2019 at 12:33 AM Felipe Contreras [off-list ref] wrote:
On Fri, Jun 7, 2019 at 5:02 AM SZEDER Gábor [off-list ref] wrote:quoted
On Fri, Jun 07, 2019 at 04:30:34PM +0700, Nguyễn Thái Ngọc Duy wrote:quoted
"git <cmd> --git-completion-helper" could fail if the command checks for a repo before parse_options(). If the result is cached, later on when the user moves to a worktree with repo, tab completion will still fail. Avoid this by detecting errors and not cache the completion output. We can try again and hopefully succeed next time (e.g. when a repo is found). Of course if --git-completion-helper fails permanently because of other reasons (*), this will slow down completion. But I don't see any better option to handle that case.I think a permanently failing 'git cmd --git-completion-helper' shouldn't really happen, unless there is a bug in the completion script or the git installation or similar exceptional situation. And then that issue should be fixed, but I don't think we should worry about an extra subshell and git process in those situations.Indeed. In think there's only sane option to make this work in all situation; a reorganization. Something like this should work: struct command checkout_command = { .name = "checkout", .function = cmd_checkout, .run_options = RUN_SETUP | NEED_WORK_TREE, .help = N_("Switch branches or restore working tree files"), .options = { OPT__QUIET(&opts.quiet, N_("suppress progress reporting")), ... }, } This way we could run parse_options_show_gitcomp() from git.c and not worry about whatever cmd_checkout() needs.
This only works for a few commands. Those with subcommands already have struct option[] array scattered in different places. And some new ones also have struct option array dynamically created. It's not impossible to do. But I feel there's a lot of reorganizing for little gain. Maybe when we pass 'struct repository *' to all commands, which means we hit all commmands at once anyway, we can reconsider this (and having config parser in a more declarative form like cmd option parser).
This has the added advantage that it gathers information about this command that is stray in multiple sources (git.c, command-list.h), and it makes builtin.h cleaner too. Plus, we could rework the way -h works too.
-- Duy